Skip to content

Commit

Permalink
implement caddy as a much cleaner alternative to traefik; closes #60
Browse files Browse the repository at this point in the history
…; thanks @Bouni
  • Loading branch information
ModischFabrications committed Feb 1, 2024
1 parent 4edf72e commit 36f0ff5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ DOMAIN_NAME=localhost
EMAIL_ADDRESS=[email protected]

# Prod
#DOMAIN_NAME=vps.modisch.me
#DOMAIN_NAME=cutsolver.modisch.me
#[email protected]
30 changes: 30 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
email {$EMAIL_ADDRESS}
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory

admin off
log {
format console
}
}

# remove once everyone forgot about it
vps.modisch.me {
redir /cutsolver https://{$DOMAIN_NAME} permanent
}

{$DOMAIN_NAME} {
reverse_proxy /solve cutsolver
reverse_proxy cutsolver_frontend

# optional, but recommended from here
reverse_proxy /version cutsolver
reverse_proxy /constants cutsolver
reverse_proxy /debug cutsolver

reverse_proxy /docs cutsolver
reverse_proxy /redoc cutsolver
reverse_proxy /openapi.json cutsolver

respond /ping "pong at {$DOMAIN_NAME}"
}
89 changes: 31 additions & 58 deletions docker-compose-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,40 @@
version: '3.3'

# TODO:
# create .env file with all references
# Remove debug stuff as needed
version: "3.3"

services:

cutsolver_frontend:
build: .
# use specific tags for a persistent reference
image: modischfabrications/cutsolver_frontend:master
image: modischfabrications/cutsolver_frontend:latest
restart: unless-stopped
ports:
- "9500:80"
environment:
- VUE_APP_BACKEND_SOLVER_URL=https://${DOMAIN_NAME:?err}/solve
networks:
- webserver
- cutsolver
depends_on:
- cutsolver
environment:
- VUE_APP_BACKEND_SOLVER_URL=https://${DOMAIN_NAME:?err}/cutsolver/api/solve
labels:
- "traefik.enable=true"
- "traefik.http.routers.cutsolver_frontend.rule=Host(`${DOMAIN_NAME:?err}`) && PathPrefix(`/cutsolver`)"
- "traefik.http.routers.cutsolver_frontend.entrypoints=websecure"
- "traefik.http.routers.cutsolver_frontend.tls.certresolver=myresolver"
# forceslash/trailing slashes are needed to support relative hrefs
- "traefik.http.middlewares.cutsolver_frontend-stripprefix.stripprefix.forceslash=true"
- "traefik.http.middlewares.cutsolver_frontend-stripprefix.stripprefix.prefixes=/cutsolver"
- "traefik.http.routers.cutsolver_frontend.middlewares=cutsolver_frontend-stripprefix"

cutsolver:
image: modischfabrications/cutsolver:master
image: modischfabrications/cutsolver:latest
restart: unless-stopped
ports:
- "9501:80"
command:
# needs to be set for OpenAPI and other internal links
- "--root-path=/cutsolver/api"
labels:
- "traefik.enable=true"
- "traefik.http.routers.cutsolver.rule=Host(`${DOMAIN_NAME:?err}`) && PathPrefix(`/cutsolver/api`)"
- "traefik.http.routers.cutsolver.entrypoints=websecure"
- "traefik.http.routers.cutsolver.tls.certresolver=myresolver"
- "traefik.http.middlewares.cutsolver-stripprefix.stripprefix.forceslash=true"
- "traefik.http.middlewares.cutsolver-stripprefix.stripprefix.prefixes=/cutsolver/api"
- "traefik.http.routers.cutsolver.middlewares=cutsolver-stripprefix"
networks:
- webserver
- cutsolver

traefik:
image: traefik:v2.9
caddy:
image: caddy:2.7-alpine
restart: unless-stopped
command:
# TODO remove insecure and debug logs once ready
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.httpchallenge=true"
- "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
- "--certificatesresolvers.myresolver.acme.email=${EMAIL_ADDRESS:?err}"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
# staging for tests; TODO remove once ready
- "--certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
ports:
- "80:80" # HTTP
- "443:443" # HTTPS
- "9001:8080" # Web UI (enabled by --api.insecure=true)
environment:
- EMAIL_ADDRESS=${EMAIL_ADDRESS:?err}
- DOMAIN_NAME=${DOMAIN_NAME:?err}
volumes:
- "./letsencrypt:/letsencrypt"
# listen to docker events, *readonly*
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- ./Caddyfile:/etc/caddy/Caddyfile
- ./caddy/data:/data
- ./caddy/config:/config
ports:
- 80:80
- 443:443
networks:
- webserver

# auto-updates
# THIS WILL RANDOMLY RESTART YOUR CONTAINERS!
Expand All @@ -83,3 +49,10 @@ services:
# recovery from broken images
- "--include-stopped"
- "--revive-stopped"

networks:
webserver:
name: webserver
driver: bridge
cutsolver:
name: cutsolver

0 comments on commit 36f0ff5

Please sign in to comment.