Skip to content

Merge pull request #59 from dnwls16071/fix-episodes #38

Merge pull request #59 from dnwls16071/fix-episodes

Merge pull request #59 from dnwls16071/fix-episodes #38

Workflow file for this run

name: Deploy To EC2
on:
push:
branches:
- dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Github Repository 소스코드 불러오기
uses: actions/checkout@v4
- name: JDK 17 Version 설치하기
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- name: application.yml 파일 작성하기
run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml
- name: 실행 권한 부여하기
run: chmod +x ./gradlew
- name: 빌드하기
run: ./gradlew clean build -x test
- 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 aniwhere .
- name: Docker 이미지에 태그 붙이기
run: docker tag aniwhere ${{ steps.login-ecr.outputs.registry }}/aniwhere:latest
- name: ECR에 Docker 이미지 푸시하기
run: docker push ${{ steps.login-ecr.outputs.registry }}/aniwhere:latest
- name: docker-compose.yml 전송하기
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: "docker-compose.yml, Dockerfile, build/libs/*.jar"
target: "~/app"
- name: SSH로 EC2에 접속하기
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
cd ~/app
docker compose down || true
docker compose pull
docker compose up -d --build