Files
soroushasadi/.gitea/workflows/deploy.yml
T
soroush.asadi 059c67bf76 Fix deploy: free port 3000 by removing any container publishing it
The previous name-based stop only removed soroushasadi-site, but the
container holding :3000 can have a different name (old Next.js build or
an orphan from a previously-named compose project), so the bind kept
failing. Now we remove every container publishing :3000 by filter, then
also remove by our known name as a fallback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 08:29:14 +03:30

77 lines
2.1 KiB
YAML

name: deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: self-hosted
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
REF: ${{ github.ref }}
GIT_SSL_NO_VERIFY: "true"
run: |
git init
git remote remove origin 2>/dev/null || true
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git config http.extraheader "Authorization: Bearer ${TOKEN}"
git fetch --depth=1 origin "${REF}"
git checkout FETCH_HEAD
- name: Create Environment File
run: |
cat > .env << EOF
ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }}
RESEND_API_KEY=${{ secrets.RESEND_API_KEY }}
CONTACT_INBOX=${{ secrets.CONTACT_INBOX }}
CONTACT_FROM=${{ secrets.CONTACT_FROM }}
EOF
- name: Build Container
run: docker compose build
- name: Free Port 3000
run: |
# Remove any container publishing :3000 (old Next.js container,
# orphans from a previously-named compose project, etc.)
OLD=$(docker ps -a --filter publish=3000 -q)
if [ -n "$OLD" ]; then
echo "Removing containers on :3000 -> $OLD"
docker rm -f $OLD || true
fi
# Belt and suspenders: also remove by our known name.
docker rm -f soroushasadi-site 2>/dev/null || true
- name: Deploy
run: docker compose up -d --remove-orphans
- name: Wait For Health Check
run: |
for i in $(seq 1 30); do
STATUS=$(docker inspect \
--format='{{.State.Health.Status}}' \
soroushasadi-site 2>/dev/null)
echo "Status: $STATUS"
if [ "$STATUS" = "healthy" ]; then
echo "Deployment successful"
exit 0
fi
sleep 5
done
docker logs soroushasadi-site --tail 100
exit 1
- name: Cleanup
if: success()
run: docker image prune -f