first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches-ignore:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: self-hosted
|
||||
|
||||
env:
|
||||
DOCKER_BUILDKIT: 1
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
env:
|
||||
TOKEN: ${{ github.token }}
|
||||
REF: ${{ github.ref }}
|
||||
run: |
|
||||
git init
|
||||
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: Docker Build Test
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
docker build \
|
||||
--build-arg NPM_TOKEN="$NPM_TOKEN" \
|
||||
-t soroushasadi-site:test .
|
||||
@@ -0,0 +1,73 @@
|
||||
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 }}
|
||||
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 }}
|
||||
ADMIN_SESSION_SECRET=${{ secrets.ADMIN_SESSION_SECRET }}
|
||||
RESEND_API_KEY=${{ secrets.RESEND_API_KEY }}
|
||||
CONTACT_INBOX=${{ secrets.CONTACT_INBOX }}
|
||||
CONTACT_FROM=${{ secrets.CONTACT_FROM }}
|
||||
NPM_TOKEN=${{ secrets.NPM_TOKEN }}
|
||||
EOF
|
||||
|
||||
- name: Build Container
|
||||
run: |
|
||||
docker compose build
|
||||
|
||||
- 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
|
||||
Reference in New Issue
Block a user