Skip to content

Commit

Permalink
add github actions for int, stg, and public
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Oct 6, 2021
1 parent 633ec99 commit 8c5dde6
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,14 @@
# ------------------------
# Outside Configurations
# ------------------------
# 1. Create the repository in AWS ECR.
# Use naming convention `-dev` (e.g. ld4p/qa_authority_lookup-dev) for dev branch
# Use naming convention of no extension (e.g. ld4p/qa_authority_lookup) for main branch
#
# 2. Set GitHub Repository Secrets in GitHub application repo (the one defining the image, e.g. ld4p/qa_server_container).
# In GitHub repository click: Settings -> Secrets -> New repository secret -> add the following secrets
# Set GitHub Repository Secrets in GitHub application repo (the one defining the image, e.g. ld4p/qa_server_container).
# In GitHub repository click: Settings -> Secrets -> New repository secret -> add the following secrets
# * Name: AWS_ACCESS_KEY_ID
# Value: _copy access key from AWS automation user_
# * Name: AWS_SECRET_ACCESS_KEY
# Value: _copy secret access key from AWS automation user_
#
# ------------------------
# Updates to this Configuration
# ------------------------
# 1. Set the branch name
# Branch: (choose one) update on -> push -> branches in this config.
# * Set to [ dev ] for build of commits to dev branch
# * Set to [ main ] for build of commits to main branch
#
# 2. Set the ECR_REPOSITORY name
# * update jobs -> build -> steps -> step named Build, tag, and push -> env -> ECR_REPOSITORY in this config.
# * Set to repository name as created in AWS ECR, for example
# ld4p/qa_authority_lookup-dev for [ dev ] branch
# ld4p/qa_authority_lookup for [ main ] branch
#
name: Push ld4p/qa_server_container image to Amazon ECR as ld4p/qa_authority_lookup-dev

name: Push image of dev branch to integration image at Amazon ECR as ld4p/qa_authority_lookup-int

on:
push:
Expand All @@ -45,7 +27,7 @@ jobs:
run: |
VER=$(cat VERSION)
echo "VERSION=$VER" >> $GITHUB_ENV
echo "REPOSITORY_NAME=ld4p/qa_authority_lookup-test" >> $GITHUB_ENV
echo "REPOSITORY_NAME=ld4p/qa_authority_lookup-int" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/aws-push-main-to-stg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Description: Builds and pushes the Docker image created by Dockerfile to AWS ECR.
#
# ------------------------
# Outside Configurations
# ------------------------
# Set GitHub Repository Secrets in GitHub application repo (the one defining the image, e.g. ld4p/qa_server_container).
# In GitHub repository click: Settings -> Secrets -> New repository secret -> add the following secrets
# * Name: AWS_ACCESS_KEY_ID
# Value: _copy access key from AWS automation user_
# * Name: AWS_SECRET_ACCESS_KEY
# Value: _copy secret access key from AWS automation user_

name: Push image of main branch to staging image at Amazon ECR as ld4p/qa_authority_lookup-stg

on:
push:
branches: [ main ]

jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set variables
run: |
VER=$(cat VERSION)
echo "VERSION=$VER" >> $GITHUB_ENV
echo "REPOSITORY_NAME=ld4p/qa_authority_lookup-stg" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.REPOSITORY_NAME }}
SHA_IMAGE_TAG: ${{ github.sha }}
VERSION_IMAGE_TAG: ${{ env.VERSION }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$VERSION_IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
51 changes: 51 additions & 0 deletions .github/workflows/aws-push-release-to-public.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Description: Builds and pushes the Docker image created by Dockerfile to AWS ECR.
#
# ------------------------
# Outside Configurations
# ------------------------
# Set GitHub Repository Secrets in GitHub application repo (the one defining the image, e.g. ld4p/qa_server_container).
# In GitHub repository click: Settings -> Secrets -> New repository secret -> add the following secrets
# * Name: AWS_ACCESS_KEY_ID
# Value: _copy access key from AWS automation user_
# * Name: AWS_SECRET_ACCESS_KEY
# Value: _copy secret access key from AWS automation user_

name: Push image of release tag to public image at Amazon ECR as ld4p/qa_authority_lookup

on:
release:
types: [ published ]

jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set variables
run: |
VER=$(cat VERSION)
echo "VERSION=$VER" >> $GITHUB_ENV
echo "REPOSITORY_NAME=ld4p/qa_authority_lookup-stg" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.REPOSITORY_NAME }}
SHA_IMAGE_TAG: ${{ github.sha }}
VERSION_IMAGE_TAG: ${{ env.VERSION }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$VERSION_IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY

0 comments on commit 8c5dde6

Please sign in to comment.