buildx #2484
This file contains hidden or 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.2, 3.3, 3.4, 3.5] | |
| node-version: [20, 22, 24] | |
| 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/checkout@v6.0.1 | |
| - name: Set Node.js codename | |
| id: nodename | |
| run: | | |
| case "${{ matrix.node-version }}" in | |
| "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/setup-qemu-action@v3.7.0 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3.11.1 | |
| 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: Set platforms | |
| id: platforms | |
| shell: bash | |
| run: | | |
| # For Node >=24, remove linux/arm/v7 from the variant's platform list | |
| BASE_PLATFORMS="${{ matrix.platforms }}" | |
| NODE_MAJOR="${{ matrix['node-version'] }}" | |
| if [ "$NODE_MAJOR" -ge 24 ]; then | |
| IFS=',' read -ra arr <<< "$BASE_PLATFORMS" | |
| out=() | |
| for p in "${arr[@]}"; do | |
| if [ "$p" != "linux/arm/v7" ] && [ -n "$p" ]; then | |
| out+=("$p") | |
| fi | |
| done | |
| (IFS=','; echo "platforms=${out[*]}") >> "$GITHUB_OUTPUT" | |
| else | |
| echo "platforms=$BASE_PLATFORMS" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Docker Buildx (build) | |
| uses: docker/build-push-action@v6.18.0 | |
| 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: ${{ steps.platforms.outputs.platforms }} | |
| tags: ${{ steps.prepare.outputs.tags }} | |
| - name: Docker Login | |
| if: success() && github.event_name != 'pull_request' && contains(github.ref, 'master') | |
| uses: docker/login-action@v3.6.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Docker Buildx (push) | |
| uses: docker/build-push-action@v6.18.0 | |
| 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: ${{ steps.platforms.outputs.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 |