61 lines
2.2 KiB
YAML
61 lines
2.2 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
if [ ! -d /workspace/darkcodex/api-ubigeo/.git ]; then
|
|
git clone https://948ee86882f8d9ca46eb94750addfccdace443a6@git.darkcodex.dev/darkcodex/api-ubigeo.git \
|
|
/workspace/darkcodex/api-ubigeo
|
|
fi
|
|
cd /workspace/darkcodex/api-ubigeo
|
|
git fetch origin main
|
|
git reset --hard origin/main
|
|
|
|
- name: Sync source
|
|
run: |
|
|
rsync -a --delete \
|
|
--exclude='.git' \
|
|
--exclude='node_modules' \
|
|
--exclude='dist' \
|
|
--exclude='.env' \
|
|
/workspace/darkcodex/api-ubigeo/ /home/deployer/api-ubigeo/
|
|
|
|
- name: Build image
|
|
run: |
|
|
cd /home/deployer/api-ubigeo
|
|
docker build -t ubigeo-api:latest .
|
|
|
|
- name: Deploy containers
|
|
run: |
|
|
cd /home/deployer/api-ubigeo
|
|
docker compose -f docker-compose.production.yml down --remove-orphans
|
|
docker compose -f docker-compose.production.yml up -d
|
|
|
|
- name: Register Traefik route
|
|
env:
|
|
TRAEFIK_RULE: "Host(`api-ubigeo.darkcodex.dev`)"
|
|
run: |
|
|
docker run --rm \
|
|
-e TRAEFIK_RULE \
|
|
-v /etc/easypanel/traefik/config:/traefik-config \
|
|
alpine sh -c '
|
|
OUT=/traefik-config/api-ubigeo.yaml
|
|
[ -f "$OUT" ] && echo "route already exists" && exit 0
|
|
printf "http:\n routers:\n ubigeo-api:\n rule: \"%s\"\n service: ubigeo-api\n entryPoints:\n - websecure\n tls:\n certResolver: letsencrypt\n services:\n ubigeo-api:\n loadBalancer:\n servers:\n - url: \"http://ubigeo-api:3200\"\n" "$TRAEFIK_RULE" > "$OUT"
|
|
echo "Traefik route created"
|
|
'
|
|
|
|
- name: Health check
|
|
run: |
|
|
sleep 15
|
|
STATUS=$(wget -qO- http://ubigeo-api:3200/api/v1/health 2>/dev/null || echo "fail")
|
|
echo "Health: $STATUS"
|
|
echo "$STATUS" | grep -q "ok" && echo "Deploy OK" || echo "Warning: health check unreachable from runner"
|