-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DCMAW-11057: Push STS test image to dev and build (#338)
- Loading branch information
1 parent
a9c5517
commit f624de1
Showing
5 changed files
with
161 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Build, Sign, Push and Tag test image | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
WORKING_DIRECTORY: | ||
required: true | ||
type: string | ||
secrets: | ||
GH_ACTIONS_ROLE_ARN: | ||
required: true | ||
TEST_IMAGE_REPOSITOR_URI: | ||
required: true | ||
CONTAINER_SIGN_KMS_KEY: | ||
required: true | ||
|
||
jobs: | ||
build-and-push: | ||
name: build-and-push | ||
runs-on: ubuntu-24.04 | ||
env: | ||
IMAGE_TAG: latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ${{ inputs.WORKING_DIRECTORY }} | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 | ||
with: | ||
submodules: true | ||
fetch-depth: 0 | ||
|
||
- name: Install Cosign | ||
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da #v3.7.0 | ||
with: | ||
cosign-release: 'v1.9.0' | ||
|
||
- name: Authenticate with AWS | ||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4.0.2 | ||
with: | ||
aws-region: eu-west-2 | ||
role-to-assume: ${{ secrets.GH_ACTIONS_ROLE_ARN }} | ||
|
||
- name: Login to AWS ECR | ||
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 #v2.0.1 | ||
|
||
- name: Build image | ||
run: | | ||
docker build -t ${{ secrets.TEST_IMAGE_REPOSITOR_URI }}:$IMAGE_TAG . | ||
- name: Push image | ||
run: | | ||
docker push ${{ secrets.TEST_IMAGE_REPOSITOR_URI }}:$IMAGE_TAG | ||
- name: Sign image | ||
run: | | ||
cosign sign --key awskms:///${{ secrets.CONTAINER_SIGN_KMS_KEY }} ${{ secrets.TEST_IMAGE_REPOSITOR_URI }}:$IMAGE_TAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM node:iron-alpine | ||
|
||
RUN adduser --disabled-password test | ||
RUN chown test . | ||
|
||
RUN apk upgrade && apk update; apk add --no-cache bash aws-cli && aws --version | ||
|
||
WORKDIR /sts-mock | ||
|
||
COPY package.json package-lock.json ./ | ||
RUN npm clean-install --no-scripts | ||
|
||
COPY tests/ ./tests/ | ||
COPY jest.config.ts tsconfig.json ./ | ||
|
||
COPY run-tests.sh / | ||
RUN chmod 005 /run-tests.sh | ||
USER test | ||
|
||
ENTRYPOINT ["/run-tests.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
stack_name=${1:-mob-sts-mock} | ||
|
||
echo "Running tests against ${stack_name}" | ||
|
||
rm -rf docker-vars.env | ||
|
||
export AWS_DEFAULT_REGION="eu-west-2" | ||
TEST_REPORT_DIR="results" | ||
ENVIRONMENT="dev" | ||
|
||
aws cloudformation describe-stacks \ | ||
--stack-name "$stack_name" \ | ||
--query 'Stacks[0].Outputs[].{key: OutputKey, value: OutputValue}' \ | ||
--output text >cf-output.txt | ||
|
||
eval $(awk '{ printf("export CFN_%s=\"%s\"\n", $1, $2) }' cf-output.txt) | ||
awk '{ printf("CFN_%s=\"%s\"\n", $1, $2) }' cf-output.txt >>docker-vars.env | ||
|
||
{ | ||
echo TEST_REPORT_DIR="$TEST_REPORT_DIR" | ||
echo TEST_REPORT_ABSOLUTE_DIR="/results" | ||
echo TEST_ENVIRONMENT="$ENVIRONMENT" | ||
echo SAM_STACK_NAME="$stack_name" | ||
} >>docker-vars.env | ||
|
||
docker build --tag testcontainer . | ||
|
||
docker run --rm --interactive --tty \ | ||
--user root \ | ||
--env-file docker-vars.env \ | ||
--volume "$(pwd):/results" \ | ||
testcontainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
remove_quotes() { | ||
echo "$1" | tr -d '"' | ||
} | ||
|
||
export STS_MOCK_API_URL=$(remove_quotes "$CFN_StsMockApiUrl") | ||
|
||
if npm run test:api; then | ||
cp -rf results "$TEST_REPORT_ABSOLUTE_DIR" | ||
else | ||
cp -rf results "$TEST_REPORT_ABSOLUTE_DIR" | ||
exit 1 | ||
fi |