Merge pull request #1479 from Shelf-nu/1478-improvement-make-sure-nrm… #600
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🐳 Create and publish a Docker image | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
permissions: | |
actions: write | |
contents: read | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
name: 🐳 Build | |
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🛑 Cancel Previous Runs | |
uses: styfle/cancel-workflow-action@0.12.1 | |
- name: ⬇️ Checkout repo | |
uses: actions/checkout@v4.1.1 | |
- name: 🥡 Set up QEMU | |
uses: docker/setup-qemu-action@v3.0.0 | |
- name: ✖️ Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3.2.0 | |
- name: ⚡️ Cache Docker layers | |
uses: actions/cache@v4.0.2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: 👋 Log in to the Container registry | |
uses: docker/login-action@v3.1.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 🧪 Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5.5.1 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
type=ref,enable=${{ github.ref_type != 'tag' }},suffix=-{{sha}},event=branch | |
type=ref,event=tag | |
- name: 🛠 Build and push Docker image | |
uses: docker/build-push-action@v5.3.0 | |
with: | |
context: . | |
file: Dockerfile.image | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
# Note: provenance fixes unknown/unknown platform to be generated on build | |
# https://github.com/orgs/community/discussions/45969#discussioncomment-8170787 | |
# https://github.com/docker/build-push-action/issues/820#issuecomment-1445131521 | |
provenance: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} | |
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} | |
COMMIT_SHA=${{ github.sha }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | |
- name: 🚚 Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |