|
1 | | -name: Build and Push Docker Image |
| 1 | +name: Build and Push Docker image |
2 | 2 |
|
3 | 3 | on: |
4 | 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/**' |
| 5 | + branches: |
| 6 | + - main |
13 | 7 | workflow_dispatch: |
14 | 8 |
|
15 | 9 | jobs: |
16 | 10 | build-and-push: |
17 | 11 | runs-on: ubuntu-latest |
18 | | - |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + |
19 | 16 | 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 |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Log in to GitHub Container Registry |
| 21 | + uses: docker/login-action@v3 |
| 22 | + with: |
| 23 | + registry: ghcr.io |
| 24 | + username: ${{ github.actor }} |
| 25 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + |
| 27 | + - name: Build Docker image |
| 28 | + run: | |
| 29 | + docker build -t ghcr.io/${{ github.repository }}:latest ./docker |
| 30 | +
|
| 31 | + - name: Push Docker image |
| 32 | + run: | |
| 33 | + docker push ghcr.io/${{ github.repository }}:latest |
0 commit comments