Skip to content

Commit

Permalink
Add CI action to publish custom-branch hydra-node docker images (#1756)
Browse files Browse the repository at this point in the history
Introduce new docker ci to publish custom hydra-node docker images by
branch name.
> date time will be used so multiple images can be built and publish per
branch.

<!-- Describe your change here -->

---

<!-- Consider each and tick it off one way or the other -->
* [X] CHANGELOG updated or not needed
* [X] Documentation updated or not needed
* [X] Haddocks updated or not needed
* [X] No new TODOs introduced or explained herafter
  • Loading branch information
ffakenz authored Dec 3, 2024
2 parents 3748690 + 491260e commit dd67f3d
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ on:
push:
branches: [ "master" ]
tags: [ "*.*.*" ]
workflow_dispatch:
inputs:
ref_name:
type: string
description: 'Point-in-time to build the custom docker images'
required: true
default: "master"

permissions:
packages: write
Expand All @@ -27,6 +34,8 @@ jobs:
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref_name || '' }}

- name: 🐳 Login to GitHub Container Registry
uses: docker/login-action@v3
Expand Down Expand Up @@ -54,25 +63,41 @@ jobs:
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
nix build .#docker-${{ matrix.target }}
./result | docker load
IMAGE_LABEL=unstable
BUILDING_WORKFLOW_DISPATCH=${{github.event_name == 'workflow_dispatch'}}
[[ ${BUILDING_WORKFLOW_DISPATCH} = true ]] && \
IMAGE_LABEL=workflow_dispatch-${{github.event.inputs.ref_name}}
IS_TAG=${{github.ref_type == 'tag'}}
# Only build say we are building a tag if it's a tag _and_ not part of a
# workflow-dispatch task
[[ ${IS_TAG} = true && ${BUILDING_WORKFLOW_DISPATCH} = false ]] && \
BUILDING_TAG=true ||
BUILDING_TAG=false
# Determine whether we are building a tag and if yes, set a VERSION_NAME
BUILDING_TAG=${{github.ref_type == 'tag'}}
[[ ${BUILDING_TAG} = true ]] && \
VERSION_NAME=${{github.ref_name}}
# Use 'FROM' instruction to use docker build with --label
echo "FROM ${{matrix.target}}" | docker build \
--label org.opencontainers.image.source=https://github.com/cardano-scaling/hydra \
--label org.opencontainers.image.licenses=Apache-2.0 \
--label org.opencontainers.image.created=$(date -Is) \
--label org.opencontainers.image.revision=${{github.sha}} \
--label org.opencontainers.image.version=${VERSION_NAME:-unstable} \
--tag ${IMAGE_NAME}:unstable -
--label org.opencontainers.image.version=${VERSION_NAME:-${IMAGE_LABEL}} \
--tag ${IMAGE_NAME}:${IMAGE_LABEL} -
# Also tag with semver and 'latest' if we are building a tag
[[ ${BUILDING_TAG} = true && ${{matrix.target}} != "hydraw" ]] && \
docker tag ${IMAGE_NAME}:unstable ${IMAGE_NAME}:${{github.ref_name}}
docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:${{github.ref_name}}
[[ ${BUILDING_TAG} = true ]] && \
docker tag ${IMAGE_NAME}:unstable ${IMAGE_NAME}:latest
docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:latest
docker images
docker inspect ${IMAGE_NAME}:unstable
docker inspect ${IMAGE_NAME}:${IMAGE_LABEL}
- name: 📤 Push to registry
run: |
Expand Down

0 comments on commit dd67f3d

Please sign in to comment.