Skip to content

Commit

Permalink
ADD: proxy service
Browse files Browse the repository at this point in the history
TODO: dynamic env vars with defaults in caddy.json. See caddyserver/caddy#5275
  • Loading branch information
MrStanana committed Mar 19, 2024
1 parent 417c404 commit 9f2a4d0
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
9 changes: 9 additions & 0 deletions proxy/Dockerfile
@@ -0,0 +1,9 @@
ARG ENV=production

FROM caddy:2.7.6-builder-alpine AS builder
# https://github.com/mholt/caddy-l4
RUN xcaddy build --with github.com/mholt/caddy-l4

FROM caddy:2.7.6-alpine AS final
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY ./caddy.json /etc/caddy/caddy.json
2 changes: 2 additions & 0 deletions proxy/Dockerfile.dockerignore
@@ -0,0 +1,2 @@
*
!caddy.json
144 changes: 144 additions & 0 deletions proxy/caddy.json
@@ -0,0 +1,144 @@
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":8080"
],
"routes": [
{
"match": [
{
"host": [
"localhost"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "headers",
"response": {
"set": {
"Content-Type": [
"application/xml"
]
}
}
}
],
"match": [
{
"path": [
"*.xml"
]
}
]
},
{
"handle": [
{
"encodings": {
"gzip": {},
"zstd": {}
},
"handler": "encode",
"prefer": [
"zstd",
"gzip"
]
}
]
},
{
"handle": [
{
"body": "\u003cConfig\u003e\n \u003cTest\u003e123\u003c/Test\u003e\n\u003c/Config\u003e",
"close": true,
"handler": "static_response",
"status_code": 200
}
],
"match": [
{
"path": [
"/config.xml"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
],
"root": "/srv"
}
]
}
]
}
],
"terminal": true
}
],
"errors": {
"routes": [
{
"match": [
{
"host": [
"localhost"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"status_code": 404
}
]
}
]
}
],
"match": [
{
"expression": "{http.error.status_code} in [404, 410]"
}
]
}
]
}
],
"terminal": true
}
]
},
"logs": {
"logger_names": {
"localhost": ""
}
}
}
}
}
}
}
23 changes: 23 additions & 0 deletions proxy/makefile
@@ -0,0 +1,23 @@
#!/usr/bin/make -f

ENV?=development
ENV_FILE?=./env/.env.build.${ENV}
-include ${ENV_FILE}

SERVICE?=openatbp-proxy
VERSION?=0.0.1

export

EXCLUDED_CHARACTERS:=< . ? @ , % ^ * + >
FILTERED_VARIABLES:=$(sort $(filter-out $(foreach C,${EXCLUDED_CHARACTERS},$(foreach S,${.VARIABLES},$(if $(findstring $C,$S),$S))),${.VARIABLES}))

docker_build: Dockerfile
docker build -t ${SERVICE}:${VERSION} -t ${SERVICE}:latest -f ./Dockerfile $(addprefix --build-arg ,${FILTERED_VARIABLES}) .

docker_run:
docker run --rm -p 8080:8080/tcp --name ${SERVICE} --env-file ${ENV_FILE} ${SERVICE}:${VERSION}

docker_push:
docker push ${SERVICE}:${VERSION}
docker push ${SERVICE}:latest

0 comments on commit 9f2a4d0

Please sign in to comment.