Skip to content

Merge pull request #444 from beyond-sw-camp/docs/리드미작성 #137

Merge pull request #444 from beyond-sw-camp/docs/리드미작성

Merge pull request #444 from beyond-sw-camp/docs/리드미작성 #137

Workflow file for this run

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"