Skip to content

Upgrade to Node v20 #24

Upgrade to Node v20

Upgrade to Node v20 #24

Workflow file for this run

name: "Publish Docker Image"
on:
push:
branches:
- "main"
tags:
- "v*"
pull_request:
branches:
- "main"
env:
IMAGE_NAME: 'shopify-checkout-starter'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: Set outputs
id: set-outputs
run: |
echo 'image=ghcr.io/the-vaan-group/${{ env.IMAGE_NAME }}' >> "${GITHUB_OUTPUT}"
# Only enable push on push events or pull requests coming from the same repository, except from dependabot
echo 'push=${{ github.event_name == 'push' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}' >> "${GITHUB_OUTPUT}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ steps.set-outputs.outputs.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
outputs:
image: ${{ steps.set-outputs.outputs.image }}
push: ${{ steps.set-outputs.outputs.push }}
meta-version: ${{ steps.meta.outputs.version }}
meta-labels: ${{ steps.meta.outputs.labels }}
meta-json: ${{ steps.meta.outputs.json }}
build:
needs:
- prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
if: needs.prepare.outputs.push == 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set cache flags
id: cache-flags
run: |
# Set the cache-to output
echo 'cache-to=type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}' >> "${GITHUB_OUTPUT}"
# Set the cache-from output
if [[ '${{ github.event_name }}' == 'push' ]]; then
echo 'cache-from=type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}' >> "${GITHUB_OUTPUT}"
else
# Use cache from target branch too when building a pull request
# In this case, it has to be a multiline string
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "cache-from<<${EOF}" >> "${GITHUB_OUTPUT}"
printf '%s\n' \
"type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}" \
"type=gha,scope=${{ github.base_ref }}-${{ matrix.platform }}" \
>> "${GITHUB_OUTPUT}"
echo "${EOF}" >> "${GITHUB_OUTPUT}"
fi
- name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ needs.prepare.outputs.meta-labels }}
outputs: |
type=image,name=${{ needs.prepare.outputs.image }},push-by-digest=true,name-canonical=true,push=${{ needs.prepare.outputs.push }}
cache-from: |
${{ steps.cache-flags.outputs.cache-from }}
cache-to: |
${{ steps.cache-flags.outputs.cache-to }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest='${{ steps.build.outputs.digest }}'
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
push:
needs:
- prepare
- build
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
if: needs.prepare.outputs.push == 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
if: needs.prepare.outputs.push == 'true'
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -r '"-t " + (.tags | join(" -t "))' <<< '${{ needs.prepare.outputs.meta-json }}') \
$(printf '${{ needs.prepare.outputs.image }}@sha256:%s ' *)
- name: Inspect image
if: needs.prepare.outputs.push == 'true'
run: |
docker buildx imagetools inspect '${{ needs.prepare.outputs.image }}:${{ needs.prepare.outputs.meta-version }}'