-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (53 loc) · 2.04 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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: |
chmod +x ./gradlew
./gradlew clean build
- 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 cano-server .
- name: Docker 이미지에 Tag 붙이기
run: docker tag cano-server ${{ steps.login-ecr.outputs.registry }}/cano-server:latest
- name: ECR에 Docker 이미지 Push하기
run: docker push ${{ steps.login-ecr.outputs.registry }}/cano-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: |
cd /cano-server
docker compose down || true
docker compose pull
docker compose up -d
# docker stop cano-server || true
# docker rm cano-server || true
# docker pull ${{ steps.login-ecr.outputs.registry }}/cano-server:latest
# docker run -d --name cano-server -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/cano-server:latest