Compare commits
3 Commits
976c5ee10b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bfc5a473e | ||
|
|
3ef332f073 | ||
|
|
c00fc2fbd6 |
64
.gitea/workflows/deploy.yml
Normal file
64
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
name: Deploy API-Ubigeo
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Backup current image
|
||||||
|
run: |
|
||||||
|
docker tag ubigeo-api:latest ubigeo-api:rollback 2>/dev/null || true
|
||||||
|
|
||||||
|
- name: Sync source
|
||||||
|
run: |
|
||||||
|
rsync -a --delete \
|
||||||
|
--exclude='.git' \
|
||||||
|
--exclude='node_modules' \
|
||||||
|
--exclude='dist' \
|
||||||
|
--exclude='.env*' \
|
||||||
|
./ /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: Health check
|
||||||
|
id: health
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
echo "Waiting for API-Ubigeo to start..."
|
||||||
|
for i in $(seq 1 15); do
|
||||||
|
sleep 3
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3200/api/v1/health 2>/dev/null || echo "000")
|
||||||
|
if [ "$HTTP_CODE" != "000" ] && [ "$HTTP_CODE" != "502" ] && [ "$HTTP_CODE" != "503" ]; then
|
||||||
|
echo "✅ Health check passed after $((i*3))s (HTTP $HTTP_CODE)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Attempt $i/15 - not ready yet (HTTP $HTTP_CODE)..."
|
||||||
|
done
|
||||||
|
echo "❌ Health check failed after 45s"
|
||||||
|
docker logs ubigeo-api --tail 50
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Rollback on failure
|
||||||
|
if: steps.health.outcome == 'failure'
|
||||||
|
run: |
|
||||||
|
echo "❌ Deploy failed, rolling back..."
|
||||||
|
docker tag ubigeo-api:rollback ubigeo-api:latest 2>/dev/null || true
|
||||||
|
cd /home/deployer/api-ubigeo
|
||||||
|
docker compose -f docker-compose.production.yml up -d --force-recreate
|
||||||
|
echo "🔄 Rollback complete"
|
||||||
|
exit 1
|
||||||
13
.github/workflows/ci.yml
vendored
13
.github/workflows/ci.yml
vendored
@@ -6,16 +6,15 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: self-hosted
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Generate Prisma client
|
- name: Generate Prisma client
|
||||||
run: npx prisma generate
|
run: npx prisma generate
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
66
.github/workflows/deploy.yml.disabled
vendored
66
.github/workflows/deploy.yml.disabled
vendored
@@ -1,66 +0,0 @@
|
|||||||
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
|
|
||||||
run: |
|
|
||||||
docker run --rm \
|
|
||||||
-v /etc/easypanel/traefik/config:/traefik-config \
|
|
||||||
alpine sh -c '
|
|
||||||
apk add jq -q --no-progress 2>/dev/null
|
|
||||||
FILE=/traefik-config/main.yaml
|
|
||||||
|
|
||||||
if jq -e ".http.routers[\"https-ubigeo-0\"]" "$FILE" > /dev/null 2>&1; then
|
|
||||||
echo "ubigeo route already exists in main.yaml"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
jq ".http.routers[\"http-ubigeo-0\"] = {\"rule\": \"Host(\\\"api-ubigeo.darkcodex.dev\\\") && PathPrefix(\\\"/\\\")\", \"entryPoints\": [\"http\"], \"middlewares\": [\"redirect-to-https\", \"bad-gateway-error-page\"], \"service\": \"ubigeo_api-0\"} |
|
|
||||||
.http.routers[\"https-ubigeo-0\"] = {\"rule\": \"Host(\\\"api-ubigeo.darkcodex.dev\\\") && PathPrefix(\\\"/\\\")\", \"entryPoints\": [\"https\"], \"middlewares\": [\"bad-gateway-error-page\"], \"service\": \"ubigeo_api-0\", \"tls\": {\"certResolver\": \"letsencrypt\"}} |
|
|
||||||
.http.services[\"ubigeo_api-0\"] = {\"loadBalancer\": {\"passHostHeader\": true, \"servers\": [{\"url\": \"http://ubigeo-api:3200/\"}]}}" \
|
|
||||||
"$FILE" > /tmp/main-new.json && mv /tmp/main-new.json "$FILE"
|
|
||||||
echo "Traefik route injected into main.yaml"
|
|
||||||
'
|
|
||||||
|
|
||||||
- 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"
|
|
||||||
17
.github/workflows/sync-gitea.yml
vendored
Normal file
17
.github/workflows/sync-gitea.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
name: Sync to Gitea
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
name: Push to Gitea
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Push to Gitea
|
||||||
|
run: |
|
||||||
|
git push https://${{ secrets.GITEA_TOKEN }}@git.darkcodex.dev/darkcodex/api-ubigeo.git main --force
|
||||||
Reference in New Issue
Block a user