aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/deploy.yml
blob: eaf5099fe834d0c5c9af7a548e28e4afaf97b3a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Deploy

on:
  workflow_run:
    workflows: 
      - "Build"
      - "build.yml"
    types:
      - completed
    branches: 
      - main
  workflow_dispatch:

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    env:
      IMAGE_URL: ""
      APP_SERVER: ${{ secrets.APP_SERVER }}
      APP_NAME: ${{ secrets.APP_NAME }}
      APP_TOKEN: ${{ secrets.APP_TOKEN }}

    steps:
      - name: Debug workflow run info
        run: |
          echo "Workflow run conclusion: ${{ github.event.workflow_run.conclusion }}"
          echo "Workflow run status: ${{ github.event.workflow_run.status }}"
          echo "Workflow run name: ${{ github.event.workflow_run.name }}"
          echo "Branch: ${{ github.event.workflow_run.head_branch }}"
          
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Preset Image Name
        id: set_image_url
        run: |
          IMAGE_URL=$(echo ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:$(echo ${{ github.sha }} | cut -c1-7) | tr '[:upper:]' '[:lower:]')
          echo "IMAGE_URL=$IMAGE_URL" >> $GITHUB_ENV
          echo "image_url=$IMAGE_URL" >> $GITHUB_OUTPUT

      - name: Build and push Docker Image
        uses: docker/build-push-action@v5
        with:
          context: .
          file: ./Dockerfile
          push: true
          platforms: linux/arm64/v8
          tags: ${{ steps.set_image_url.outputs.image_url }}

      - name: Deploy Image to Server
        uses: caprover/[email protected]
        with:
          server: ${{ env.APP_SERVER }}
          app: ${{ env.APP_NAME }}
          token: ${{ env.APP_TOKEN }}
          image: ${{ steps.set_image_url.outputs.image_url }}