buildx #2119
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: buildx | |
on: | |
schedule: | |
- cron: "37 05 * * *" | |
push: | |
branches: | |
- master | |
pull_request: | |
jobs: | |
buildx: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
ruby-version: [3.1, 3.2, 3.3, 3.4] | |
node-version: [18, 20, 22] | |
variant: [default, slim, alpine] | |
include: | |
- variant: default | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
- variant: slim | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
- variant: alpine | |
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 | |
steps: | |
- uses: actions/[email protected] | |
- name: Set Node.js codename | |
id: nodename | |
run: | | |
case "${{ matrix.node-version }}" in | |
"18") echo "codename=hydrogen" >> $GITHUB_OUTPUT ;; | |
"20") echo "codename=iron" >> $GITHUB_OUTPUT ;; | |
"22") echo "codename=jod" >> $GITHUB_OUTPUT ;; | |
"24") echo "codename=krypton" >> $GITHUB_OUTPUT ;; | |
"26") echo "codename=lithium" >> $GITHUB_OUTPUT ;; | |
"28") echo "codename=magnesium" >> $GITHUB_OUTPUT ;; | |
esac | |
- name: Generate tags | |
id: prepare | |
run: | | |
DOCKER_IMAGE=timbru31/ruby-node | |
VERSION="${{ matrix.ruby-version }}" | |
NODE_CODENAME=${{ steps.nodename.outputs.codename }} | |
if [ "${{ matrix.variant }}" = "default" ]; then | |
VARIANT="" | |
else | |
VARIANT="-${{ matrix.variant }}" | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}${VARIANT}-${{ matrix.node-version }}" | |
TAGS="${TAGS},${DOCKER_IMAGE}:${VERSION}${VARIANT}-${NODE_CODENAME}" | |
if [ "${{ matrix.ruby-version }}" = "3.4" ] && [ "${{ matrix.node-version }}" = "22" ]; then | |
if [ "${{ matrix.variant }}" = "default" ]; then | |
TAGS="${TAGS},${DOCKER_IMAGE}:3,${DOCKER_IMAGE}:latest" | |
elif [ "${{ matrix.variant }}" = "slim" ]; then | |
TAGS="${TAGS},${DOCKER_IMAGE}:3-slim,${DOCKER_IMAGE}:slim" | |
elif [ "${{ matrix.variant }}" = "alpine" ]; then | |
TAGS="${TAGS},${DOCKER_IMAGE}:3-alpine,${DOCKER_IMAGE}:alpine" | |
fi | |
fi | |
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT | |
echo "version=${VERSION}${VARIANT}-${{ matrix.node-version }}" >> $GITHUB_OUTPUT | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/[email protected] | |
with: | |
install: true | |
- name: Set build path | |
id: buildpath | |
run: | | |
if [ "${{ matrix.variant }}" = "default" ]; then | |
echo "path=./${{ matrix.ruby-version }}/${{ matrix.node-version }}" >> $GITHUB_OUTPUT | |
else | |
echo "path=./${{ matrix.ruby-version }}/${{ matrix.node-version }}/${{ matrix.variant }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Docker Buildx (build) | |
uses: docker/[email protected] | |
if: success() && !contains(github.ref, 'master') | |
with: | |
push: false | |
context: ${{ steps.buildpath.outputs.path }} | |
file: ${{ steps.buildpath.outputs.path }}/Dockerfile | |
build-args: REFRESHED_AT=$(date +%Y-%m-%d) | |
platforms: ${{ matrix.platforms }} | |
tags: ${{ steps.prepare.outputs.tags }} | |
- name: Docker Login | |
if: success() && github.event_name != 'pull_request' && contains(github.ref, 'master') | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker Buildx (push) | |
uses: docker/[email protected] | |
if: success() && github.event_name != 'pull_request' && contains(github.ref, 'master') | |
with: | |
push: true | |
context: ${{ steps.buildpath.outputs.path }} | |
file: ${{ steps.buildpath.outputs.path }}/Dockerfile | |
build-args: REFRESHED_AT=$(date +%Y-%m-%d) | |
platforms: ${{ matrix.platforms }} | |
tags: ${{ steps.prepare.outputs.tags }} | |
- name: Inspect Image | |
if: always() && github.event_name != 'pull_request' && contains(github.ref, 'master') | |
run: | | |
docker buildx imagetools inspect $(echo "${{ steps.prepare.outputs.tags }}" | cut -d',' -f1) | |
- name: Clear | |
if: always() && github.event_name != 'pull_request' | |
run: | | |
rm -f ${HOME}/.docker/config.json |