From 7998cc420c9c77fe7e1dd6b635a8e96c4d6c5e6c Mon Sep 17 00:00:00 2001 From: ladunuthala <133906074+ladunuthala@users.noreply.github.com> Date: Thu, 18 May 2023 16:38:46 -0400 Subject: [PATCH] Create push_to_ECR --- .github/workflows/push_to_ECR | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/push_to_ECR diff --git a/.github/workflows/push_to_ECR b/.github/workflows/push_to_ECR new file mode 100644 index 0000000..313af4e --- /dev/null +++ b/.github/workflows/push_to_ECR @@ -0,0 +1,45 @@ +name: Deploy to ECR + +on: + push: + branches: [ master ] + +jobs: + + build: + + name: Build Image + runs-on: ubuntu-latest + + + steps: + + - name: Check out code + uses: actions/checkout@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} + AWS_REGION: us-east-1 + + - name: Build, test, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: clo835-week4 + IMAGE_TAG: v0.1 + run: | + cd Chapter02/kubia/ + ls -ltra + # Docker build + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + # Unit test + docker run -d -p 80:8080 --name nodeapp $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker ps + echo "Pause for 10 seconds to let container start" + sleep 10 + curl localhost -vvv + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG