-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds reusable workflow to build and publish ECR images (#15)
- Loading branch information
1 parent
16e1553
commit 263f99f
Showing
5 changed files
with
497 additions
and
0 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,9 @@ | ||
FROM alpine:3.16 | ||
|
||
ARG VERSION=latest | ||
|
||
WORKDIR /app | ||
|
||
RUN echo '{"version": "'"$VERSION"'"}' > info.json | ||
|
||
CMD [ "cat", "/app/info.json" ] |
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,44 @@ | ||
--- | ||
|
||
name: 'Test build-ecr-image workflow' | ||
description: 'Runs validation against the build-ecr-image workflow' | ||
|
||
inputs: | ||
aws-account-id: | ||
description: 'The AWS Account id' | ||
required: true | ||
ref: | ||
description: 'The github ref to expect' | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: 'Setup brew' | ||
uses: Homebrew/actions/setup-homebrew@master | ||
|
||
- name: 'Install BATS' | ||
shell: bash | ||
run: brew install bats-core | ||
|
||
- name: 'Set up Docker Buildx' | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: 'Checkout' | ||
uses: actions/checkout@v3 | ||
|
||
- name: 'Configure AWS Credentials' | ||
uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
aws-region: 'us-east-1' | ||
role-to-assume: arn:aws:iam::${{ inputs.aws-account-id }}:role/github-actions-tests | ||
|
||
- name: 'Log into AWS ECR' | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: 'Validate' | ||
shell: bash | ||
run: bats --verbose-run -r ${{ github.action_path }}/build-ecr-image.bats | ||
env: | ||
ECR_REPOSITORY: ${{ inputs.aws-account-id }}.dkr.ecr.us-east-1.amazonaws.com/github-actions-tests | ||
VERSION_TAG: ${{ inputs.ref || github.sha }} |
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,22 @@ | ||
#!/usr/bin/env bats | ||
|
||
function setup() { | ||
: | ||
} | ||
|
||
function teardown() { | ||
: | ||
} | ||
|
||
@test "it should have deployed the image to ecr" { | ||
run docker pull "$ECR_REPOSITORY:$VERSION_TAG" | ||
|
||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "it should run the correct image" { | ||
run docker run "$ECR_REPOSITORY:$VERSION_TAG" | ||
|
||
[ "$status" -eq 0 ] | ||
[ "$output" = "{\"version\": \"$VERSION_TAG\"}" ] | ||
} |
Oops, something went wrong.