Skip to content

Commit

Permalink
use registry cache for docker builds and refresh non registry caches
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesw committed Nov 21, 2024
1 parent a07c3bf commit 9b1d0f6
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 0 deletions.
153 changes: 153 additions & 0 deletions .github/workflows/bld_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: bld_docker

permissions:
checks: write
contents: read
issues: read
pull-requests: write

on:
workflow_call:
inputs:
docker_name:
description: 'Name of the docker image to build'
required: false
default: "orcid/version-bumping-test"
type: string
context:
description: 'Name of the context in the repo'
required: false
default: "."
type: string
build_args:
description: 'build_args e.g wibble=blar'
required: false
default: ""
type: string
file:
description: 'specify a custom dockerfile'
required: false
default: ""
type: string
version_tag:
description: 'Name of the tag to build'
required: false
default: 'latest'
type: string
bump:
description: 'whether to bump the version number by a major minor patch amount or none'
required: false
default: 'patch'
type: string
ref:
description: 'git reference to use with the checkout use default_branch to have that calculated'
required: false
default: "default"
type: string

workflow_dispatch:
inputs:
docker_name:
description: 'Name of the docker image to build'
required: false
default: "orcid/version-bumping-test"
type: string
context:
description: 'Name of the context in the repo'
required: false
default: "."
type: string
build_args:
description: 'build_args e.g wibble=blar'
required: false
default: ""
type: string
file:
description: 'specify a custom dockerfile'
required: false
default: ""
type: string
version_tag:
description: 'Name of the tag to build'
required: false
default: 'latest'
type: string
bump:
description: 'whether to bump the version number by a major minor patch amount or none'
required: false
default: 'patch'
type: string
ref:
description: 'git reference to use with the checkout use default_branch to have that calculated'
required: false
default: "default"
type: string


jobs:
bld_docker:
strategy:
matrix:
include:
- artifact_name: hello-world
docker_name: orcid/test/hello-world
context: .
file: hello-world/Dockerfile

- artifact_name: hello-world-alt
docker_name: orcid/test/hello-world-alt
context: .
file: hello-world-alt/Dockerfile

runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: git-checkout-ref-action
id: ref
uses: ORCID/git-checkout-ref-action@main
with:
default_branch: ${{ github.event.repository.default_branch }}
ref: ${{ inputs.ref }}

- uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.ref }}
# checkout some history so we can scan commits for bump messages
# NOTE: history does not include tags!
fetch-depth: 100

- name: find next version
id: version
uses: ORCID/version-bump-action@main
with:
version_tag: ${{ inputs.version_tag }}
bump: ${{ inputs.bump }}

- uses: docker/setup-buildx-action@v3

- name: Login to private registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REG_PRIVATE }}
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: nasty hack to allow dynamic defaults
id: dynamic_defaults
run: |
FILE="${{ matrix.file }}"
echo "default_file=${FILE:-${{ inputs.context }}/Dockerfile}" >> "$GITHUB_OUTPUT"
- name: show the dynamic defaults
run: |
echo ${{ steps.dynamic_defaults.outputs.default_file }}
- uses: docker/build-push-action@v6
with:
push: false
tags: ${{ secrets.DOCKER_REG_PRIVATE }}/${{ matrix.docker_name}}:${{ steps.version.outputs.version_tag_numeric }}
context: ${{ matrix.context }}
cache-from: type=registry,ref=${{ secrets.DOCKER_REG_PRIVATE }}/${{ matrix.docker_name }}:cache
cache-to: type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${{ secrets.DOCKER_REG_PRIVATE }}/${{ matrix.docker_name }}:cache
file: ${{ steps.dynamic_defaults.outputs.default_file }}

24 changes: 24 additions & 0 deletions .github/workflows/weekly_cache_refresh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: weekly_cache_refresh

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *

on:
schedule:
- cron: '0 5 * * SUN'

workflow_dispatch:

jobs:
lint:
uses: ./.github/workflows/lint.yml

test_mvn:
uses: ./.github/workflows/test_mvn.yml

0 comments on commit 9b1d0f6

Please sign in to comment.