Skip to content

Commit

Permalink
deploy.yml 파일 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
m020202 committed Jul 27, 2024
1 parent 90f0684 commit cd2db66
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy To EC2

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Github Repository 파일 불러오기
uses: actions/checkout@v4

- name: JDK 17버전 설치
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: application.yml 파일 생성
run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml

- name: 테스트 및 빌드
run: ./gradlew clean build

- name: AWS Resource에 접근할 수 있게 AWS credentials 설정
uses: aws-actions/configure-aws-credential@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 locavel-server .

- name: Docker 이미지 생성
run: docker tag locavel-server ${{ steps.login-ecr.outputs.registry }}

- name: ECR에 Docker 이미지 Push 하기
run: docker push ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest



- name: SSH로 EC2에 접속하기
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
docker stop locavel-server || true
docker rm locavel-server || true
docker pull ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest
docker run -d --name locavel-server -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/locavel-server:latest
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ out/
### VS Code ###
.vscode/
# YAML files
*.yml
*.yml

# CI/CD 관련 deploy.yml 파일 제외
!.github/workflows/deploy.yml

0 comments on commit cd2db66

Please sign in to comment.