-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.52 KB
/
cd_gradle.yaml
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
name: Java CD with Gradle
on:
workflow_dispatch:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## create application-secret.yml
- name: make application-secret.yml
run: |
mkdir -p ./api/src/main/resources
touch ./api/src/main/resources/application-secret.yml
shell: bash
- name: deliver application-secret.yml
run: echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application-secret.yaml
shell: bash
# 빌드 및 테스트 단계.
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# gradle build
- name: Build with Gradle
run: ./gradlew build -x test
# push 하기 위해 로그인
- name: Docker Hub 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_ID }}
password: ${{ secrets.DOCKER_PASSWORD }}
#도커 빌드 & 이미지 push
- name: Docker build & Push
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKER_ID }}/gitbox .
docker push ${{ secrets.DOCKER_ID }}/gitbox
# Docker 파일을 홈 서버에 배포
- name: Deploy to Prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOME_SERVER_IP }}
username: tuna
password: ${{ secrets.HOME_SERVER_PASSWORD }}
port: 22
script: |
if [ ! -z "$(docker ps -q)" ]; then
docker stop $(docker ps -q)
fi
if [ ! -z "$(docker ps -aq)" ]; then
docker rm $(docker ps -aq)
fi
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
docker pull ${{ secrets.DOCKER_ID }}/gitbox
docker network create gitbox
docker run -d \
--name redis \
--network=gitbox \
-p 6379:6379 \
redis
docker run -d \
--name gitbox-server \
--network=gitbox \
-p 1234:1234 \
-e TZ=Asia/Seoul \
${{ secrets.DOCKER_ID }}/gitbox
docker system prune -f