Build and publish golang image #1325
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: Build and publish golang image | |
on: | |
workflow_dispatch: | |
inputs: | |
force: | |
description: 'Force a build and push' | |
required: false | |
type: boolean | |
default: false | |
# Run every day at 5AM UTC | |
schedule: | |
- cron: '0 5 * * *' | |
env: | |
QUAY_ORG: projectquay | |
QUAY_REPO: golang | |
QUAY_USER: projectquay+claircore_github | |
jobs: | |
versions: | |
if: ${{ github.repository == 'quay/claircore' }} | |
name: Check available go versions | |
runs-on: 'ubuntu-latest' | |
outputs: | |
versions: ${{ steps.versions.outputs.versions }} | |
steps: | |
- id: versions | |
run: | | |
curl -sL 'https://golang.org/dl/?mode=json' | | |
jq -rc 'map(.version|sub("go(?<maj>1\\.[0-9]+)\\.[0-9]+$";"\(.maj)"))|@text "versions=\(.)"' >> $GITHUB_OUTPUT | |
golang-image: | |
if: ${{ github.repository == 'quay/claircore' }} | |
needs: versions | |
name: Build and publish golang image | |
runs-on: 'ubuntu-latest' | |
strategy: | |
fail-fast: false | |
matrix: | |
go: ${{ fromJSON(needs.versions.outputs.versions) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check verisons and dates | |
run: | | |
v=$(.github/scripts/get-latest-golang-minor-version.sh ${{ matrix.go }}) | |
t=$(curl -sSLf "https://quay.io/api/v1/repository/${QUAY_ORG}/${QUAY_REPO}/tag/?specificTag=${{ matrix.go }}&onlyActiveTags=true" | | |
jq -r '.tags[0].last_modified//"Thu, 01 Jan 1970 00:00:00 -0000"') | |
g=$(curl -sSLfI --http2 "https://dl.google.com/go/go${v}.linux-amd64.tar.gz" | | |
awk 'BEGIN {FS=": "}/^last-modified/{print $2}') | |
cat <<. | |
::notice title=Latest Go version::$v | |
::notice title=Latest tag update::$t | |
::notice title=Go version update::$g | |
. | |
cat <<. >>"$GITHUB_ENV" | |
GO_VERSION=$v | |
TAG_LAST_MODIFIED=$t | |
GO_LAST_MODIFIED=$g | |
. | |
- name: Decide whether we need to build new golang image | |
run: | | |
TAG=$(date -d "${TAG_LAST_MODIFIED}" +%s) | |
GO=$(date -d "${GO_LAST_MODIFIED}" +%s) | |
if test "${{ inputs.force }}" = 'true' -o "$GO" -gt "$TAG"; then | |
echo "BUILD_IMAGE=1" >> "$GITHUB_ENV" | |
fi | |
- name: Set up QEMU | |
if: env.BUILD_IMAGE == 1 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y qemu-user-static | |
- name: Build | |
uses: redhat-actions/buildah-build@v2 | |
if: env.BUILD_IMAGE == 1 | |
with: | |
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x | |
build-args: | | |
GO_VERSION=${{ env.GO_VERSION }} | |
containerfiles: etc/Dockerfile | |
context: etc | |
tags: | | |
quay.io/${{ env.QUAY_ORG }}/${{ env.QUAY_REPO }}:${{ matrix.go }} | |
- uses: redhat-actions/podman-login@v1 | |
if: env.BUILD_IMAGE == 1 | |
with: | |
registry: quay.io | |
username: ${{ env.QUAY_USER }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
- name: Publish | |
uses: redhat-actions/push-to-registry@v2 | |
if: env.BUILD_IMAGE == 1 | |
with: | |
#extra-args: | | |
# --compression-format=zstd:chunked | |
tags: | | |
quay.io/${{ env.QUAY_ORG }}/${{ env.QUAY_REPO }}:${{ matrix.go }} |