Skip to content

Commit

Permalink
Use caching and retagging for keycloakify action (#1174)
Browse files Browse the repository at this point in the history
* Use caching and retagging for keycloakify action

* Fix: need to login befor querying docker registry
  • Loading branch information
corneliusroemer committed Feb 28, 2024
1 parent 312404e commit aa0b53a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/keycloakify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ name: keycloakify-build

on:
push:
workflow_dispatch:

env:
DOCKER_IMAGE_NAME: ghcr.io/loculus-project/keycloakify

defaults:
run:
working-directory: ./keykloak/keycloakify

concurrency:
group: ci-${{ github.ref }}-keycloak
cancel-in-progress: true
Expand All @@ -24,28 +21,47 @@ jobs:
checks: read
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
- name: Generate files hash
id: files-hash
run: |
DIR_HASH=$(echo -n ${{ hashFiles('./keycloak/keycloakify/**','.github/workflows/keycloakify-build.yml') }})
echo "DIR_HASH=$DIR_HASH" >> $GITHUB_ENV
- name: Setup Docker metadata
id: dockerMetadata
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=raw,value=${{ env.DIR_HASH }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch
type=sha,prefix=commit-
- name: Check if image exists
id: check-image
run: |
EXISTS=$(docker manifest inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DIR_HASH }} > /dev/null 2>&1 && echo "true" || echo "false")
echo "CACHE_HIT=$EXISTS" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image
if: env.CACHE_HIT == 'false'
uses: docker/build-push-action@v5
with:
context: ./keycloak/keycloakify
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=keycloakify=${{ github.ref }}
cache-to: type=gha,mode=max,scope=keycloakify=${{ github.ref }}
- name: Tag and push image if cache hit
if: env.CACHE_HIT == 'true'
run: |
TAGS=(${{ steps.dockerMetadata.outputs.tags }})
for TAG in "${TAGS[@]}"; do
docker buildx imagetools create --tag $TAG ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DIR_HASH }}
done

0 comments on commit aa0b53a

Please sign in to comment.