|
11 | 11 | branches: |
12 | 12 | - develop |
13 | 13 | - main |
| 14 | + types: |
| 15 | + - labeled |
| 16 | + |
| 17 | +env: |
| 18 | + REGISTRY_IMAGE: ${{ secrets.DOCKER_USERNAME }}/status-frontend |
| 19 | + PR_ID: ${{ github.event.pull_request.number }} |
| 20 | + TAG: ${{ github.ref_name }} |
14 | 21 |
|
15 | 22 | jobs: |
16 | 23 | build: |
17 | 24 | runs-on: ubuntu-latest |
| 25 | + if: (github.event.pull_request && github.event.label.name == 'dockerize') || github.event_name == 'push' |
18 | 26 |
|
19 | 27 | steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v2 |
22 | | - |
23 | | - - name: Set up Docker Buildx |
24 | | - uses: docker/setup-buildx-action@v2 |
| 28 | + - name: Checkout ⬇️ |
| 29 | + |
25 | 30 | with: |
26 | | - install: true |
| 31 | + show-progress: false |
| 32 | + |
| 33 | + - name: Configure QEMU ⚙️ |
| 34 | + |
27 | 35 |
|
28 | | - - name: Login to DockerHub |
29 | | - uses: docker/login-action@v2 |
| 36 | + - name: Configure Docker Buildx ⚙️ |
| 37 | + |
| 38 | + |
| 39 | + - name: Login to DockerHub 🔑 |
| 40 | + |
30 | 41 | with: |
31 | 42 | username: ${{ secrets.DOCKER_USERNAME }} |
32 | 43 | password: ${{ secrets.DOCKER_PASSWORD }} |
33 | 44 |
|
34 | | - - name: Create Docker Buildx Builder |
35 | | - run: | |
36 | | - docker buildx create --name mybuilder --use |
37 | | - docker buildx inspect --bootstrap |
38 | | -
|
39 | | - - name: Build and Push Docker Image (Develop) |
40 | | - if: github.ref == 'refs/heads/develop' |
41 | | - run: | |
42 | | - docker buildx build \ |
43 | | - --platform linux/amd64,linux/arm64 \ |
44 | | - --push \ |
45 | | - -t ${{ secrets.DOCKER_USERNAME }}/status-frontend:develop . |
46 | | -
|
47 | | - - name: Build and Push Docker Image (Version Tags) |
48 | | - if: startsWith(github.ref, 'refs/tags/') |
49 | | - run: | |
50 | | - TAG=$(echo "${GITHUB_REF#refs/tags/}") |
51 | | - docker buildx build \ |
52 | | - --platform linux/amd64,linux/arm64 \ |
53 | | - --push \ |
54 | | - -t ${{ secrets.DOCKER_USERNAME }}/status-frontend:$TAG . |
55 | | -
|
56 | | - - name: Build and Push Docker Image for Pull Request |
57 | | - if: github.event_name == 'pull_request' |
58 | | - run: | |
59 | | - PR_ID=${{ github.event.pull_request.number }} |
60 | | - docker buildx build \ |
61 | | - --platform linux/amd64,linux/arm64 \ |
62 | | - --push \ |
63 | | - -t ${{ secrets.DOCKER_USERNAME }}/status-frontend:PR.$PR_ID . |
| 45 | + - name: Build and Push Docker Image |
| 46 | + |
| 47 | + with: |
| 48 | + context: . |
| 49 | + file: Dockerfile |
| 50 | + platforms: linux/amd64,linux/arm64 |
| 51 | + push: true |
| 52 | + cache-from: type=gha |
| 53 | + cache-to: type=gha,mode=max |
| 54 | + tags: | |
| 55 | + ${{ startsWith(github.ref, 'refs/tags/') && format('{0}:{1}', env.REGISTRY_IMAGE, env.TAG) || '' }} |
| 56 | + ${{ github.ref == 'refs/heads/main' && format('{0}:latest', env.REGISTRY_IMAGE) || '' }} |
| 57 | + ${{ github.ref == 'refs/heads/develop' && format('{0}:develop', env.REGISTRY_IMAGE) || '' }} |
| 58 | + ${{ github.event_name == 'pull_request' && format('{0}:PR.{1}', env.REGISTRY_IMAGE, env.PR_ID) || '' }} |
0 commit comments