-
Notifications
You must be signed in to change notification settings - Fork 3
97 lines (83 loc) · 3.18 KB
/
Copy pathgradle.yml
File metadata and controls
97 lines (83 loc) · 3.18 KB
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: CI/CD
on:
push:
branches: [ "dev" ]
# pull_request:
# branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# Github secrets로부터 데이터를 받아서, 워크 플로우에 파일을 생성
- name: Make application.properties
run: |
cd ./src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
shell: bash
- name: Make Gcs credentials
run: |
cd ./src/main/resources
touch ./gcs_secret.json
echo "${{ secrets.GCS_JSON }}" | base64 -d > ./gcs_secret.json
shell: bash
- name: Build with Gradle Wrapper
run: |
chmod +x gradlew
./gradlew build
# - name: Save SSH key
# run: |
# touch ./key
# echo "${{ secrets.KEY }}" > ./key
# chmod 600 key
- name: Add SSH known hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "Scanning host: ${{ secrets.HOST }}"
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
echo "Known hosts after scanning:"
cat ~/.ssh/known_hosts
# WAR 파일을 서버로 옮기기
- name: Copy WAR file to server
run : |
scp -i ~/.ssh/id_rsa ./build/libs/*.war ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/home/dhbs1010a/war
## 도커허브 로그
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWD }}
## 웹 이미지 빌드 및 도커허브에 push
# - name: web docker build and push
# run: |
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWD }}
# docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest .
# docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
## docker compose up
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{secrets.USERNAME}}
key: ${{ secrets.KEY }}
script: |
cd ~
sudo docker compose up -d app
sudo docker cp ~/war/backend-1.0-SNAPSHOT.war team-spring:/usr/local/tomcat/webapps/ROOT.war
sudo docker image prune -f