-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (69 loc) · 3.66 KB
/
cicd.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
name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
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'
- name: Create application.yml
# github actions에서 설정한 값을 application.yml 파일에 쓰기
run: |
touch ./src/main/resources/application.yml
echo -e "${{secrets.ACTIVE_PROFILE}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.DATASOURCE_URL_DEV}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.DATASOURCE_USERNAME}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.DATASOURCE_PASSWORD}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.ACCESSTOKEN_EXPIREDDATE}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.JWT_EXPIRED_IN}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.JWT_SECRET_KEY}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.DATA_REDIS_HOST}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.DATA_REDIS_PORT}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.OAUTH_APPLE_CLIENT_ID}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.OAUTH_APPLE_NONCE}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.OAUTH_KAKAO_CLIENT_ID}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.AWS_S3_BUCKET_NAME}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.AWS_S3_ACCESS_KEY}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.AWS_S3_SECRET_KEY}}" | base64 --decode > ./src/main/resources/application.yml
echo -e "${{secrets.USER_DEFAULTIMAGE}}" | base64 --decode > ./src/main/resources/application.yml
- name: Test env
if: env.ACTIVE_PROFILE == 'dev'
run: echo "ACTIVE PROFILE is dev"
env:
ACTIVE_PROFILE: ${{ secrets.ACTIVE_PROFILE }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle Wrapper
run: ./gradlew build
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/conet:latest
docker push ${{ secrets.DOCKER_USERNAME }}/conet:latest
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS
port: 22
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # pem 키
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/conet:latest
docker stop $(docker ps -a -q)
docker run -d --log-driver=syslog -p 9001:9000 ${{ secrets.DOCKER_USERNAME }}/conet:latest
docker rm $(docker ps --filter 'status=exited' -a -q)
docker image prune -a -f