Skip to content

refac: changing image registry saving point to AWS Public ECR #124

refac: changing image registry saving point to AWS Public ECR

refac: changing image registry saving point to AWS Public ECR #124

Workflow file for this run

name: Develop deploy workflow
on:
workflow_dispatch:
push:
branches:
- 'develop'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- run: yarn run test
build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Push Image to AWS ECR Public Repo
id: ecr-image-push
run: |
aws ecr-public get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}
docker build -t ${{ secrets.ECR_REPOSITORY }}:latest .
docker tag ${{ secrets.ECR_REPOSITORY }}:latest public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.ECR_REPOSITORY }}:latest
docker push public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.ECR_REPOSITORY }}:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: ssh command deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.PEM_KEY }}
script: |
sudo docker stop dev-server
sudo docker rm dev-server
sudo docker rm -f $(docker ps -qa)
sudo docker image prune -a -f
sudo docker pull public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.ECR_REPOSITORY }}:latest
sudo docker run --name dev-server --env-file .env -d -p 3000:3000 -t public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.ECR_REPOSITORY }}:latest