Update Docker Image for GitHub Action #191
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: "Update Docker Image for GitHub Action" | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- "docker/**" | |
- ".github/workflows/docker.yml" | |
schedule: | |
# Once monthly at a randomly selected time. | |
- cron: "24 2 3,18 * *" | |
jobs: | |
build: | |
name: "Update Docker Image" | |
runs-on: ubuntu-latest | |
services: | |
registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v3 | |
- name: "Configure" | |
id: config | |
run: | | |
ref="${{ github.ref }}" | |
if [ "$ref" = "refs/heads/main" ]; then | |
label=latest | |
elif [ "${ref#refs/tags/}" != "$ref" ]; then | |
label="${ref#refs/tags/}" | |
else | |
label=test | |
fi | |
tag() { | |
echo "${1}/martinthomson/i-d-template${2}:${label}" | |
} | |
if [ "$label" = "test" ]; then | |
registry=localhost:5000 | |
driver_opts="network=host" | |
else | |
registry=ghcr.io | |
driver_opts= | |
fi | |
action_tags="$(tag "$registry" -action)" | |
circle_tags="$(tag "$registry" "")" | |
math_tags="$(tag "$registry" -math)" | |
echo "registry=$registry" >>"$GITHUB_OUTPUT" | |
echo "driver_opts=$driver_opts" >>"$GITHUB_OUTPUT" | |
echo "label=$label" >>"$GITHUB_OUTPUT" | |
echo "action_tags=$action_tags" >>"$GITHUB_OUTPUT" | |
echo "circle_tags=$circle_tags" >>"$GITHUB_OUTPUT" | |
echo "math_tags=$math_tags" >>"$GITHUB_OUTPUT" | |
- name: "Setup Docker Buildx" | |
uses: docker/setup-buildx-action@v2 | |
with: | |
driver-opts: ${{ steps.config.outputs.driver_opts }} | |
- name: "Login to GitHub Container Registry" | |
if: ${{ steps.config.outputs.label != 'test' }} | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GHCR_USERNAME }} | |
password: ${{ secrets.GHCR_PASSWORD }} | |
- name: "Build and Publish GitHub Actions Image" | |
uses: docker/build-push-action@v3 | |
with: | |
context: ./docker/action | |
file: ./docker/action/Dockerfile | |
push: true | |
tags: ${{ steps.config.outputs.action_tags }} | |
- name: "Build and Publish CircleCI Image" | |
uses: docker/build-push-action@v3 | |
with: | |
context: ./docker/circleci | |
file: ./docker/circleci/Dockerfile | |
build-args: | | |
REGISTRY=${{ steps.config.outputs.registry }} | |
VERSION=${{ steps.config.outputs.label }} | |
push: true | |
tags: ${{ steps.config.outputs.circle_tags }} | |
- name: "Build and Publish Math Image" | |
uses: docker/build-push-action@v3 | |
with: | |
context: ./docker/math | |
file: ./docker/math/Dockerfile | |
build-args: | | |
REGISTRY=${{ steps.config.outputs.registry }} | |
VERSION=${{ steps.config.outputs.label }} | |
push: true | |
tags: ${{ steps.config.outputs.math_tags }} |