-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: docker compose files and deploy.sh [skip ci]
- Loading branch information
Showing
7 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
services: | ||
dku-nginx: | ||
container_name: dku-nginx | ||
image: nginx:1 | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf | ||
environment: | ||
VIRTUAL_HOST: dku-aegis-library-system.seongmin.dev | ||
VIRTUAL_PORT: 80 | ||
networks: | ||
- dku | ||
depends_on: | ||
- dku-blue-app-1 | ||
- dku-blue-app-2 | ||
- dku-green-app-1 | ||
- dku-green-app-2 | ||
|
||
dku-blue-app-1: | ||
container_name: dku-app-blue-1 | ||
image: ghcr.io/ilcm96/dku-aegis-library-system:latest | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: blue | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
dku-blue-app-2: | ||
container_name: dku-app-blue-2 | ||
image: ghcr.io/ilcm96/dku-aegis-library-system:latest | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: blue | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
dku-green-app-1: | ||
container_name: dku-app-green-1 | ||
image: ghcr.io/ilcm96/dku-aegis-library-system:latest | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: green | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
dku-green-app-2: | ||
container_name: dku-app-green-2 | ||
image: ghcr.io/ilcm96/dku-aegis-library-system:latest | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: green | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
networks: | ||
dku: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
services: | ||
dku-nginx: | ||
container_name: dku-nginx | ||
image: nginx:1 | ||
volumes: | ||
- ./nginx.local.conf:/etc/nginx/nginx.conf | ||
networks: | ||
- dku | ||
depends_on: | ||
- dku-blue-app-1 | ||
- dku-blue-app-2 | ||
- dku-green-app-1 | ||
- dku-green-app-2 | ||
|
||
dku-blue-app-1: | ||
container_name: dku-app-blue-1 | ||
build: . | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: blue | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
dku-blue-app-2: | ||
container_name: dku-app-blue-2 | ||
build: . | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: blue | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
dku-green-app-1: | ||
container_name: dku-app-green-1 | ||
build: . | ||
restart: on-failure:5 | ||
depends_on: | ||
- dku-blue-app-1 | ||
environment: | ||
COLOR: green | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
dku-green-app-2: | ||
container_name: dku-app-green-2 | ||
build: . | ||
restart: on-failure:5 | ||
environment: | ||
COLOR: green | ||
PORT: ${PORT} | ||
DB_USER: ${DB_USER} | ||
DB_PASSWORD: ${DB_PASSWORD} | ||
DB_HOST: ${DB_HOST} | ||
DB_PORT: ${DB_PORT} | ||
DB_NAME: ${DB_NAME} | ||
MINIO_HOST: ${MINIO_HOST} | ||
MINIO_PORT: ${MINIO_PORT} | ||
MINIO_KEY: ${MINIO_KEY} | ||
MINIO_SECRET: ${MINIO_SECRET} | ||
REDIS_HOST: ${REDIS_HOST} | ||
REDIS_PORT: ${REDIS_PORT} | ||
networks: | ||
- dku | ||
|
||
networks: | ||
dku: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
services: | ||
minio: | ||
container_name: dku-minio | ||
image: quay.io/minio/minio:latest | ||
command: server /data --console-address ":9001" | ||
ports: | ||
- "9000:9000" | ||
- "9001:9001" | ||
volumes: | ||
- minio-data:/data | ||
environment: | ||
MINIO_ROOT_USER: ${MINIO_USER} | ||
MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD} | ||
VIRTUAL_HOST: minio.seongmin.dev | ||
VIRTUAL_PORT: ${MINIO_PORT} | ||
|
||
networks: | ||
- dku | ||
volumes: | ||
minio-data: | ||
|
||
networks: | ||
dku: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
services: | ||
postgresql: | ||
container_name: dku-postgresql | ||
image: postgres:alpine | ||
command: postgres -c max_connections=1500 -c shared_buffers=8GB -c effective_cache_size=18GB -c work_mem=32MB -c maintenance_work_mem=1GB | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- postgresql-data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_USER: ${DB_USER} | ||
POSTGRES_PASSWORD: ${DB_PASSWORD} | ||
POSTGRES_DB: ${DB_NAME} | ||
networks: | ||
- dku | ||
|
||
volumes: | ||
postgresql-data: | ||
|
||
networks: | ||
dku: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
redis: | ||
container_name: dku-redis | ||
image: redis:alpine | ||
ports: | ||
- "6379:6379" | ||
volumes: | ||
- redis-data:/data | ||
networks: | ||
- dku | ||
|
||
volumes: | ||
redis-data: | ||
|
||
networks: | ||
dku: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "CURRENT SERVER: Oracel Arm Seoul" | ||
|
||
cd /home/ubuntu/docker/dku-aegis-library-system | ||
|
||
CURRENT_COLOR=$(curl -s https://dku-aegis-library-system.seongmin.dev/color) | ||
|
||
if [ "$CURRENT_COLOR" == "blue" ]; then | ||
NEW_COLOR="green" | ||
else | ||
NEW_COLOR="blue" | ||
fi | ||
|
||
echo "Current color is $CURRENT_COLOR. Deploying to $NEW_COLOR..." | ||
|
||
docker compose -f compose-app.yml pull | ||
docker compose -f compose-app.yml up -d dku-${NEW_COLOR}-app-1 dku-${NEW_COLOR}-app-2 | ||
|
||
echo "New version deployed to $NEW_COLOR. Checking health..." | ||
|
||
# Here you should add health check logic for the new version | ||
# This example assumes the health check endpoint is /health | ||
HEALTHY=0 | ||
for i in {1..10}; do | ||
if docker compose -f compose-app.yml exec -T dku-nginx bash -c "curl -s http://dku-${NEW_COLOR}-app-1:3000/health" | grep -q "OK"; then | ||
HEALTHY=$((HEALTHY + 1)) | ||
fi | ||
if docker compose -f compose-app.yml exec -T dku-nginx bash -c "curl -s http://dku-${NEW_COLOR}-app-2:3000/health" | grep -q "OK"; then | ||
HEALTHY=$((HEALTHY + 1)) | ||
fi | ||
if [ "$HEALTHY" -ge 2 ]; then | ||
break | ||
fi | ||
echo "Waiting for the new version to become healthy..." | ||
sleep 3 | ||
done | ||
|
||
if [ "$HEALTHY" -lt 2 ]; then | ||
echo "New version is not healthy. Aborting." | ||
docker compose -f compose-app.yml stop ${NEW_COLOR}-app-1 ${NEW_COLOR}-app-2 | ||
exit 1 | ||
fi | ||
|
||
echo "New version is healthy. Switching traffic to $NEW_COLOR..." | ||
|
||
# Update Nginx environment variable and reload | ||
# Not work on alpine image due to different behavior of cp -f | ||
docker compose -f compose-app.yml exec -T dku-nginx bash -c "sed "s/${CURRENT_COLOR}/${NEW_COLOR}/g" /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.tmp \ | ||
&& cp -f /etc/nginx/nginx.conf.tmp /etc/nginx/nginx.conf \ | ||
&& rm /etc/nginx/nginx.conf.tmp \ | ||
&& nginx -s reload" | ||
|
||
echo "Traffic switched to $NEW_COLOR. Stopping old version..." | ||
|
||
# Stop the old version | ||
docker compose -f compose-app.yml stop dku-${CURRENT_COLOR}-app-1 dku-${CURRENT_COLOR}-app-2 | ||
|
||
echo "Deployment complete. Now serving $NEW_COLOR." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
events { | ||
worker_connections 10240; | ||
} | ||
|
||
http { | ||
upstream color { | ||
server dku-blue-app-1:3000; | ||
server dku-blue-app-2:3000; | ||
} | ||
|
||
server { | ||
listen 80; | ||
|
||
location / { | ||
proxy_pass http://color; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
} |