Skip to content

Merge pull request #239 from Donggrina/hotfix/fix_find_diary #173

Merge pull request #239 from Donggrina/hotfix/fix_find_diary

Merge pull request #239 from Donggrina/hotfix/fix_find_diary #173

Workflow file for this run

name: Deploy To EC2 with using Docker
on:
push:
branches:
- main
- develop
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Github Repository 파일 불러오기
uses: actions/checkout@v4
- name: JDK17 버전 설치
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: application.yml 만들기
run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application-prod.yml
- name: 빌드하기
run: ./gradlew clean build -x test -Pprod
- name: AWS Resource에 접근할 수 있게 AWS credentials 설정
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: ECR 로그인
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Docker 이미지 생성
run: docker build -t donggrina .
- name: Docker 이미지에 Tag 붙이기
run: docker tag donggrina ${{ steps.login-ecr.outputs.registry }}/donggrina:latest
- name: ECR에 Docker 이미지 push
run: docker push ${{ steps.login-ecr.outputs.registry }}/donggrina:latest
- name: SSH로 EC2에 접속
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script_stop: true
script: |
docker compose stop
docker rm -f $(docker ps -qa)
docker pull ${{ steps.login-ecr.outputs.registry }}/donggrina:latest
docker tag ${{ steps.login-ecr.outputs.registry }}/donggrina:latest donggrina
docker-compose up -d
echo 123
LATEST_IMAGE_ID=$(docker images -q donggrina)
docker rmi $(docker images -q | grep -v $LATEST_IMAGE_ID) || true