Skip to content

feat(CI): Adds GitHub Actions Multi-Platform Dev Container Builds (#3… #1

feat(CI): Adds GitHub Actions Multi-Platform Dev Container Builds (#3…

feat(CI): Adds GitHub Actions Multi-Platform Dev Container Builds (#3… #1

Workflow file for this run

name: Build and Publish Images
on:
workflow_dispatch:
push:
branches:
- main
concurrency:
group: '${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
env:
PHP_STABLE_VERSION: '8.3'
NODE_STABLE_VERSION: '20'
REGISTRY: ghcr.io
OWNER: ndigitals
PACKAGE: wp-dev-container
ACTION_VERSION: 1
jobs:
build:
name: Build Images
strategy:
fail-fast: false
matrix:
PHP_VERSION:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
NODE_VERSION:
- '16'
- '18'
- '20'
builder:
- ubuntu-22.04
- self-hosted
platform:
- amd64
- arm64
exclude:
- builder: ubuntu-22.04
platform: arm64
- builder: self-hosted
platform: amd64
runs-on:
- ${{ matrix.builder }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://github.com/marketplace/actions/docker-login
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false
# https://github.com/marketplace/actions/docker-metadata-action
- name: Docker Metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.PACKAGE }}
tags: type=raw,value=php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}
flavor: suffix=-${{ matrix.platform }}
# https://github.com/marketplace/actions/setup-node-js-environment
- name: Setup Node Environment
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'
# https://github.com/marketplace/actions/dev-container-build-and-run-action
- name: Pre-build dev container image
uses: devcontainers/[email protected]
env:
PHP_VERSION: ${{ matrix.PHP_VERSION }}
NODE_VERSION: ${{ matrix.NODE_VERSION }}
with:
platform: linux/${{ matrix.platform }}
imageName: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.PACKAGE }}
cacheFrom: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.PACKAGE }}
imageTag: php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-${{ matrix.platform }}
push: never
skipContainerUserIdUpdate: true
- name: Copy Container to Storage
run: skopeo copy containers-storage:${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.PACKAGE }}:php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-${{ matrix.platform }} oci-archive:/tmp/${{ matrix.platform }}/php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-oci.tar
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload Digests
uses: actions/upload-artifact@v3
with:
name: ${{ env.PACKAGE }}-php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-${{ matrix.platform }}
path: /tmp/${{ matrix.platform }}/php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-oci.tar
if-no-files-found: error
retention-days: 1
upload:
name: Upload Images
needs: build
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
PHP_VERSION:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
NODE_VERSION:
- '16'
- '18'
- '20'
runs-on: ubuntu-latest
steps:
- name: Download Digests - amd64
uses: actions/download-artifact@v3
with:
name: ${{ env.PACKAGE }}-php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-amd64
path: /tmp
- name: Download Digests - arm64
uses: actions/download-artifact@v3
with:
name: ${{ env.PACKAGE }}-php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}-arm64
path: /tmp
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://github.com/marketplace/actions/docker-login
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false
# https://github.com/marketplace/actions/docker-metadata-action
- name: Docker Metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.PACKAGE }}
tags: type=raw,value=php-${{ matrix.PHP_VERSION }}-node-${{ matrix.NODE_VERSION }}
- name: Create Manifest List and Push
working-directory: /tmp
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.metadata.outputs.version }}
release:
name: Publish Release
runs-on: ubuntu-latest
needs: upload
steps:
# https://github.com/marketplace/actions/semver-conventional-commits
- name: Get Versions
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: main
- name: Create Release Name
id: release-name
run: |
RELEASE_NAME=$(echo ${{ steps.semver.outputs.nextStrict }} Release)
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_OUTPUT
# https://github.com/marketplace/actions/universal-changelog-generator
- name: Generate a Changelog
id: changelog
uses: mrchief/[email protected]
with:
previousReleaseTagNameOrSha: ${{ steps.semver.outputs.current }}
nextReleaseTagName: 'main'
nextReleaseName: ${{ steps.release-name.outputs.RELEASE_NAME }}
# https://github.com/marketplace/actions/create-release
- name: Create Release
uses: ncipollo/[email protected]
with:
name: ${{ steps.release-name.outputs.RELEASE_NAME }}
tag: ${{ steps.semver.outputs.next }}
commit: ${{ github.sha }}
body: ${{ steps.changelog.outputs.changelog }}