Skip to content

Commit

Permalink
[TT-707] Build Test Base Image As Needed in CI (smartcontractkit#11329)
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Nov 17, 2023
1 parent 738146e commit 5f09e55
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 22 deletions.
62 changes: 56 additions & 6 deletions .github/actions/build-test-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ inputs:
description: The test suites to build into the image
default: chaos migration performance reorg smoke soak benchmark load/automationv2_1
required: false
base_image_tag:
description: The test base image version to use, if not provided it will use the version from the ./integration-tests/go.mod file
required: false
QA_AWS_ROLE_TO_ASSUME:
description: The AWS role to assume as the CD user, if any. Used in configuring the docker/login-action
required: true
Expand All @@ -33,14 +30,66 @@ inputs:
runs:
using: composite
steps:

# Base Test Image Logic
- name: Get CTF Version
if: ${{ inputs.base_image_tag == '' }}
id: version
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/mod-version@e865e376b8c2d594028c8d645dd6c47169b72974 # v2.2.16
with:
go-project-path: ./integration-tests
module-name: github.com/smartcontractkit/chainlink-testing-framework
enforce-semantic-tag: "true" # it has to be in the form of v1.2.3 or the image won't exist
enforce-semantic-tag: false
- name: Get CTF sha
if: steps.version.outputs.is_semantic == 'false'
id: short_sha
env:
VERSION: ${{ steps.version.outputs.version }}
shell: bash
run: |
short_sha="${VERSION##*-}"
echo "short sha is: ${short_sha}"
echo "short_sha=${short_sha}" >> "$GITHUB_OUTPUT"
- name: Checkout chainlink-testing-framework
if: steps.version.outputs.is_semantic == 'false'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: smartcontractkit/chainlink-testing-framework
ref: main
fetch-depth: 0
path: ctf
- name: Get long sha
if: steps.version.outputs.is_semantic == 'false'
id: long_sha
env:
SHORT_SHA: ${{ steps.short_sha.outputs.short_sha }}
shell: bash
run: |
cd ctf
long_sha=$(git rev-parse ${SHORT_SHA})
echo "sha is: ${long_sha}"
echo "long_sha=${long_sha}" >> "$GITHUB_OUTPUT"
- name: Check if test base image exists
if: steps.version.outputs.is_semantic == 'false'
id: check-base-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@00c6214deb10a3f374c6d3430c32c5202015d463 # v2.2.12
with:
repository: ${{ inputs.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ inputs.QA_AWS_REGION }}.amazonaws.com/test-base-image
tag: ${{ steps.long_sha.outputs.long_sha }}
AWS_REGION: ${{ inputs.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ inputs.QA_AWS_ROLE_TO_ASSUME }}
- name: Build Base Image
if: steps.version.outputs.is_semantic == 'false' && steps.check-base-image.outputs.exists == 'false'
uses: smartcontractkit/chainlink-github-actions/docker/build-push@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
env:
BASE_IMAGE_NAME: ${{ inputs.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ inputs.QA_AWS_REGION }}.amazonaws.com/test-base-image:${{ steps.long_sha.outputs.long_sha }}
with:
tags: ${{ env.BASE_IMAGE_NAME }}
file: ctf/k8s/Dockerfile.base
AWS_REGION: ${{ inputs.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ inputs.QA_AWS_ROLE_TO_ASSUME }}
# End Base Image Logic

# Test Runner Logic
- name: Check if image exists
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@00c6214deb10a3f374c6d3430c32c5202015d463 # v2.2.12
Expand All @@ -59,7 +108,7 @@ runs:
file: ./integration-tests/test.Dockerfile
build-args: |
BASE_IMAGE=${{ inputs.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ inputs.QA_AWS_REGION }}.amazonaws.com/test-base-image
IMAGE_VERSION=${{ inputs.base_image_tag || steps.version.outputs.version }}
IMAGE_VERSION=${{ steps.long_sha.outputs.long_sha || steps.version.outputs.version }}
SUITES="${{ inputs.suites }}"
AWS_REGION: ${{ inputs.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ inputs.QA_AWS_ROLE_TO_ASSUME }}
Expand All @@ -71,3 +120,4 @@ runs:
run: |
echo "### ${INPUTS_REPOSITORY} image tag for this test run :ship:" >>$GITHUB_STEP_SUMMARY
echo "\`${INPUTS_TAG}\`" >>$GITHUB_STEP_SUMMARY
# End Test Runner Logic
20 changes: 4 additions & 16 deletions .github/workflows/integration-tests-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ on:
branches:
- develop
workflow_dispatch:
inputs:
ctf-base-image-tag:
description: |
'The tag of the CTF base image to be used,
typically something like v1.18.6 from https://github.com/smartcontractkit/chainlink-testing-framework/releases
or a custom tag or branch you have pushed.'
required: true

env:
ECR_TAG: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink-tests:develop
Expand All @@ -39,20 +32,15 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup Other Tags
- name: Setup Other Tags If Not Workflow Dispatch
id: tags
env:
BASE_IMAGE_TAG: ${{ inputs.ctf-base-image-tag}}
if: github.event_name != 'workflow_dispatch'
run: |
if [ -z "${BASE_IMAGE_TAG+x}" ]; then
echo "ctf-base-image-tag is not set, we are part of a merge and want to push the develop tag"
echo "other_tags=${ECR_TAG}" >> $GITHUB_OUTPUT
fi
echo "other_tags=${ECR_TAG}" >> $GITHUB_OUTPUT
- name: Build Image
uses: ./.github/actions/build-test-image
with:
other_tags: ${{ steps.tags.outputs.other_tags }}
base_image_tag: ${{ inputs.ctf-base-image-tag }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ACCOUNT_NUMBER: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}
Expand All @@ -68,7 +56,7 @@ jobs:
build-chainlink-image:
environment: integration
# Only run this build for workflow_dispatch
if: ${{ inputs.ctf-base-image-tag != '' }}
if: github.event_name == 'workflow_dispatch'
permissions:
id-token: write
contents: read
Expand Down

0 comments on commit 5f09e55

Please sign in to comment.