Skip to content

Commit

Permalink
ci: use docker swarm in production (#72)
Browse files Browse the repository at this point in the history
* config(api): define data source driver class

* ci: define a docker swarm stack compose file
  • Loading branch information
neumanf authored Oct 3, 2024
1 parent 22caf4a commit 9505b47
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ jobs:
- name: Deploy
run: |
cd $HOME/mally &&
docker compose -f docker-compose.prod.yml down &&
docker compose -f docker-compose.prod.yml pull &&
docker compose -f docker-compose.prod.yml up -d
docker compose -f docker-compose.stack.yml pull &&
export $(cat .env) &&
docker stack deploy -c docker-compose.stack.yml mally
1 change: 1 addition & 0 deletions apps/api/src/main/resources/application.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring:
url: jdbc:${DATABASE_URL}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
driverClassName: org.postgresql.Driver

jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/main/resources/application.testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring:
url: jdbc:postgresql://postgres:5432/mally
username: postgres
password: postgres
driverClassName: org.postgresql.Driver

jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring:
url: jdbc:postgresql://localhost:5432/mally
username: postgres
password: postgres
driverClassName: org.postgresql.Driver

jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
Expand Down
97 changes: 60 additions & 37 deletions docker-compose.prod.yml → docker-compose.stack.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '3.7'

services:
postgres:
container_name: mally-postgres
image: ghcr.io/neumanf/mally-postgres
restart: unless-stopped
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "keycloak", "-U", "postgres" ]
test: pg_isready -q -d keycloak -U postgres
timeout: 45s
interval: 10s
retries: 5
Expand All @@ -20,11 +20,9 @@ services:
- postgres:/var/lib/postgresql/data

keycloak:
container_name: mally-keycloak
image: ghcr.io/neumanf/mally-keycloak
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://0.0.0.0:9000/health/ready"]
test: curl -f http://localhost:9000/health/ready
timeout: 45s
interval: 10s
retries: 15
Expand All @@ -45,19 +43,14 @@ services:
KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
env_file:
- .env
depends_on:
postgres:
condition: service_healthy
networks:
- mally-network
command: start --hostname ${KEYCLOAK_URL} --import-realm

api:
container_name: mally-api
image: ghcr.io/neumanf/mally-api
restart: unless-stopped
healthcheck:
test: [ "CMD", "curl", "-f", "http://0.0.0.0:8080/health/" ]
test: curl -f http://localhost:8080/health/
timeout: 45s
interval: 10s
retries: 15
Expand All @@ -73,70 +66,100 @@ services:
- ./logs/api:/app/logs/api
networks:
- mally-network
depends_on:
postgres:
condition: service_healthy
keycloak:
condition: service_healthy
deploy:
mode: replicated
replicas: 2
update_config:
order: start-first
failure_action: rollback
delay: 5s
placement:
constraints:
- node.role == manager

ui:
container_name: mally-ui
image: ghcr.io/neumanf/mally-ui
restart: unless-stopped
healthcheck:
test: curl -f http://localhost || exit 1
timeout: 45s
interval: 10s
retries: 15
networks:
- mally-network
depends_on:
api:
condition: service_healthy
keycloak:
condition: service_healthy
deploy:
mode: replicated
replicas: 2
update_config:
order: start-first
failure_action: rollback
delay: 5s

nginx:
container_name: mally-nginx
image: ghcr.io/neumanf/mally-nginx
restart: unless-stopped
healthcheck:
test: curl -f http://localhost || exit 1
timeout: 45s
interval: 10s
retries: 15
networks:
- mally-network
depends_on:
- api
- ui
ports:
- '80:80'
- '443:443'
volumes:
- ./certbot/www/:/var/www/certbot/:rw
- ./certbot/conf/:/etc/letsencrypt/:rw
deploy:
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 15
placement:
constraints:
- node.role == manager

loki:
container_name: mally-loki
image: ghcr.io/neumanf/mally-loki
restart: unless-stopped
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:3100/ready || exit 1
timeout: 45s
interval: 10s
retries: 15
command: -config.file=/etc/loki/loki.yml
networks:
- mally-network

promtail:
container_name: mally-promtail
image: ghcr.io/neumanf/mally-promtail
restart: unless-stopped
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:9080/ready || exit 1
timeout: 45s
interval: 10s
retries: 15
volumes:
- ./logs/api/:/var/log/
command: -config.file=/etc/promtail/promtail.yml
networks:
- mally-network

prometheus:
container_name: mally-prometheus
image: ghcr.io/neumanf/mally-prometheus
restart: unless-stopped
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:9090 || exit 1
timeout: 45s
interval: 10s
retries: 15
command: '--config.file=/etc/prometheus/config.yml'
networks:
- mally-network

grafana:
container_name: mally-grafana
image: ghcr.io/neumanf/mally-grafana
restart: unless-stopped
healthcheck:
test: curl -f http://localhost:3000/
timeout: 45s
interval: 10s
retries: 15
environment:
GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
Expand Down

0 comments on commit 9505b47

Please sign in to comment.