mirror of
https://github.com/timokz/flutter-vienna-hackathon-25.git
synced 2025-11-08 17:14:21 +01:00
server: make/docker: add deployment procedures
Signed-off-by: Max R. Carrara <max@aequito.sh>
This commit is contained in:
parent
6786def063
commit
f87843785a
4 changed files with 139 additions and 0 deletions
|
|
@ -3,9 +3,20 @@ include ../defines.mk
|
|||
COMPOSE_FILE_LOCAL = docker-compose.local.yaml
|
||||
COMPOSE_FILE_DEPLOY = docker-compose.deploy.yaml
|
||||
|
||||
# NOTE: the --env-file flags are necessary because the env_file directive
|
||||
# in the docker-compose.yaml doesn't work for env vars that are used inside the
|
||||
# compose file itself.
|
||||
# This is jank, but it is what it is <.<
|
||||
COMPOSE_COMMON_ARGS_DEPLOY = -f $(COMPOSE_FILE_DEPLOY) \
|
||||
--env-file env.d/postgres.env \
|
||||
--env-file env.d/server.env \
|
||||
|
||||
|
||||
# Basically the current directory's name, so wien_talks_server
|
||||
COMPOSE_PROJECT := $(shell basename $(shell pwd))
|
||||
|
||||
DEPLOY_NETWORK = docker-net
|
||||
|
||||
.env: .env.template
|
||||
cp -a .env.template .env
|
||||
|
||||
|
|
@ -25,3 +36,33 @@ local-clean: local-down
|
|||
for VOLUME in $(shell docker compose -f $(COMPOSE_FILE_LOCAL) volumes -q); \
|
||||
do docker volume rm "$$VOLUME"; done
|
||||
|
||||
.PHONY: deploy deploy-env deploy-build deploy-stop deploy-down
|
||||
deploy:
|
||||
if test -z "$$(docker network ls -q --filter name=$(DEPLOY_NETWORK))"; then \
|
||||
docker network create --driver bridge $(DEPLOY_NETWORK); fi
|
||||
docker compose $(COMPOSE_COMMON_ARGS_DEPLOY) up -d
|
||||
|
||||
# TODO: parameterize .env files
|
||||
deploy-env: env.d/postgres.env.template env.d/server.env.template
|
||||
if test -e env.d/postgres.env; then echo "env.d/postgres.env already exists"; exit 1; fi
|
||||
if test -e env.d/server.env; then echo "env.d/server.env already exists"; exit 1; fi
|
||||
cp -a env.d/postgres.env.template env.d/postgres.env
|
||||
cp -a env.d/server.env.template env.d/server.env
|
||||
@echo -e "\n!!! Environment files for deployment initialized !!!\n\nDon't forget to edit them!"
|
||||
|
||||
deploy-build:
|
||||
docker compose $(COMPOSE_COMMON_ARGS_DEPLOY) build --no-cache
|
||||
|
||||
deploy-stop:
|
||||
if test -n "$$(docker network ls -q --filter name=$(DEPLOY_NETWORK))"; then \
|
||||
docker compose $(COMPOSE_COMMON_ARGS_DEPLOY) stop; fi
|
||||
|
||||
deploy-down:
|
||||
if test -n "$$(docker network ls -q --filter name=$(DEPLOY_NETWORK))"; then \
|
||||
docker compose $(COMPOSE_COMMON_ARGS_DEPLOY) down; fi
|
||||
|
||||
# Note: Doesn't clean up DB for safety reasons!
|
||||
deploy-clean: deploy-down
|
||||
if test -n "$$(docker network ls -q --filter name=$(DEPLOY_NETWORK))"; then \
|
||||
docker network rm $(DEPLOY_NETWORK) > /dev/null; fi
|
||||
|
||||
|
|
|
|||
75
wien_talks/wien_talks_server/docker-compose.deploy.yaml
Normal file
75
wien_talks/wien_talks_server/docker-compose.deploy.yaml
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
networks:
|
||||
docker-net:
|
||||
name: docker-net
|
||||
external: true
|
||||
backend:
|
||||
name: backend
|
||||
driver: bridge
|
||||
external: false
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-trixie
|
||||
container_name: postgres
|
||||
env_file:
|
||||
- path: env.d/postgres.env
|
||||
required: true
|
||||
volumes:
|
||||
- db:/var/lib/postgresql/data
|
||||
restart: always
|
||||
networks:
|
||||
- backend
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
|
||||
server:
|
||||
depends_on:
|
||||
- postgres
|
||||
build:
|
||||
context: ./
|
||||
image: wien-talks
|
||||
command: [
|
||||
"--mode",
|
||||
"production",
|
||||
"--server-id",
|
||||
"default",
|
||||
"--logging",
|
||||
"normal",
|
||||
"--role",
|
||||
"monolith",
|
||||
"--apply-migrations",
|
||||
]
|
||||
env_file:
|
||||
- path: env.d/server.env
|
||||
required: true
|
||||
restart: always
|
||||
networks:
|
||||
- docker-net
|
||||
- backend
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.wien-talks-api.rule=Host(`${SERVERPOD_API_SERVER_PUBLIC_HOST}`)"
|
||||
- "traefik.http.routers.wien-talks-api.entrypoints=secure"
|
||||
- "traefik.http.routers.wien-talks-api.service=wien-talks-api-service"
|
||||
- "traefik.http.services.wien-talks-api-service.loadbalancer.server.port=${SERVERPOD_API_SERVER_PORT}"
|
||||
|
||||
- "traefik.http.routers.wien-talks-insights.rule=Host(`${SERVERPOD_INSIGHTS_SERVER_PUBLIC_HOST}`)"
|
||||
- "traefik.http.routers.wien-talks-insights.entrypoints=secure"
|
||||
- "traefik.http.routers.wien-talks-insights.service=wien-talks-insights-service"
|
||||
- "traefik.http.services.wien-talks-insights-service.loadbalancer.server.port=${SERVERPOD_INSIGHTS_SERVER_PORT}"
|
||||
|
||||
- "traefik.http.routers.wien-talks-web.rule=Host(`${SERVERPOD_WEB_SERVER_PUBLIC_HOST}`)"
|
||||
- "traefik.http.routers.wien-talks-web.entrypoints=secure"
|
||||
- "traefik.http.routers.wien-talks-web.service=wien-talks-web-service"
|
||||
- "traefik.http.services.wien-talks-web-service.loadbalancer.server.port=${SERVERPOD_WEB_SERVER_PORT}"
|
||||
|
||||
debug:
|
||||
container_name: debug
|
||||
image: debian:13
|
||||
networks:
|
||||
- docker-net
|
||||
- backend
|
||||
|
||||
volumes:
|
||||
db:
|
||||
|
||||
3
wien_talks/wien_talks_server/env.d/postgres.env.template
Normal file
3
wien_talks/wien_talks_server/env.d/postgres.env.template
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=sergtsop
|
||||
POSTGRES_DB=wien_talks
|
||||
20
wien_talks/wien_talks_server/env.d/server.env.template
Normal file
20
wien_talks/wien_talks_server/env.d/server.env.template
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
SERVERPOD_API_SERVER_PORT=8080
|
||||
SERVERPOD_API_SERVER_PUBLIC_HOST=localhost
|
||||
SERVERPOD_API_SERVER_PUBLIC_PORT
|
||||
SERVERPOD_API_SERVER_PUBLIC_SCHEME
|
||||
SERVERPOD_DATABASE_HOST=postgres
|
||||
SERVERPOD_DATABASE_IS_UNIX_SOCKET
|
||||
SERVERPOD_DATABASE_NAME=wien_talks
|
||||
SERVERPOD_DATABASE_PASSWORD=${POSTGRES_PASSWORD}
|
||||
SERVERPOD_DATABASE_PORT=5432
|
||||
SERVERPOD_DATABASE_REQUIRE_SSL=false
|
||||
SERVERPOD_DATABASE_USER=postgres
|
||||
SERVERPOD_INSIGHTS_SERVER_PORT=8081
|
||||
SERVERPOD_INSIGHTS_SERVER_PUBLIC_HOST=localhost
|
||||
SERVERPOD_INSIGHTS_SERVER_PUBLIC_SCHEME
|
||||
SERVERPOD_MAX_REQUEST_SIZE
|
||||
SERVERPOD_SERVICE_SECRET
|
||||
SERVERPOD_WEB_SERVER_PORT=8082
|
||||
SERVERPOD_WEB_SERVER_PUBLIC_HOST=localhost
|
||||
SERVERPOD_WEB_SERVER_PUBLIC_PORT
|
||||
SERVERPOD_WEB_SERVER_PUBLIC_SCHEME
|
||||
Loading…
Add table
Reference in a new issue