Skip to content

Commit

Permalink
Tag last version as latest when merging to main.
Browse files Browse the repository at this point in the history
Set numerous tags as latest when PR is merged to main, but don't tag when built on branches.
  • Loading branch information
tjsr authored Jul 12, 2024
1 parent 4584d07 commit 04ca3cf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
85 changes: 58 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Release
run-name: ${{ github.actor }} Building and pushing node_patched_npm
on: [push]

env:
NODE_VERSION: '20.15.1'
ALPINE_VERSION: '3.20'
NPM_VERSION: '10.8.2'
LATEST_IMAGE_TAG: '20.15.1-alpine3.20-npm10.8.2'
jobs:
node_matrix:
strategy:
Expand All @@ -19,67 +23,94 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx
restore-keys: |
${{ runner.os }}-single-buildx
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker images for all variants and architectures.
- name: Build and push all docker images.
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
cache-to: type=gha,mode=max
cache-from: type=gha
build-args: |
NODE_VERSION=${{ matrix.node_version }}
ALPINE_VERSION=${{ matrix.alpine_version }}
NPM_VERSION=${{ matrix.npm_version }}
tags: ghcr.io/tjsr/node_patched_npm:${{ matrix.node_version }}-alpine${{ matrix.alpine_version }}-npm${{ matrix.npm_version }}
outputs: |
type=oci,dest=/tmp/${{ matrix.node_version }}-alpine${{ matrix.alpine_version }}-npm${{ matrix.npm_version }}.tar
type=registry,ref=ghcr.io/tjsr/node_patched_npm:${{ matrix.node_version }}-alpine${{ matrix.alpine_version }}-npm${{ matrix.npm_version }}
- name: Upload OCI multi-platform image
if: ${{ matrix.node_version }} == ${{ env.NODE_VERSION }} && ${{ matrix.alpine_version }} == ${{ env.ALPINE_VERSION }} && ${{ matrix.npm_version }} == ${{ env.NPM_VERSION }}
uses: actions/upload-artifact@v4
with:
name: node_patched_npm_${{ matrix.node_version }}-alpine${{ matrix.alpine_version }}-npm${{ matrix.npm_version }}
path: /tmp/${{ matrix.node_version }}-alpine${{ matrix.alpine_version }}-npm${{ matrix.npm_version }}.tar

latest:
runs-on: ubuntu-latest
needs: node_matrix
steps:
- uses: actions/checkout@v4
- name: Get branch names.
id: branch-names
uses: tj-actions/branch-names@v8

- name: Running on any event.
run: |
echo "Default branch: ${{ steps.branch-names.outputs.default_branch }}"
# Outputs: "Default branch: main"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx
restore-keys: |
${{ runner.os }}-single-buildx
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Download OCI multi-platform artifact
uses: actions/download-artifact@v4
with:
name: node_patched_npm_${{ env.LATEST_IMAGE_TAG }}
path: /tmp/node_patched_npm

- name: Pull, tag and push the latest image
- name: Load tagged OCI multi-platform image.
id: load-oci
run: |
docker import /tmp/node_patched_npm/${{ env.LATEST_IMAGE_TAG }}.tar ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }}
- name: Tag the latest image with all the variants we want
if: github.ref == 'refs/heads/main'
env:
NODE_VERSION: '20.15.1'
ALPINE_VERSION: '3.20'
NPM_VERSION: '10.8.2'
run: |
docker pull ghcr.io/tjsr/node_patched_npm:${NODE_VERSION}-alpine${ALPINE_VERSION}-npm${NPM_VERSION} || true
docker tag ghcr.io/tjsr/node_patched_npm:${NODE_VERSION}-alpine${ALPINE_VERSION}-npm${NPM_VERSION} ghcr.io/tjsr/node_patched_npm:latest
docker push ghcr.io/tjsr/node_patched_npm:latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest-alpine${{ env.ALPINE_VERSION }}-npm${{ env.NPM_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest-alpine-latest-npm${{ env.NPM_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest-npm${{ env.NPM_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest-alpine-${{ env.ALPINE_VERSION }}-npm-latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:latest-alpine-${{ env.ALPINE_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-alpine-latest-npm${{ env.NPM_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-npm${{ env.NPM_VERSION }}-latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-npm${{ env.NPM_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-alpine${{ env.ALPINE_VERSION }}-npm-latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-alpine${{ env.ALPINE_VERSION }}
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-alpine-latest-npm-latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}-latest
docker tag ghcr.io/tjsr/node_patched_npm:${{ env.LATEST_IMAGE_TAG }} ghcr.io/tjsr/node_patched_npm:${{ env.NODE_VERSION }}
- name: Push tagged images
run:
docker push --all-tags ghcr.io/tjsr/node_patched_npm

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ARG NODE_VERSION=20.15.1
ARG ALPINE_VERSION=3.20
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} as node_patched_npm
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_patched_npm
ARG NPM_VERSION=10.8.2
LABEL org.opencontainers.image.authors="Tim Rowe <[email protected]>"
LABEL description="Node.js with most up-to-date npm versions globally installed."
LABEL version="node${NODE_VERSION}-alpine${ALPINE_VERSION}-npm$NPM_VERSION"
LABEL version="node$NODE_VERSION-alpine$ALPINE_VERSION-npm$NPM_VERSION"
RUN --mount=type=cache,target=/root/.npm npm config set fund false --location=global && \
npm config set update-notifier false --location=global && \
npm install -g npm@${NPM_VERSION}

0 comments on commit 04ca3cf

Please sign in to comment.