|
| 1 | +name: 'Docker composite action' |
| 2 | +description: 'Set up Buildx and QEMU + Cache + Metadata + Build and push' |
| 3 | + |
| 4 | +inputs: |
| 5 | + images: |
| 6 | + description: "List of Docker image slugs (eg. name/app)" |
| 7 | + required: true |
| 8 | + context: |
| 9 | + description: "Build's context is the set of files located in the specified PATH or URL. (default Git context)" |
| 10 | + required: false |
| 11 | + file: |
| 12 | + description: "Path to the Dockerfile. (default {context}/Dockerfile)" |
| 13 | + required: false |
| 14 | + platforms: |
| 15 | + description: "List of target platforms (eg. linux/amd64)" |
| 16 | + required: false |
| 17 | + cachekey: |
| 18 | + description: "Cache key for local cache. (default buildx-{github.repository.name})" |
| 19 | + required: false |
| 20 | + default: "buildx-${{ github.repository.name}}" |
| 21 | + push: |
| 22 | + description: "Push image to the registry" |
| 23 | + required: false |
| 24 | + default: "true" |
| 25 | + |
| 26 | +runs: |
| 27 | + using: "composite" |
| 28 | + steps: |
| 29 | + - |
| 30 | + uses: actions/cache@v2 |
| 31 | + with: |
| 32 | + path: /tmp/.buildx-${{ inputs.cachekey }}-cache |
| 33 | + key: ${{ runner.os }}-${{ inputs.cachekey }}-${{ github.sha }} |
| 34 | + restore-keys: | |
| 35 | + ${{ runner.os }}-${{ inputs.cachekey }}- |
| 36 | + - |
| 37 | + id: meta |
| 38 | + uses: docker/metadata-action@v3 |
| 39 | + with: |
| 40 | + images: ${{ inputs.images }} |
| 41 | + tags: | |
| 42 | + type=schedule |
| 43 | + type=ref,event=branch |
| 44 | + type=semver,pattern={{version}} |
| 45 | + type=semver,pattern={{major}}.{{minor}} |
| 46 | + type=semver,pattern={{major}} |
| 47 | + - |
| 48 | + uses: docker/setup-qemu-action@v1 |
| 49 | + - |
| 50 | + uses: docker/setup-buildx-action@v1 |
| 51 | + - |
| 52 | + uses: docker/build-push-action@v2 |
| 53 | + with: |
| 54 | + context: ${{ inputs.context }} |
| 55 | + file: ${{ inputs.file }} |
| 56 | + push: ${{ inputs.push }} |
| 57 | + tags: ${{ steps.meta.outputs.tags }} |
| 58 | + labels: ${{ steps.meta.outputs.labels }} |
| 59 | + platforms: ${{ inputs.platforms }} |
| 60 | + cache-from: type=local,src=/tmp/.${{ inputs.cachekey }}-cache |
| 61 | + cache-to: type=local,dest=/tmp/.${{ inputs.cachekey }}-cache-new,mode=max |
| 62 | + - |
| 63 | + # Temp fix |
| 64 | + # https://github.com/docker/build-push-action/issues/252 |
| 65 | + # https://github.com/moby/buildkit/issues/1896 |
| 66 | + run: | |
| 67 | + rm -rf /tmp/.${{ inputs.cachekey }}-cache |
| 68 | + mv /tmp/.${{ inputs.cachekey }}-cache-new /tmp/.${{ inputs.cachekey }}-cache |
| 69 | + shell: bash |
0 commit comments