diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 00000000..194a7152 --- /dev/null +++ b/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 diff --git a/proxy/Dockerfile.dockerignore b/proxy/Dockerfile.dockerignore new file mode 100644 index 00000000..f85b6b8e --- /dev/null +++ b/proxy/Dockerfile.dockerignore @@ -0,0 +1,2 @@ +* +!caddy.json diff --git a/proxy/caddy.json b/proxy/caddy.json new file mode 100644 index 00000000..86302b7f --- /dev/null +++ b/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": "" + } + } + } + } + } + } +} diff --git a/proxy/makefile b/proxy/makefile new file mode 100644 index 00000000..e210b281 --- /dev/null +++ b/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