Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Deploy
name: CI/CD Pipeline

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # manual button — also lets you redeploy any commit
# (this is our "rollback")

Expand All @@ -16,7 +18,7 @@ env:
NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL_PROD }}

jobs:
deploy:
build-and-deploy:
runs-on: ubuntu-latest
timeout-minutes: 15

Expand All @@ -41,14 +43,16 @@ jobs:
run: pnpm build

- name: Prepare production build
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
run: |
mkdir -p dist/api dist/db
pnpm --filter @repo/api deploy --prod dist/api
pnpm --filter @repo/database deploy --prod dist/db

- name: Create release zip
- name: Create release tarball
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
run: |
zip -qq -r release.zip \
tar -czf release.tar.gz \
docker-compose.prod.yml \
docker/Dockerfile.api \
docker/Dockerfile.web \
Expand All @@ -58,22 +62,25 @@ jobs:
apps/web/.next/static

- name: Write .env from secret
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
env:
PROD_ENV: ${{ secrets.PROD_ENV }}
run: |
printf '%s\n' "$PROD_ENV" > _env

- name: Copy files to VM
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "release.zip,_env"
source: "release.tar.gz,_env"
target: "/home/dittya/projects/canvasflow"

- name: Deploy via Docker Compose
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
Expand All @@ -85,8 +92,8 @@ jobs:
cd /home/dittya/projects/canvasflow

# Extract release bundle
unzip -o release.zip
rm release.zip
tar -xzf release.tar.gz
rm release.tar.gz
mv _env .env
chmod 600 .env

Expand All @@ -97,7 +104,7 @@ jobs:
docker image prune -f

- name: Summary
if: success()
if: (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch') && success()
run: |
echo "### ✅ Deployed from \`${{ github.sha }}\` via Docker Compose" >> "$GITHUB_STEP_SUMMARY"
echo "- web: https://canvasflow.dittya.dev" >> "$GITHUB_STEP_SUMMARY"
Expand Down
Loading