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

refactor: use only goreleaser to build unsigned chainlink images in one workflow #14034

Merged
merged 59 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b7c8fc3
refactor: use only goreleaser to build unsigned chainlink images in o…
momentmaker Aug 5, 2024
e079212
fix: use branches-ignore filter instead
momentmaker Aug 5, 2024
1c3244b
rename and switch runner
momentmaker Aug 5, 2024
3e2eee5
temp switch back name because of env protection rule
momentmaker Aug 5, 2024
61a1c66
back to use the refactored name
momentmaker Aug 5, 2024
6309fcf
update goreleaser yaml
momentmaker Aug 5, 2024
7d6edc7
add new docker inputs, rename IMAGE_NAME, add goreleaser build-sign-p…
momentmaker Aug 6, 2024
d33bcdd
add output image name and digest to github summary
momentmaker Aug 6, 2024
5b01357
refactor gha workflow names and add output image name and digest to b…
momentmaker Aug 6, 2024
c5390a5
remove unnecessary outputs
momentmaker Aug 6, 2024
1e3222f
add a git_ref validation job
momentmaker Aug 6, 2024
c607492
temp delete workflows for easier testing
momentmaker Aug 6, 2024
800b5bf
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 6, 2024
253e74d
add if conditional to validate step
momentmaker Aug 6, 2024
a903b20
fix metric name and add debug log
momentmaker Aug 7, 2024
2073502
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 7, 2024
793b3a7
update docker registry
momentmaker Aug 7, 2024
3c874d3
no goreleaser output since we don't use the goreleaser/action
momentmaker Aug 7, 2024
e70dbe1
remove debug log and use bash shell
momentmaker Aug 7, 2024
c9aa538
fix formatting
momentmaker Aug 7, 2024
30c0ec7
remove root images from goreleaser yaml
momentmaker Aug 7, 2024
3c83784
use custom setup-go
momentmaker Aug 7, 2024
be22f6d
fix typo
momentmaker Aug 7, 2024
3b0aa83
use tee instead
momentmaker Aug 7, 2024
6d91f10
add back setup-go and refactor output summary step
momentmaker Aug 7, 2024
8765e27
update with new filename and workflow trigger
momentmaker Aug 8, 2024
4d17c65
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 8, 2024
cf60d4c
fix docker registry input
momentmaker Aug 8, 2024
4aca4de
remove role-duration input
momentmaker Aug 8, 2024
cc65cf1
change conditional
momentmaker Aug 8, 2024
8e22ef7
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 8, 2024
4757406
revert temp gha workflow delete commit
momentmaker Aug 8, 2024
0b2f3e0
sync with origin develop
momentmaker Aug 8, 2024
6424fdc
refactor trigger based on push and pr label
momentmaker Aug 9, 2024
7b29382
fix install remote plugins bug include
momentmaker Aug 9, 2024
da70962
add new docker builds for plugins and update dockerfile
momentmaker Aug 12, 2024
11aa57b
add goreleaser --split to gha and refactor action_utils script
momentmaker Aug 12, 2024
583bf8d
fix add shell
momentmaker Aug 12, 2024
0d9fd36
fix metrics job name and publish docker manifest files
momentmaker Aug 12, 2024
d33f98d
fix image_templates goreleaser
momentmaker Aug 12, 2024
481ce97
fix check artifacts.json and metrics name
momentmaker Aug 12, 2024
c8e41ce
fix if not end
momentmaker Aug 12, 2024
6a2a19e
ls -al dist
momentmaker Aug 12, 2024
83c4b76
add --single-target flag and split checksum
momentmaker Aug 12, 2024
9274809
remove split in checksum
momentmaker Aug 12, 2024
2088c24
remove --single-target and update output artifact.json path
momentmaker Aug 12, 2024
42b57c7
cat artifacts.json
momentmaker Aug 12, 2024
f51f0d8
use ubuntu-latest runner
momentmaker Aug 13, 2024
b699543
update build-publish workflow output summary step
momentmaker Aug 13, 2024
96829b0
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 13, 2024
78a0fbc
build on every pr - conditional publish | add workflow_dispatch trigger
momentmaker Aug 13, 2024
3a93e0c
add workflow_dispatch conditional build-publish
momentmaker Aug 13, 2024
1084cb3
fix typo
momentmaker Aug 13, 2024
c5ec2d8
fix typo
momentmaker Aug 13, 2024
3fe4b7e
use ubuntu-20.04 runner
momentmaker Aug 13, 2024
09b3d37
fix conditional
momentmaker Aug 13, 2024
996a83f
add comment
momentmaker Aug 13, 2024
37d617b
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 13, 2024
60e55dd
Merge branch 'develop' into re-2756/goreleaser-build-image
momentmaker Aug 14, 2024
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
41 changes: 28 additions & 13 deletions .github/actions/goreleaser-build-sign-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ inputs:
description: The docker registry
default: localhost:5001
required: false
# snapshot inputs
enable-goreleaser-snapshot:
description: Enable goreleaser build / release snapshot
default: "false"
docker-image-name:
description: The docker image name
default: chainlink
required: false
docker-image-tag:
description: The docker image tag
default: develop
required: false
# goreleaser inputs
goreleaser-exec:
Expand All @@ -43,6 +46,17 @@ inputs:
description: "The goreleaser configuration yaml"
default: ".goreleaser.yaml"
required: false
enable-goreleaser-snapshot:
description: Enable goreleaser build / release snapshot
default: "false"
required: false
enable-goreleaser-split:
description: Enable goreleaser split and merge builds
default: "false"
required: false
goreleaser-split-arch:
description: The architecture to split the goreleaser build
required: false
# signing inputs
enable-cosign:
description: Enable signing of docker images
Expand All @@ -57,13 +71,6 @@ inputs:
cosign-password:
description: The password to decrypt the cosign private key needed to sign the image
required: false
outputs:
goreleaser-metadata:
description: "Build result metadata"
value: ${{ steps.goreleaser.outputs.metadata }}
goreleaser-artifacts:
description: "Build result artifacts"
value: ${{ steps.goreleaser.outputs.artifacts }}
runs:
using: composite
steps:
Expand Down Expand Up @@ -97,14 +104,22 @@ runs:
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ${{ inputs.docker-registry }}
- name: Goreleaser release
id: goreleaser
- name: Set goreleaser split env
if: inputs.enable-goreleaser-split == 'true'
shell: bash
run: |
echo "GOOS=linux" | tee -a $GITHUB_ENV
echo "GOARCH=${{ inputs.goreleaser-split-arch }}" | tee -a $GITHUB_ENV
- name: Run goreleaser release
shell: bash
env:
ENABLE_COSIGN: ${{ inputs.enable-cosign }}
ENABLE_GORELEASER_SNAPSHOT: ${{ inputs.enable-goreleaser-snapshot }}
ENABLE_GORELEASER_SPLIT: ${{ inputs.enable-goreleaser-split }}
ENABLE_DOCKER_PUBLISH: ${{ inputs.enable-docker-publish }}
IMAGE_PREFIX: ${{ inputs.docker-registry }}
IMAGE_NAME: ${{ inputs.docker-image-name }}
IMAGE_TAG: ${{ inputs.docker-image-tag }}
GORELEASER_EXEC: ${{ inputs.goreleaser-exec }}
GORELEASER_CONFIG: ${{ inputs.goreleaser-config }}
COSIGN_PASSWORD: ${{ inputs.cosign-password }}
Expand Down
32 changes: 25 additions & 7 deletions .github/actions/goreleaser-build-sign-publish/action_utils
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -euo pipefail

