Merge pull request #443 from beyond-sw-camp/refactor/production #135
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Backend Workflows | |
on: | |
push: | |
branches: | |
- main # mainμΌλ‘ pushνλ©΄ workflow μ€ν | |
paths: | |
- 'SCM/backend/**' | |
pull_request: | |
types: [ opened, reopened, synchronize ] # Pull Requestκ° μ΄λ¦¬κ±°λ, λ€μ μ΄λ¦¬κ±°λ, λκΈ°νλ λ νΈλ¦¬κ±°λ©λλ€. | |
branches: | |
- main # mainμΌλ‘ prνλ©΄ workflow μ€ν | |
jobs: | |
CI: | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest # μ΅μ Ubuntu νκ²½ | |
permissions: | |
contents: read # contents read κΆνμ λΆμ¬ | |
steps: | |
- uses: actions/checkout@v4 # λ ν¬μ§ν 리 μ½λλ₯Ό 체ν¬μμ [v4λΌκ³ λ²μ μ§μ μ v4λ‘ μμνλ μ΅μ λ¦΄λ¦¬μ¦ λ²μ μ μ¬μ© (μ νν λ²μ κΈ°μ μ ν΄λΉ λ¦΄λ¦¬μ¦ λ²μ λ§ μ¬μ©)] | |
# JDK 17 κ°λ° νκ²½ μ€μ | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle λ²μ 8.11 μ€μ | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
gradle-version: "8.11" | |
# gradlew μ€ν κΆν λΆμ¬ | |
- name: Grant execute permission for Gradle Wrapper | |
run: chmod +x ./gradlew | |
working-directory: ./SCM/backend | |
# envsubst λꡬ μ€μΉ | |
- name: Install envsubst | |
# gettext ν¨ν€μ§λ₯Ό μ€μΉνμ¬ envsubst λͺ λ Ήμ μ¬μ© κ°λ₯νκ² ν©λλ€. | |
run: sudo apt-get install -y gettext | |
# application.yml ν νλ¦Ώ μμ± | |
- name: Create application.yml.template | |
run: | | |
mkdir -p SCM/backend/src/main/resources | |
cat > SCM/backend/src/main/resources/application.yml.template <<EOL | |
server: | |
port: 5000 | |
servlet: | |
encoding: | |
charset: UTF-8 | |
spring: | |
application: | |
name: orderBridge | |
datasource: | |
url: jdbc:log4jdbc:mariadb://\${RDS_HOSTNAME}:\${RDS_PORT}/\${RDS_DB_NAME}?serverTimezone=Asia/Seoul | |
username: \${RDS_USERNAME} | |
password: \${RDS_PASSWORD} | |
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | |
hikari: | |
idle-timeout: 300000 | |
max-lifetime: 1800000 | |
pool-name: HikariPool-1 | |
jpa: | |
show-sql: true | |
hibernate: | |
ddl-auto: none | |
naming: | |
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy | |
properties: | |
hibernate: | |
format_sql: true | |
hibernate.dialect: org.hibernate.dialect.MariaDBDialect | |
data: | |
redis: | |
host: \${REDIS_HOST} | |
port: \${REDIS_PORT} | |
username: \${REDIS_HOSTNAME} | |
password: \${REDIS_PASSWORD} | |
springdoc: | |
packages-to-scan: error.pirate.backend | |
default-consumes-media-type: application/json;charset=UTF-8 | |
default-produces-media-type: application/json;charset=UTF-8 | |
swagger-ui: | |
path: /swagger | |
operations-sorter: method | |
doc-expansion: none | |
logging: | |
file: | |
path: /var/app/current | |
level: | |
root: info | |
org.springframework.web: info | |
com.zaxxer.hikari: debug | |
log4jdbc.log4j2: error | |
jdbc.sqlonly: info | |
jdbc.resultsettable: info | |
jdbc.connection: info | |
mybatis: | |
configuration: | |
map-underscore-to-camel-case: true | |
mapper-locations: mappers/**/*.xml | |
jwt: | |
secretKey: \${JWT_SECRET_KEY} | |
access: | |
expiration: 3600000 # 1μκ° | |
header: Authorization | |
refresh: | |
expiration: 1209600000 # 2μ£Ό | |
header: Refresh-Token | |
frontend: \${FRONTEND_URL} | |
gemini: | |
baseurl: \${GEMINI_URL} | |
googleai: | |
api: | |
key: \${GEMINI_KEY} | |
cloud: | |
aws: | |
s3: | |
bucket: \${AWS_S3_BUCKET} | |
credentials: | |
access-key: \${AWS_ACCESS_KEY_ID} | |
secret-key: \${AWS_SECRET_ACCESS_KEY} | |
region: | |
static: \${AWS_REGION} | |
auto: false | |
stack: | |
auto: false | |
EOL | |
# ν νλ¦Ώ νμΌμ νκ²½ λ³μλ₯Ό λμ νμ¬ application.yml μμ± | |
- name: Set Yaml | |
run: | | |
envsubst < SCM/backend/src/main/resources/application.yml.template > SCM/backend/src/main/resources/application.yml | |
echo "Generated application.yml:" | |
cat SCM/backend/src/main/resources/application.yml | |
env: | |
RDS_HOSTNAME: ${{ secrets.RDS_HOSTNAME }} | |
RDS_PORT: ${{ secrets.RDS_PORT }} | |
RDS_DB_NAME: ${{ secrets.RDS_DB_NAME }} | |
RDS_USERNAME: ${{ secrets.RDS_USERNAME }} | |
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }} | |
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }} | |
REDIS_HOST: ${{ secrets.REDIS_HOST }} | |
REDIS_HOSTNAME: ${{ secrets.REDIS_HOSTNAME }} | |
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }} | |
REDIS_PORT: ${{ secrets.REDIS_PORT }} | |
GEMINI_URL: ${{ secrets.GEMINI_URL }} | |
GEMINI_KEY: ${{ secrets.GEMINI_KEY }} | |
FRONTEND_URL: ${{ secrets.FRONTEND_URL }} | |
AWS_S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
# backend λΉλ | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build -x test # ν μ€νΈ μ½λ μ μΈ λΉλ | |
working-directory: ./SCM/backend | |
# backend Test Code μ€ν | |
#- name: Run Test | |
# run: ./gradlew test | |
# working-directory: ./SCM/backend | |
# continue-on-error: true | |
# Test κ²°κ³Ό νμΌμ μμΉ΄μ΄λΈλ‘ μ μ₯νμ¬ Github Actionsμμ νμΈν μ μλλ‘ νλ€. | |
#- name: Archive Test Results | |
# if: always() # μ΄ μ λ¨κ³μ μ±κ³΅ μ¬λΆμ κ΄κ³μμ΄ νμ μ€ν | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: test-results | |
# path: | | |
# ./SCM/backend/build/test-results/test | |
# ./SCM/backend/build/reports/tests/test | |
CD: | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest # μ΅μ Ubuntu νκ²½ | |
permissions: | |
contents: read # contents read κΆνμ λΆμ¬ | |
steps: | |
- uses: actions/checkout@v4 # λ ν¬μ§ν 리 μ½λλ₯Ό 체ν¬μμ [v4λΌκ³ λ²μ μ§μ μ v4λ‘ μμνλ μ΅μ λ¦΄λ¦¬μ¦ λ²μ μ μ¬μ© (μ νν λ²μ κΈ°μ μ ν΄λΉ λ¦΄λ¦¬μ¦ λ²μ λ§ μ¬μ©)] | |
# JDK 17 κ°λ° νκ²½ μ€μ | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle λ²μ 8.11 μ€μ | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
gradle-version: "8.11" | |
# gradlew μ€ν κΆν λΆμ¬ | |
- name: Grant execute permission for Gradle Wrapper | |
run: chmod +x ./gradlew | |
working-directory: ./SCM/backend | |
# envsubst λꡬ μ€μΉ | |
- name: Install envsubst | |
# gettext ν¨ν€μ§λ₯Ό μ€μΉνμ¬ envsubst λͺ λ Ήμ μ¬μ© κ°λ₯νκ² ν©λλ€. | |
run: sudo apt-get install -y gettext | |
# application.yml ν νλ¦Ώ μμ± | |
- name: Create application.yml.template | |
run: | | |
mkdir -p SCM/backend/src/main/resources | |
cat > SCM/backend/src/main/resources/application.yml.template <<EOL | |
server: | |
port: 5000 | |
servlet: | |
encoding: | |
charset: UTF-8 | |
spring: | |
application: | |
name: orderBridge | |
datasource: | |
url: jdbc:log4jdbc:mariadb://\${RDS_HOSTNAME}:\${RDS_PORT}/\${RDS_DB_NAME}?serverTimezone=Asia/Seoul | |
username: \${RDS_USERNAME} | |
password: \${RDS_PASSWORD} | |
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy | |
hikari: | |
idle-timeout: 300000 | |
max-lifetime: 1800000 | |
pool-name: HikariPool-1 | |
jpa: | |
show-sql: true | |
hibernate: | |
ddl-auto: none | |
naming: | |
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy | |
properties: | |
hibernate: | |
format_sql: true | |
hibernate.dialect: org.hibernate.dialect.MariaDBDialect | |
data: | |
redis: | |
host: \${REDIS_HOST} | |
port: \${REDIS_PORT} | |
username: \${REDIS_HOSTNAME} | |
password: \${REDIS_PASSWORD} | |
springdoc: | |
packages-to-scan: error.pirate.backend | |
default-consumes-media-type: application/json;charset=UTF-8 | |
default-produces-media-type: application/json;charset=UTF-8 | |
swagger-ui: | |
path: /swagger | |
operations-sorter: method | |
doc-expansion: none | |
logging: | |
file: | |
path: /var/app/current | |
level: | |
root: info | |
org.springframework.web: info | |
com.zaxxer.hikari: debug | |
log4jdbc.log4j2: error | |
jdbc.sqlonly: info | |
jdbc.resultsettable: info | |
jdbc.connection: info | |
mybatis: | |
configuration: | |
map-underscore-to-camel-case: true | |
mapper-locations: mappers/**/*.xml | |
jwt: | |
secretKey: \${JWT_SECRET_KEY} | |
access: | |
expiration: 3600000 # 1μκ° | |
header: Authorization | |
refresh: | |
expiration: 1209600000 # 2μ£Ό | |
header: Refresh-Token | |
frontend: \${FRONTEND_URL} | |
gemini: | |
baseurl: \${GEMINI_URL} | |
googleai: | |
api: | |
key: \${GEMINI_KEY} | |
cloud: | |
aws: | |
s3: | |
bucket: \${AWS_S3_BUCKET} | |
credentials: | |
access-key: \${AWS_ACCESS_KEY_ID} | |
secret-key: \${AWS_SECRET_ACCESS_KEY} | |
region: | |
static: \${AWS_REGION} | |
auto: false | |
stack: | |
auto: false | |
EOL | |
# ν νλ¦Ώ νμΌμ νκ²½ λ³μλ₯Ό λμ νμ¬ application.yml μμ± | |
- name: Set Yaml | |
run: | | |
envsubst < SCM/backend/src/main/resources/application.yml.template > SCM/backend/src/main/resources/application.yml | |
echo "Generated application.yml:" | |
cat SCM/backend/src/main/resources/application.yml | |
env: | |
RDS_HOSTNAME: ${{ secrets.RDS_HOSTNAME }} | |
RDS_PORT: ${{ secrets.RDS_PORT }} | |
RDS_DB_NAME: ${{ secrets.RDS_DB_NAME }} | |
RDS_USERNAME: ${{ secrets.RDS_USERNAME }} | |
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }} | |
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }} | |
REDIS_HOST: ${{ secrets.REDIS_HOST }} | |
REDIS_HOSTNAME: ${{ secrets.REDIS_HOSTNAME }} | |
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }} | |
REDIS_PORT: ${{ secrets.REDIS_PORT }} | |
GEMINI_URL: ${{ secrets.GEMINI_URL }} | |
GEMINI_KEY: ${{ secrets.GEMINI_KEY }} | |
FRONTEND_URL: ${{ secrets.FRONTEND_URL }} | |
AWS_S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
# backend λΉλ | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build -x test # ν μ€νΈ μ½λ μ μΈ λΉλ | |
working-directory: ./SCM/backend | |
# backend Test Code μ€ν | |
#- name: Run Test | |
# run: ./gradlew test | |
# working-directory: ./SCM/backend | |
# continue-on-error: true | |
# Test κ²°κ³Ό νμΌμ μμΉ΄μ΄λΈλ‘ μ μ₯νμ¬ Github Actionsμμ νμΈν μ μλλ‘ νλ€. | |
#- name: Archive Test Results | |
# if: always() # μ΄ μ λ¨κ³μ μ±κ³΅ μ¬λΆμ κ΄κ³μμ΄ νμ μ€ν | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: test-results | |
# path: | | |
# ./SCM/backend/build/test-results/test | |
# ./SCM/backend/build/reports/tests/test | |
- name: Get current time | |
uses: 1466587594/get-current-time@v2 | |
id: current-time | |
with: | |
format: YYYY-MM-DD HH:mm:ss | |
utcOffset: "+09:00" | |
- name: Show Current Time | |
run: echo "currentTime=${{steps.current-time.outputs.formattedTime}}" | |
shell: bash | |
- name: Generate backend deployment package | |
run: | | |
mkdir -p deploy | |
cp SCM/backend/build/libs/*.jar deploy/application.jar | |
cp Procfile_back deploy/Procfile | |
cp -r SCM/backend/.ebextensions deploy/.ebextensions | |
cp -r .platform deploy/.platform | |
cd deploy && zip -r deploy.zip . | |
- name: Beanstalk backend Deploy | |
uses: einaregilsson/beanstalk-deploy@v22 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
application_name: ${{ secrets.AWS_ELASTIC_BEANSTALK_BACKEND_APPLICATION }} | |
environment_name: ${{ secrets.AWS_ELASTIC_BEANSTALK_BACKEND_ENV }} | |
version_label: github-action-backend_${{steps.current-time.outputs.formattedTime}} | |
region: ${{ secrets.AWS_REGION }} | |
deployment_package: deploy/deploy.zip | |
use_existing_version_if_available: false | |
wait_for_deployment: true | |
wait_for_environment_recovery: 300 | |
# νλ‘μ νΈμ μμ‘΄μ± κ·Έλνλ₯Ό μμ± λ° μ μΆνμ¬ Githubμμ μκ°μ μΌλ‘ κ΄λ¦¬νλλ‘ νλ€. | |
dependency-submission: | |
runs-on: ubuntu-latest | |
# μ°κΈ° κΆνμ μ£Όμ΄ μμ‘΄μ± λ°μ΄ν°λ₯Ό Githubμ μ μΆν μ μλ€. | |
permissions: | |
contents: write | |
steps: | |
# μ½λ 체ν¬μμ | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Generate and submit dependency graph | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
gradle-version: "8.11" |