-
Notifications
You must be signed in to change notification settings - Fork 3
97 lines (81 loc) · 3.87 KB
/
gradle.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
name: Deploy
on:
push:
branches: [ "develop", "Feat/#53" ]
pull_request:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
# 폴더 정보 확인
- name: List the repository structure
run: ls -R
# JDK 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Gradlew 실행 허용
- name: Grant execute permission for gradlew
run: chmod +x ./wabi/gradlew
# 환경 변수 설정
- name: Set environment values
run: |
touch ./wabi/src/main/resources/env.properties
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" >> ./env.properties
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> ./env.properties
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> ./env.properties
echo "JWT_KEY=${{ secrets.JWT_KEY }}" >> ./env.properties
echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" >> ./env.properties
echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" >> ./env.properties
echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" >> ./env.properties
shell: bash
# Gradle build (Test 제외)
- name: Build with Gradle
run: |
ls
cd wabi
ls
./gradlew clean build -x test
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
cd wabi
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest . # 이미지에 latest 태그를 추가
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest seongwonyoon/wabi:${GITHUB_SHA::7} # GITHUB_SHA를 이용한 커밋 태그 추가
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest # latest 버전 푸시
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} # 커밋 해시 버전 푸시
# Deploy
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
envs: GITHUB_SHA
script: |
#!/bin/bash
ls
cd /
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
# Create .env file in the correct directory
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" | sudo tee -a .env > /dev/null
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" | sudo tee -a .env > /dev/null
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" | sudo tee -a .env > /dev/null
echo "JWT_KEY=${{ secrets.JWT_KEY }}" | sudo tee -a .env > /dev/null
echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" | sudo tee -a .env > /dev/null
echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" | sudo tee -a .env > /dev/null
echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" | sudo tee -a .env > /dev/null
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" | sudo tee -a .env > /dev/null
echo "DOCKERHUB_REPOSITORY=${{ secrets.DOCKERHUB_REPOSITORY }}" | sudo tee -a .env > /dev/null
sudo docker-compose down
sudo docker-compose up -d