CI Pipeline: definitions fix #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI + Deploy to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| concurrency: | |
| group: deploy-nextjs-main | |
| cancel-in-progress: false | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test -- --runInBand | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| environment: production | |
| steps: | |
| - name: Deploy over SSH | |
| uses: appleboy/ssh-action@v1.2.0 | |
| env: | |
| DEPLOY_BRANCH: main | |
| DEPLOY_PATH: ${{ vars.VPS_NEXTJS_APP_DIR }} | |
| IMAGE_NAME: nextjs-app | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT }} | |
| script_stop: true | |
| envs: DEPLOY_BRANCH,DEPLOY_PATH,IMAGE_NAME | |
| script: | | |
| set -euo pipefail | |
| cd "$DEPLOY_PATH" | |
| git fetch origin "$DEPLOY_BRANCH" | |
| git checkout "$DEPLOY_BRANCH" | |
| git reset --hard "origin/$DEPLOY_BRANCH" | |
| docker build -t "$IMAGE_NAME" . | |
| cd ~/app | |
| docker compose up -d mysql_nextjs redis | |
| docker compose run --rm -e RUN_MIGRATIONS=1 nextjs true | |
| docker compose up -d nextjs | |
| docker image prune -f |