|
| 1 | +name: Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: {} |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + FULL_IMAGE_NAME: ghcr.io/${{ github.repository }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + push-image: |
| 19 | + name: Build and push image |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + |
| 34 | + - name: Log in to GitHub Container Registry |
| 35 | + uses: docker/login-action@v3 |
| 36 | + with: |
| 37 | + registry: ${{ env.REGISTRY }} |
| 38 | + username: ${{ github.repository_owner }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Extract metadata for Docker |
| 42 | + id: meta |
| 43 | + uses: docker/metadata-action@v5 |
| 44 | + with: |
| 45 | + images: ${{ env.FULL_IMAGE_NAME }} |
| 46 | + tags: | |
| 47 | + type=ref,event=branch |
| 48 | + type=ref,event=tag |
| 49 | + type=semver,pattern={{version}} |
| 50 | + type=semver,pattern={{major}}.{{minor}} |
| 51 | + type=sha,prefix= |
| 52 | + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} |
| 53 | +
|
| 54 | + - name: Build and push Docker image |
| 55 | + uses: docker/build-push-action@v5 |
| 56 | + with: |
| 57 | + context: . |
| 58 | + file: ./Dockerfile |
| 59 | + push: true |
| 60 | + tags: ${{ steps.meta.outputs.tags }} |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
| 62 | + |
| 63 | + deploy-to-dev: |
| 64 | + name: Deploy to dev |
| 65 | + runs-on: ubuntu-latest |
| 66 | + needs: push-image |
| 67 | + if: github.ref == 'refs/heads/main' |
| 68 | + environment: |
| 69 | + name: dev |
| 70 | + url: ${{ vars.APP_URL }} |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Deploy via SSH |
| 74 | + uses: appleboy/ssh-action@v1.2.4 |
| 75 | + with: |
| 76 | + host: ${{ secrets.SSH_HOST }} |
| 77 | + username: ${{ secrets.SSH_USER }} |
| 78 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 79 | + port: ${{ secrets.SSH_PORT || 22 }} |
| 80 | + fingerprint: ${{ secrets.SSH_HOST_FINGERPRINT }} |
| 81 | + script: deploy dev |
0 commit comments