-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (78 loc) · 3.16 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
name: CD-dev
on:
push:
branches: [ "main", "develop" ]
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set .env for configuration
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
rm -rf ./.env
touch ./.env
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> ./.env
echo "DOCKER_REPOSITORY=${{ secrets.DOCKER_REPOSITORY }}" >> ./.env
echo "DB_URL=${{ secrets.DEV_DB_URL }}" >> ./.env
echo "DB_USERNAME=${{ secrets.DEV_DB_USERNAME }}" >> ./.env
echo "DB_PASSWORD=${{ secrets.DEV_DB_PASSWORD }}" >> ./.env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> ./.env
echo "JWT_ACCESS_TOKEN_EXPIRATION_TIME=${{ secrets.JWT_ACCESS_TOKEN_EXPIRATION_TIME }}" >> ./.env
echo "JWT_REFRESH_TOKEN_EXPIRATION_TIME=${{ secrets.JWT_REFRESH_TOKEN_EXPIRATION_TIME }}" >> ./.env
echo "JWT_REGISTRATION_TOKEN_EXPIRATION_TIME=${{ secrets.JWT_REGISTRATION_TOKEN_EXPIRATION_TIME }}" >> ./.env
echo "KEY_STORE_PASSWORD=${{ secrets.KEY_STORE_PASSWORD }}" >> ./.env
# gradle build
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
## 도커 이미지 빌드 후 도커허브에 push
- name: docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f ./.deploy/Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
username: ubuntu
host: ${{ secrets.HOST }}
key: ${{ secrets.KEY }}
source: "./.deploy/docker-compose-dev.yml"
target: "/home/ubuntu/"
strip_components: 2
## 도커 허브에서 jar파일 및 pull후에 컴포즈 up
- name: Deploy to Dev
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.HOST }}
key: ${{ secrets.KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
docker compose stop ${{secrets.DOCKER_REPOSITORY}}
docker compose rm -f ${{secrets.DOCKER_REPOSITORY}}
docker compose -f docker-compose-dev.yml up -d
docker image prune -f