Merge pull request #19 from JobDri-Developer/fix/analysis-question-co… #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: Deploy Worker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| IMAGE_NAME: ghcr.io/jobdri-developer/analysis-worker | |
| REMOTE_COMPOSE_FILE: docker-compose.worker.prod.yml | |
| jobs: | |
| build-and-push: | |
| name: Build and Push Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:latest | |
| ${{ env.IMAGE_NAME }}:${{ github.sha }} | |
| deploy: | |
| name: Deploy to Server | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| env: | |
| HAS_DEPLOY_SECRETS: ${{ secrets.DEPLOY_HOST != '' && secrets.DEPLOY_USER != '' && secrets.DEPLOY_SSH_KEY != '' && secrets.DEPLOY_PATH != '' && secrets.GHCR_USERNAME != '' && secrets.GHCR_TOKEN != '' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Skip deploy when server secrets are missing | |
| if: env.HAS_DEPLOY_SECRETS != 'true' | |
| run: echo "Deployment skipped because required server secrets are not configured." | |
| - name: Upload worker compose file | |
| if: env.HAS_DEPLOY_SECRETS == 'true' | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.DEPLOY_HOST }} | |
| username: ${{ secrets.DEPLOY_USER }} | |
| key: ${{ secrets.DEPLOY_SSH_KEY }} | |
| port: ${{ secrets.DEPLOY_PORT || 22 }} | |
| source: deploy/${{ env.REMOTE_COMPOSE_FILE }} | |
| target: ${{ secrets.DEPLOY_PATH }} | |
| strip_components: 1 | |
| - name: Deploy worker with Docker Compose | |
| if: env.HAS_DEPLOY_SECRETS == 'true' | |
| uses: appleboy/ssh-action@v1.2.0 | |
| env: | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| IMAGE_TAG: latest | |
| GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }} | |
| GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} | |
| with: | |
| host: ${{ secrets.DEPLOY_HOST }} | |
| username: ${{ secrets.DEPLOY_USER }} | |
| key: ${{ secrets.DEPLOY_SSH_KEY }} | |
| port: ${{ secrets.DEPLOY_PORT || 22 }} | |
| envs: IMAGE_NAME,IMAGE_TAG,GHCR_USERNAME,GHCR_TOKEN | |
| script: | | |
| set -e | |
| cd "${{ secrets.DEPLOY_PATH }}" | |
| echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin | |
| export WORKER_IMAGE_NAME="$IMAGE_NAME" | |
| export WORKER_IMAGE_TAG="$IMAGE_TAG" | |
| docker compose -f "${{ env.REMOTE_COMPOSE_FILE }}" config --services | grep -Fx worker | |
| docker compose -f "${{ env.REMOTE_COMPOSE_FILE }}" pull worker | |
| docker compose -f "${{ env.REMOTE_COMPOSE_FILE }}" up -d worker | |
| docker image prune -f |