From 8c5dde6e696ebbc99fc1479bbe2ecfc552c38071 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Wed, 6 Oct 2021 13:29:29 -0400 Subject: [PATCH] add github actions for int, stg, and public --- ...s_push-dev.yml => aws-push-dev-to-int.yml} | 28 ++-------- .github/workflows/aws-push-main-to-stg.yml | 51 +++++++++++++++++++ .../workflows/aws-push-release-to-public.yml | 51 +++++++++++++++++++ 3 files changed, 107 insertions(+), 23 deletions(-) rename .github/workflows/{aws_push-dev.yml => aws-push-dev-to-int.yml} (53%) create mode 100644 .github/workflows/aws-push-main-to-stg.yml create mode 100644 .github/workflows/aws-push-release-to-public.yml diff --git a/.github/workflows/aws_push-dev.yml b/.github/workflows/aws-push-dev-to-int.yml similarity index 53% rename from .github/workflows/aws_push-dev.yml rename to .github/workflows/aws-push-dev-to-int.yml index df03e32..ef11506 100644 --- a/.github/workflows/aws_push-dev.yml +++ b/.github/workflows/aws-push-dev-to-int.yml @@ -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: @@ -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 diff --git a/.github/workflows/aws-push-main-to-stg.yml b/.github/workflows/aws-push-main-to-stg.yml new file mode 100644 index 0000000..8107aad --- /dev/null +++ b/.github/workflows/aws-push-main-to-stg.yml @@ -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 diff --git a/.github/workflows/aws-push-release-to-public.yml b/.github/workflows/aws-push-release-to-public.yml new file mode 100644 index 0000000..878ec51 --- /dev/null +++ b/.github/workflows/aws-push-release-to-public.yml @@ -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