-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (81 loc) · 3.28 KB
/
gradle-dev.yml
File metadata and controls
95 lines (81 loc) · 3.28 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
# 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: Java CI(dev) with Gradle
on:
push:
branches:
- dev
permissions:
contents: read
jobs:
if_merged:
runs-on: ubuntu-latest
steps:
- name: Check if merged
run: |
if [[ "$(git log -1 --pretty=%B)" == *"Merge branch"* ]]; then
echo "The branch was merged"
else
echo "The branch was pushed without merge"
fi
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: make application.properties
run: |
cd ./src/main/resources # resources 폴더로 이동
touch ./application-dev.properties # application.properties 생성
echo "${{ secrets.APPLICATION_DEV }}" > ./application-dev.properties # github actions에서 설정한 값을 application.yml 파일에 쓰기
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker build & push
run: |
docker build -f Dockerfile.dev -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}
## deploy to production
- name: Deploy to dev
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.AWS_USERNAME }}
key: ${{ secrets.AWS_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f redis
sudo docker rm -f creative-semester-dev
sudo docker pull redis
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}
docker run -d -p 6379:6379 --network creative-semester-network --name redis redis
docker run -d -p 8082:8082 --network creative-semester-network --name creative-semester-dev ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}
docker image prune -f
current-time:
needs: build
runs-on: ubuntu-latest
steps:
- name: Get Current Time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH:mm:ss
utcOffset: "+09:00" # 기준이 UTC이기 때문에 한국시간인 KST를 맞추기 위해 +9시간 추가
- name: Print Current Time
run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" # current-time 에서 지정한 포맷대로 현재 시간 출력
shell: bash