test: GitAction 배포 테스트 #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Development deploy workflow | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'feat/2-infra-setup' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
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 }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Push Image to AWS ECR Public Repo | |
id: ecr-image-push | |
run: | | |
aws ecr-public get-login-password --region ${{ secrets.AWS_PUBLIC_REPO_REGION }} | docker login --username AWS --password-stdin public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }} | |
docker build -t ${{ secrets.DEV_ECR_REPO }}:latest . | |
docker tag ${{ secrets.DEV_ECR_REPO }}:latest public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.DEV_ECR_REPO }}:latest | |
docker push public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.DEV_ECR_REPO }}:latest | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy SpringBoot in EC2 using SSH script | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DEV_HOST }} | |
username: ubuntu | |
key: ${{ secrets.PEM_KEY }} | |
script: | | |
sudo docker stop dev-app | |
sudo docker rm dev-app | |
sudo docker image prune -a -f | |
sudo docker pull public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.DEV_ECR_REPO }}:latest | |
sudo docker run --name dev-app --env-file .env -d -p 8080:8080 -t public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.DEV_ECR_REPO }}:latest | |