|
| 1 | +name: Build Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + image_tag: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + ghcr_username: |
| 10 | + type: string |
| 11 | + required: true |
| 12 | + ghcr_image_name: |
| 13 | + type: string |
| 14 | + required: true |
| 15 | + secrets: |
| 16 | + ghcr_token: |
| 17 | + required: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: Build Docker Image |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout the Repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Cache Docker Layers |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: /tmp/.buildx-cache |
| 37 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-buildx- |
| 40 | +
|
| 41 | + - name: Login to GitHub Container Registry |
| 42 | + uses: docker/login-action@v3 |
| 43 | + with: |
| 44 | + registry: ghcr.io |
| 45 | + username: ${{ inputs.ghcr_username }} |
| 46 | + password: ${{ secrets.ghcr_token }} |
| 47 | + |
| 48 | + - name: Build & Push Docker Image (linux/amd64) |
| 49 | + id: docker_build_amd64 |
| 50 | + uses: docker/build-push-action@v6 |
| 51 | + env: |
| 52 | + GHCR_IMAGE: ghcr.io/${{ inputs.ghcr_image_name }} |
| 53 | + with: |
| 54 | + context: . |
| 55 | + file: amd64.Dockerfile |
| 56 | + push: true |
| 57 | + tags: | |
| 58 | + ${{ env.GHCR_IMAGE }}:${{ inputs.image_tag }} |
| 59 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 60 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 61 | + platforms: linux/amd64 |
| 62 | + |
| 63 | + - name: Image Digest (linux/amd64) |
| 64 | + run: echo ${{ steps.docker_build_amd64.outputs.digest }} |
| 65 | + |
| 66 | + - name: Build & Push Docker Image (linux/arm64) |
| 67 | + id: docker_build_arm64 |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + env: |
| 70 | + GHCR_IMAGE: ghcr.io/${{ inputs.ghcr_image_name }}-arm |
| 71 | + with: |
| 72 | + context: . |
| 73 | + file: arm64.Dockerfile |
| 74 | + push: true |
| 75 | + tags: | |
| 76 | + ${{ env.GHCR_IMAGE }}:${{ inputs.image_tag }} |
| 77 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 78 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 79 | + platforms: linux/arm64/v8 |
| 80 | + |
| 81 | + - name: Image Digest (linux/arm64) |
| 82 | + run: echo ${{ steps.docker_build_arm64.outputs.digest }} |
0 commit comments