-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (146 loc) ยท 5.77 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# 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 gradle
on:
push:
branches:
- "main"
- "develop"
- "deploy"
pull_request:
branches:
- "main"
- "develop"
- "deploy"
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: github-action-sample-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: space-code-deploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: space-code-deploy
RESOURCE_PATH: ./src/main/resources/application.yml
permissions:
contents: read
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'
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
# (3) gradlew ๊ถํ ์ถ๊ฐ
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle Wrapper
run: ./gradlew build
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
# with:
# gradle-version: '8.5'
#
# - name: Build with Gradle 8.5
# run: gradle build
deploy:
name: deploy
runs-on: ubuntu-latest
needs: build
if: |
github.ref == 'refs/heads/main' ||
github.base_ref == 'deploy'||
github.ref == 'refs/heads/deploy' ||
startsWith(github.head_ref, 'chore/') ||
startsWith(github.head_ref, 'set')
environment: production
steps:
# (1) ๊ธฐ๋ณธ ์ฒดํฌ์์
- name: Checkout
uses: actions/checkout@v3
# (2) application.properties ์ค์
# - uses: actions/checkout@v3
# - run: touch ./src/main/resources/application.properties
# - run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
# - run: cat ./src/main/resources/application.properties
# (3) gradlew ๊ถํ ์ถ๊ฐ
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
# (4) JDK ์ธํ
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# (4.5) application.yml file ์ค์
#- name: Set yml file
# uses: microsoft/variable-substitution@v1
# with:
# files: ${{ env.RESOURCE_PATH }}
# env:
# spring.datasource.url: ${{ secrets.RDS_HOST }}
# spring.datasource.username: ${{ secrets.RDS_USERNAME }}
# spring.datasource.password: ${{ secrets.RDS_PASSWORD }}
# secret.jwt-secret-key: ${{secrets.JWT_SECRET_KEY}}
# secret.jwt-login-secret-key: ${{secrets.JWT_SECRET_KEY_1}}
# secret.jwt-user-space-secret-key: ${{secrets.JWT_SECRET_KEY_2}}
# secret.jwt-expired-in: ${{secrets.JWT_EXPIRED_IN}}
# spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
- name: Set YML
run: |
echo "${{ secrets.APPLICATION_YML_DEV }}" > src/main/resources/application.yml
# (5) Gradle build (Test ์ ์ธ)
- name: Build with Gradle
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
arguments: clean build -x test
# (6) AWS ์ธ์ฆ (IAM ์ฌ์ฉ์ Access Key, Secret Key ํ์ฉ)
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# (7) ๋น๋ ๊ฒฐ๊ณผ๋ฌผ์ S3 ๋ฒํท์ ์
๋ก๋
- name: Upload to AWS S3
run: |
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
# (6) S3 ๋ฒํท์ ์๋ ํ์ผ์ ๋์์ผ๋ก CodeDeploy ์คํ
- name: Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip
dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0