-
Notifications
You must be signed in to change notification settings - Fork 1
67 lines (54 loc) · 2.02 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
name: CI / CD
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시
application-build:
runs-on: ubuntu-latest
permissions:
contents: read
# 지정한 저장소(현재 REPO)에서 코드를 워크플로우 환경으로 가져오도록 하는 github action
steps:
- uses: actions/checkout@v4
# 1. Java 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 2. application-private.yml 설정
- name: Set application-private.yml file
run: |
# application-private.yml 파일 생성
cd ./src/main/resources
touch ./application-private.yml
# GitHub-Actions 에서 설정한 값을 application-private.yml 파일에 쓰기
echo "${{ secrets.APPLICATION_PRIVATE_YML }}" >> ./application-private.yml
shell: bash
# 3. gradle을 통해 소스를 빌드.
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build
# 4. Docker image 업로드
# { username/repository } 로 빌드 & . 이 의미하는 것은 Dockerfile의 경로를 의미함.
- name: Docker build & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USER }}/wssrs .
docker push ${{ secrets.DOCKER_USER }}/wssrs
run-docker-image-on-ec2:
needs: application-build
runs-on: self-hosted
steps:
- name: docker pull
run: sudo docker pull ${{ secrets.DOCKER_USER }}/wssrs:latest
- name: docker stop container
run: sudo docker stop clerker:latest || true
- name: docker run new container
run: sudo docker run --name github-actions-demo --rm -d -p 8080:8080 ${{ secrets.DOCKER_USER }}/wssrs:latest
- name: delete old docker image
run: sudo docker image prune -f