-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (43 loc) · 1.56 KB
/
main.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
name: CI/CD using github actions & docker
on:
push:
branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
- name: set chmod
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2 .
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
port: ${{ secrets.PORT }} #ssh port (22)
envs: GITHUB_SHA
script: |
docker stop sopo_v2
docker rm sopo_v2
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker run -d -p 8080:8080 --name sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2