Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cd): use correct sha for PR based docker build #12115

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
deploy-environment: ${{ steps.build-info.outputs.deploy-environment }}
matrix: ${{ steps.build-info.outputs.matrix }}
arch: ${{ steps.build-info.outputs.arch }}
# use github.event.pull_request.head.sha instead of github.sha on a PR, as github.sha on PR is the merged commit (temporary commit)
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -342,11 +344,13 @@ jobs:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_PR_HEAD_SHA: true
with:
images: ${{ needs.metadata.outputs.prerelease-docker-repository }}
tags: |
type=raw,${{ github.sha }}-${{ matrix.label }}
type=raw,enable=${{ matrix.label == 'ubuntu' }},${{ github.sha }}
type=raw,${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}
type=raw,enable=${{ matrix.label == 'ubuntu' }},${{ needs.metadata.outputs.commit-sha }}

- name: Set up QEMU
if: matrix.docker-platforms != ''
Expand Down Expand Up @@ -390,6 +394,7 @@ jobs:
build-args: |
KONG_BASE_IMAGE=${{ matrix.base-image }}
KONG_ARTIFACT_PATH=bazel-bin/pkg/
KONG_VERSION=${{ needs.metadata.outputs.kong-version }}
RPM_PLATFORM=${{ steps.docker_rpm_platform_arg.outputs.rpm_platform }}
EE_PORTS=8002 8445 8003 8446 8004 8447

Expand All @@ -400,7 +405,7 @@ jobs:
token: ${{ secrets.GHA_COMMENT_TOKEN }}
body: |
### Bazel Build
Docker image available `${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ github.sha }}`
Docker image available `${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ needs.metadata.outputs.commit-sha }}`
Artifacts available https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

verify-manifest-images:
Expand Down Expand Up @@ -429,7 +434,7 @@ jobs:
# docker image verify requires sudo to set correct permissions, so we
# also install deps for root
sudo -E pip install -r requirements.txt
IMAGE=${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ github.sha }}-${{ matrix.label }}
IMAGE=${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}

sudo -E python ./main.py --image $IMAGE -f docker_image_filelist.txt -s docker-image

Expand All @@ -451,7 +456,7 @@ jobs:
matrix:
include: "${{ fromJSON(needs.metadata.outputs.matrix)['scan-vulnerabilities'] }}"
env:
IMAGE: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ github.sha }}-${{ matrix.label }}
IMAGE: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}
steps:
- name: Install regctl
uses: regclient/actions/regctl-installer@main
Expand Down Expand Up @@ -490,16 +495,16 @@ jobs:
if: steps.image_manifest_metadata.outputs.amd64_sha != ''
uses: Kong/public-shared-actions/security-actions/scan-docker-image@v1
with:
asset_prefix: kong-${{ github.sha }}-${{ matrix.label }}-linux-amd64
image: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ github.sha }}-${{ matrix.label }}
asset_prefix: kong-${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}-linux-amd64
image: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}

- name: Scan ARM64 Image digest
if: steps.image_manifest_metadata.outputs.manifest_list_exists == 'true' && steps.image_manifest_metadata.outputs.arm64_sha != ''
id: sbom_action_arm64
uses: Kong/public-shared-actions/security-actions/scan-docker-image@v1
with:
asset_prefix: kong-${{ github.sha }}-${{ matrix.label }}-linux-arm64
image: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ github.sha }}-${{ matrix.label }}
asset_prefix: kong-${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}-linux-arm64
image: ${{ needs.metadata.outputs.prerelease-docker-repository }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}

smoke-tests:
name: Smoke Tests - ${{ matrix.label }}
Expand Down Expand Up @@ -552,7 +557,7 @@ jobs:
--restart always \
--network=host -d \
--pull always \
${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ github.sha }}-${{ matrix.label }} \
${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }} \
sh -c "kong migrations bootstrap && kong start"
sleep 3
docker logs kong
Expand Down Expand Up @@ -697,7 +702,7 @@ jobs:
env:
TAGS: "${{ steps.meta.outputs.tags }}"
run: |
PRERELEASE_IMAGE=${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ github.sha }}-${{ matrix.label }}
PRERELEASE_IMAGE=${{ env.PRERELEASE_DOCKER_REPOSITORY }}:${{ needs.metadata.outputs.commit-sha }}-${{ matrix.label }}
docker pull $PRERELEASE_IMAGE
for tag in $TAGS; do
regctl -v debug image copy $PRERELEASE_IMAGE $tag
Expand Down
Loading