Compare commits

...
2 Commits
2 changed files with 55 additions and 22 deletions
+32 -4
View File
@@ -1,8 +1,36 @@
#!/usr/bin/env zsh
echo updating docker compose with latest build image
set -e
echo "pulling latest build image..."
docker compose pull
docker compose up -d
echo finished updating and builing. Site will be down for a few seconds
# Check which service is running
if docker compose ps blog-blue --filter "status=running" -q | grep -q .; then
CURRENT="blog-blue"
TARGET="blog-green"
else
CURRENT="blog-green"
TARGET="blog-blue"
fi
echo "Current: $CURRENT -> deploying Target: $TARGET"
# TODO dont run if 0 instances running
# Scale current deployment to two instances, keeping the old one and adding a running env of the new one
docker compose up -d --no-deps $TARGET
echo "waiting for $TARGET to pass healthcheck..."
# docker ps --filter 'label=com.docker.compose.service=blog' --filter 'health=starting'
until [[ "$(docker inspect --format '{{.State.Health.Status}}' $(docker compose ps -q $TARGET) 2>/dev/null)" == "healthy" ]]; do
sleep 1
done
# Give traefik backend a few seconds to update
sleep 3
echo "Stopping $CURRENT..."
docker compose stop $CURRENT
docker compose rm -f $CURRENT
echo "Zero downtime deployment to $TARGET complete."
# TODO zero downtime deployment
# TODO run on a cron job
+23 -18
View File
@@ -1,25 +1,30 @@
services:
web:
build:
context: .
dockerfile: Dockerfile
args:
SITE_DOMAIN: "${SITE_DOMAIN:?Error: SITE_DOMAIN is not set. Please define SITE_DOMAIN in .env}"
SITE_URL: "${SITE_URL:-https://${SITE_DOMAIN}}"
PORT: "${PORT:-8080}"
image: river-rooks-blog:latest
container_name: river_rooks_web
x-blog-templage: &blog-base
image: git.riverrooks.dev/venus/river-rooks-blog:latest
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "test/healthcheck.js"]
interval: 30s
timeout: 3s
start_period: 3s
retries: 3
volumes:
- "./posts:/app/src/posts"
environment:
- "SITE_DOMAIN=${SITE_DOMAIN:?Error: SITE_DOMAIN is not set. Please define SITE_DOMAIN in .env}"
- "SITE_URL=${SITE_URL:-https://${SITE_DOMAIN}}"
- "PORT=${PORT:-8080}"
- "WATCH=true"
- "API_SECRET=${API_SECRET}"
ports:
- "${HOST_PORT:-${PORT:-8080}}:${PORT:-8080}"
networks:
- backend
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:${PORT:-8080}/healthz > /dev/null || exit 1"]
interval: 5s
timeout: 3s
retries: 3
start_period: 5s
# I Have this deployed with a series of traefik labels but that's not strictly nessescary
services:
blog-blue:
<<: *blog-base
blog-green:
<<: *blog-base
networks:
backend:
external: true