ENABLE_COSIGN=${ENABLE_COSIGN:-false}
ENABLE_GORELEASER_SNAPSHOT=${ENABLE_GORELEASER_SNAPSHOT:-false}
ENABLE_GORELEASER_SPLIT=${ENABLE_GORELEASER_SPLIT:-false}
ENABLE_DOCKER_PUBLISH=${ENABLE_DOCKER_PUBLISH:-false}
COSIGN_PASSWORD=${COSIGN_PASSWORD:-""}
GORELEASER_EXEC=${GORELEASER_EXEC:-goreleaser}
Expand All @@ -27,8 +28,12 @@ _publish_snapshot_manifests() {
local docker_manifest_extra_args=$DOCKER_MANIFEST_EXTRA_ARGS
local full_sha=$(git rev-parse HEAD)
local images=$(docker images --filter "label=org.opencontainers.image.revision=$full_sha" --format "{{.Repository}}:{{.Tag}}" | sort)
local arches=(amd64 arm64)
local raw_manifest_lists=""
if [[ $ENABLE_GORELEASER_SPLIT == "true" ]]; then
chainchad marked this conversation as resolved.
Show resolved Hide resolved
local arches=(${GOARCH:-""})
else
local arches=(amd64 arm64)
fi
for image in $images; do
for arch in "${arches[@]}"; do
image=${image%"-$arch"}
Expand All @@ -51,22 +56,35 @@ _publish_snapshot_manifests() {

# wrapper function to invoke goreleaser release
goreleaser_release() {
goreleaser_flags=()

# set goreleaser flags
if [[ $ENABLE_GORELEASER_SNAPSHOT == "true" ]]; then
goreleaser_flags+=("--snapshot")
goreleaser_flags+=("--clean")
fi
if [[ $ENABLE_GORELEASER_SPLIT == "true" ]]; then
goreleaser_flags+=("--split")
fi
flags=$(printf "%s " "${goreleaser_flags[@]}")
flags=$(echo "$flags" | sed 's/ *$//')

if [[ $ENABLE_COSIGN == "true" ]]; then
echo "$COSIGN_PUBLIC_KEY" > cosign.pub
echo "$COSIGN_PRIVATE_KEY" > cosign.key
fi

if [[ -n $MACOS_SDK_DIR ]]; then
MACOS_SDK_DIR=$(echo "$(cd "$(dirname "$MACOS_SDK_DIR")" || exit; pwd)/$(basename "$MACOS_SDK_DIR")")
fi
if [[ $ENABLE_GORELEASER_SNAPSHOT == "true" ]]; then
$GORELEASER_EXEC release --snapshot --clean --config "$GORELEASER_CONFIG" "$@"
if [[ $ENABLE_DOCKER_PUBLISH == "true" ]]; then

$GORELEASER_EXEC release ${flags} --config "$GORELEASER_CONFIG" "$@"

if [[ $ENABLE_DOCKER_PUBLISH == "true" ]]; then
_publish_snapshot_images
_publish_snapshot_manifests
fi
else
$GORELEASER_EXEC release --clean --config "$GORELEASER_CONFIG" "$@"
fi

if [[ $ENABLE_COSIGN == "true" ]]; then
rm -rf cosign.pub
rm -rf cosign.key
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/build-publish-develop-pr.yml
chainchad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: "Build and Publish Chainlink"

on:
pull_request:
types:
- labeled
push:
branches:
- develop
- "release/**"

jobs:
goreleaser-build-publish-chainlink:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
strategy:
matrix:
goarch: [amd64, arm64]
steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Get image tag
id: get-image-tag
run: |
short_sha=$(git rev-parse --short HEAD)
echo "build-publish=false" | tee -a $GITHUB_OUTPUT
if [[ ${{ github.event_name }} == 'push' ]]; then
if [[ ${{ github.ref_name }} == 'release/'* ]]; then
echo "image-tag=release-${short_sha}" | tee -a $GITHUB_OUTPUT
echo "build-publish=true" | tee -a $GITHUB_OUTPUT
else
echo "image-tag=develop-${short_sha}" | tee -a $GITHUB_OUTPUT
echo "build-publish=true" | tee -a $GITHUB_OUTPUT
fi
else
if [[ ${{ github.event.label.name }} == 'build-publish' ]]; then
echo "image-tag=pr-${{ github.event.number }}-${short_sha}" | tee -a $GITHUB_OUTPUT
echo "build-publish=true" | tee -a $GITHUB_OUTPUT
fi
fi

- name: Configure aws credentials
if: steps.get-image-tag.outputs.build-publish == 'true'
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ secrets.AWS_OIDC_IAM_ROLE_BUILD_PUBLISH_DEVELOP_PR }}
aws-region: ${{ secrets.AWS_REGION }}
mask-aws-account-id: true
role-session-name: goreleaser-build-publish-chainlink

- name: Build and publish images
if: steps.get-image-tag.outputs.build-publish == 'true'
uses: ./.github/actions/goreleaser-build-sign-publish
with:
enable-docker-publish: "true"
momentmaker marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

@chainchad chainchad Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want this to be false if it was from a PR unless that PR had a specific label?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are enabling to publish to the private sdlc ecr. it's a custom thing we created because the regular goreleaser release with snapshot does not do publish at all.

or did you mean we don't want to publish for any pr - just pr with the label build-publish?

if [[ $ENABLE_DOCKER_PUBLISH == "true" ]]; then
_publish_snapshot_images
_publish_snapshot_manifests
fi

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean we don't want to publish for any pr - just pr with the label build-publish

This. Just to minimize the number of images we publish that won't ever get used. But I'm assuming we would use this workflow to build and then optionally publish. Is there still a separate workflow that builds?

Copy link
Contributor Author

@momentmaker momentmaker Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I had created the conditional here:

else
if [[ ${{ github.event.label.name }} == 'build-publish' ]]; then
echo "image-tag=pr-${{ github.event.number }}-${short_sha}" | tee -a $GITHUB_OUTPUT
echo "build-publish=true" | tee -a $GITHUB_OUTPUT
fi
fi

so only the label build-publish will be built and published
it starts out with being false:
echo "build-publish=false" | tee -a $GITHUB_OUTPUT

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That will skip the build and publish docker job if the label is not on the PR, right? I guess I was assuming that we would have this workflow to cover all normal builds too (PR's without the label) and in those cases, we don't want to publish the image (if the label isn't on the PR).

Copy link
Collaborator

@kalverra kalverra Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it if we could hook our E2E tests (which run on almost every PR) into this build step as well and not have our own custom one any more. Is requiring the build-publish tag necessary for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah great point - looking over your ticket I had added this :)

workflow_dispatch:
inputs:
git_ref:
description: "The git ref to check out"
required: true
build-publish:
description: "Whether to build and publish - defaults to just build"
required: false
default: "false"

would this solve your issue?
of course we will need to tweak the goreleaser-build-sign-publish composite action a bit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalverra that's going to be big (avoid all of those unnecessary builds). Glad you're thinking about that.

We might need to push all images from PRs to ECR though if you're going to use it from tests (unless we used artifacts but...). In that case maybe we have a way to differentiate between docker images from PR's that can be pruned out quickly via lifecycle rules (only used for tests) and docker images from PR's that might need to run in longer tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see QA has different set of secrets for ECR? it pushes to a different repo no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it does, but I think @kalverra is considering using this image for the tests. If so, we'd need to push all PR images to ECR for your tests, right?

docker-registry: ${{ secrets.AWS_SDLC_ECR_HOSTNAME }}
docker-image-name: chainlink
docker-image-tag: ${{ steps.get-image-tag.outputs.image-tag }}
enable-goreleaser-snapshot: "true"
enable-goreleaser-split: "true"
goreleaser-split-arch: ${{ matrix.goarch }}
goreleaser-exec: ./tools/bin/goreleaser_wrapper
goreleaser-config: .goreleaser.develop.yaml
goreleaser-key: ${{ secrets.GORELEASER_KEY }}
zig-version: 0.11.0

- name: Output image name and digest
if: steps.get-image-tag.outputs.build-publish == 'true'
shell: bash
run: |
# need to check if artifacts.json exists because goreleaser splits the build
if [[ -f dist/artifacts.json ]]; then
artifact_path="dist/artifacts.json"
else
artifact_path="dist/linux_${{ matrix.goarch }}/artifacts.json"
cat dist/linux_${{ matrix.goarch }}/artifacts.json
fi
echo "### Docker Images" | tee -a "$GITHUB_STEP_SUMMARY"
jq -r '.[] | select(.type == "Docker Image") | "`\(.goarch)-image`: \(.name)"' ${artifact_path} >> output.txt
jq -r '.[] | select(.type == "Archive") | "`\(.goarch)-digest`: \(.extra.Checksum)"' ${artifact_path} >> output.txt
while read -r line; do
echo "$line" | tee -a "$GITHUB_STEP_SUMMARY"
done < output.txt

- name: Collect Metrics
if: always()
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@d9da21a2747016b3e13de58c7d4115a3d5c97935 # v3.0.1
with:
id: goreleaser-build-publish
org-id: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }}
basic-auth: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }}
hostname: ${{ secrets.GRAFANA_INTERNAL_HOST }}
this-job-name: goreleaser-build-publish-chainlink (${{ matrix.goarch }})
continue-on-error: true
69 changes: 0 additions & 69 deletions .github/workflows/build-publish-develop.yml

This file was deleted.

66 changes: 0 additions & 66 deletions .github/workflows/build-publish-pr.yml

This file was deleted.

Loading
Loading