|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + paths: |
| 7 | + - 'docker/**' |
| 8 | + - '.github/workflows/docker-build.yml' |
| 9 | + pull_request: |
| 10 | + branches: [ main, master ] |
| 11 | + paths: |
| 12 | + - 'docker/**' |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-and-push: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Docker Buildx |
| 24 | + uses: docker/setup-buildx-action@v3 |
| 25 | + |
| 26 | + - name: Log in to Docker Hub |
| 27 | + if: github.event_name != 'pull_request' |
| 28 | + uses: docker/login-action@v3 |
| 29 | + with: |
| 30 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 31 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 32 | + |
| 33 | + - name: Log in to GitHub Container Registry |
| 34 | + if: github.event_name != 'pull_request' |
| 35 | + uses: docker/login-action@v3 |
| 36 | + with: |
| 37 | + registry: ghcr.io |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Extract metadata |
| 42 | + id: meta |
| 43 | + uses: docker/metadata-action@v5 |
| 44 | + with: |
| 45 | + images: | |
| 46 | + ${{ github.repository }}/wan-ip-checker |
| 47 | + ghcr.io/${{ github.repository }}/wan-ip-checker |
| 48 | + tags: | |
| 49 | + type=ref,event=branch |
| 50 | + type=ref,event=pr |
| 51 | + type=raw,value=latest,enable={{is_default_branch}} |
| 52 | + type=sha |
| 53 | + |
| 54 | + - name: Build and push Docker image |
| 55 | + uses: docker/build-push-action@v5 |
| 56 | + with: |
| 57 | + context: ./docker |
| 58 | + file: ./docker/Dockerfile |
| 59 | + push: ${{ github.event_name != 'pull_request' }} |
| 60 | + tags: ${{ steps.meta.outputs.tags }} |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
| 62 | + platforms: linux/amd64,linux/arm64 |
| 63 | + cache-from: type=gha |
| 64 | + cache-to: type=gha,mode=max |
0 commit comments