Skip to content

Commit

Permalink
Adds reusable workflow to build and publish ECR images (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-carey authored Feb 14, 2023
1 parent 16e1553 commit 263f99f
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/actions/test-build-ecr-image/Dockerfile
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" ]
44 changes: 44 additions & 0 deletions .github/actions/test-build-ecr-image/action.yml
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 }}
22 changes: 22 additions & 0 deletions .github/actions/test-build-ecr-image/build-ecr-image.bats
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\"}" ]
}
Loading

0 comments on commit 263f99f

Please sign in to comment.