-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (129 loc) · 4.9 KB
/
cd-dev.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: TnT CD for dev with Gradle, Docker, AWS
on:
push:
branches:
- develop
jobs:
move-files:
name: move-files
runs-on: ubuntu-latest
steps:
- name: Checkout with Submodule
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.SUBMODULE_PAT }}
fetch-depth: 0
- name: Public IP
uses: haythem/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Github Actions IP 보안그룹 추가
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: AWS EC2 Create Directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_DEV_HOST }}
username: ${{ secrets.EC2_DEV_USERNAME }}
password: ${{ secrets.EC2_DEV_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
script: |
mkdir -p /home/ubuntu/tnt/
- name: Docker env File
run:
cp src/main/resources/config/dev.env ./infra/.env
- name: AWS EC2 Copy Files
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_DEV_HOST }}
username: ${{ secrets.EC2_DEV_USERNAME }}
password: ${{ secrets.EC2_DEV_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
source: "infra"
target: "/home/ubuntu/tnt"
- name: Github Actions IP 보안그룹 삭제
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout with Submodule
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.SUBMODULE_PAT }}
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'corretto'
- name: Gradle cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle 실행 권한 부여
run: chmod +x gradlew
- name: Build without test
run: ./gradlew build -x test
- name: Docker Buildx setting
uses: docker/[email protected]
- name: Dockerhub Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Dockerhub build and push
uses: docker/[email protected]
with:
context: .
file: ./infra/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO }}:latest
build-args: |
"SPRING_ACTIVE_PROFILE=dev"
platforms: |
linux/amd64
linux/arm64
- name: Public IP
uses: haythem/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Github Actions IP 보안그룹 추가
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: AWS EC2 Server Deploy
uses: appleboy/ssh-action@master
env:
COMPOSE: "home/ubuntu/infra/docker-compose-dev.yml"
with:
envs: COMPOSE
host: ${{ secrets.EC2_DEV_HOST }}
username: ${{ secrets.EC2_DEV_USERNAME }}
password: ${{ secrets.EC2_DEV_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
script: |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_TOKEN }}
docker-compose -f $COMPOSE down --rmi all
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO }}
docker-compose -f $COMPOSE up -d
echo "##### EC2 배포 완료 #####"
- name: Github Actions IP 보안그룹 삭제
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32