Skip to content

Commit

Permalink
added ECR deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
YannMjl committed Apr 12, 2024
1 parent d4cc42e commit a1ece5a
Show file tree
Hide file tree
Showing 8 changed files with 1,440 additions and 1,798 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/deploy_to_aws_ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This is a basic workflow to help you get started with Actions

name: Deploy to ECR

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains multiple jobs
build_test:
name: Build & Test App
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@master
with:
node-version: ${{ matrix.node-version }}
# install applicaion dependencies
- name: Install dependencies
run: |
npm install
npm ci
# build and test the apps
- name: build & test
run: |
npm run build
npm run test
# upload the app docker image to AWS ECR
push_to_AWS_ECR:
name: Deploy docker image to AWS ECR
runs-on: ubuntu-latest

# run this job only if the app build and test successfully
needs: [build_test]

steps:
- name: Checkout
uses: actions/checkout@v2

- 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 the image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_REPO_NAME }}
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ name: CI-CD
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# push:
# branches: [ main ]
# pull_request:
# branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -25,7 +25,7 @@ jobs:
node-version: [14.x]

# Run build and test only if the commit message says build app
if: "contains(github.event.commits[0].message, '[build app]')"
#if: "contains(github.event.commits[0].message, '[build app]')"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
Loading

0 comments on commit a1ece5a

Please sign in to comment.