Prepare universal workflow

This commit is contained in:
Alexey Pustovalov 2024-02-12 00:19:46 +09:00
parent 87b28015ec
commit 28a7dc1cde
2 changed files with 24 additions and 7 deletions

View File

@ -16,7 +16,7 @@ on:
- '!Dockerfiles/*/windows/*' - '!Dockerfiles/*/windows/*'
- '.github/workflows/images_build.yml' - '.github/workflows/images_build.yml'
schedule: schedule:
- cron: '10 14 * * *' - cron: '50 02 * * *'
workflow_dispatch: workflow_dispatch:
defaults: defaults:
@ -544,8 +544,8 @@ jobs:
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
cache-from: | cache-from: |
type=gha,scope=${{ fromJSON(steps.meta.outputs.json).tags[0] }} type=gha,scope=${{ steps.base_build.outputs.base_build_image }}
type=registry,ref=docker.io/${{ fromJSON(steps.meta.outputs.json).tags[0] }} type=registry,ref=${{ steps.base_build.outputs.base_build_image }}
cache-to: type=gha,mode=max,scope=${{ fromJSON(steps.meta.outputs.json).tags[0] }} cache-to: type=gha,mode=max,scope=${{ fromJSON(steps.meta.outputs.json).tags[0] }}
- name: Sign the images with GitHub OIDC Token - name: Sign the images with GitHub OIDC Token
@ -858,6 +858,22 @@ jobs:
"$BASE_IMAGE" "$BASE_IMAGE"
echo "::endgroup::" echo "::endgroup::"
- name: Prepare cache data
id: cache_data
env:
BASE_IMAGE_TAG: ${{ steps.base_build.outputs.base_build_image }}
run: |
cache_images=""
if [[ ! -z "$BASE_IMAGE_TAG" ]]; then
cache_images="type=gha,scope=$BASE_IMAGE_TAG"$'\n'"type=registry,ref=$BASE_IMAGE_TAG"
fi
echo "::group::Base images cache"
echo "$cache_images"
echo "::endgroup::"
echo "cache_from=$cache_images" >> $GITHUB_OUTPUT
- name: Build and push image - name: Build and push image
id: docker_build id: docker_build
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
@ -871,8 +887,7 @@ jobs:
labels: | labels: |
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
cache-from: type=gha,scope=${{ fromJSON(steps.meta.outputs.json).tags[0] }} cache-from: ${{ steps.cache_data.outputs.cache_from }}
cache-to: type=gha,mode=max,scope=${{ fromJSON(steps.meta.outputs.json).tags[0] }}
- name: Sign the images with GitHub OIDC Token - name: Sign the images with GitHub OIDC Token
env: env:

View File

@ -11,9 +11,10 @@ defaults:
shell: bash shell: bash
env: env:
AUTO_PUSH_IMAGES: ${{ vars.AUTO_PUSH_IMAGES }} AUTO_PUSH_IMAGES: ${{ contains(fromJSON('["workflow_dispatch"]'), github.event_name) && 'false' || vars.AUTO_PUSH_IMAGES }}
LATEST_BRANCH: ${{ github.event.repository.default_branch }} LATEST_BRANCH: ${{ github.event.repository.default_branch }}
TRUNK_GIT_BRANCH: "refs/heads/trunk"
IMAGES_PREFIX: "zabbix-" IMAGES_PREFIX: "zabbix-"
BASE_BUILD_NAME: "build-base" BASE_BUILD_NAME: "build-base"
@ -58,7 +59,7 @@ jobs:
shell: bash shell: bash
env: env:
LATEST_BRANCH: ${{ env.LATEST_BRANCH }} LATEST_BRANCH: ${{ env.LATEST_BRANCH }}
github_ref: ${{ env.TRUNK_ONLY_EVENT == 'true' && env.TRUNK_GIT_BRANCH || github.ref }} github_ref: ${{ github.ref }}
run: | run: |
result=false result=false
sha_short=$(git rev-parse --short HEAD) sha_short=$(git rev-parse --short HEAD)
@ -334,6 +335,7 @@ jobs:
- name: Log in to Quay.io - name: Log in to Quay.io
uses: redhat-actions/podman-login@v1.6 uses: redhat-actions/podman-login@v1.6
if: ${{ env.AUTO_PUSH_IMAGES == 'true' }}
env: env:
LOGIN: ${{ steps.login_credentials.outputs.username }} LOGIN: ${{ steps.login_credentials.outputs.username }}
PASSWORD: ${{ steps.login_credentials.outputs.password }} PASSWORD: ${{ steps.login_credentials.outputs.password }}