Skip to content

Commit

Permalink
feat: ci/cd 구현 및 프로퍼티파일정의
Browse files Browse the repository at this point in the history
  • Loading branch information
EunChanNam committed Oct 19, 2023
1 parent 472d8d8 commit 0295f93
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 11 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CD

on:
push:
branches:
- main

jobs:
build_and_deploy:
name: Deploy CD
runs-on: ubuntu-latest

steps:
- name: 레포지토리를 가져온다
uses: actions/checkout@v4

- name: 자바 17을 설치한다
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Gradle 명령 실행을 위해 권한을 부여한다
run: chmod +x gradlew

- name: Gradle 로 build 를 수행한다
run: ./gradlew clean build

- name: Docker Hub 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: 환경변수 파일 생성
run: echo "${{ secrets.APPLICATION_ENV }}" > ./.env

- name: 환경변수 파일을 서버로 전송한다
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.PORT }}
source: "./.env"
target: "./"


- name: Docker image build
run: docker build -t ${{ secrets.DOCKER_NAME }}/devops_study:latest .

- name: docker Hub 푸쉬
run: docker push ${{ secrets.DOCKER_NAME }}/devops_study:latest

- name: Deploy with push
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.PORT }}
# 이미 멈춰있어서 발생하는 예외를 방지하기 위해 || true 설정
script: |
sudo docker stop devops_study || true
sudo docker container prune -f
sudo docker pull ${{ secrets.DOCKER_NAME }}/devops_study:latest
sudo docker run -d --log-driver=syslog --env-file .env \
-p 8080:9000 --name devops_study \
${{ secrets.DOCKER_NAME }}/devops_study:latest
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
pull_request:
branches:
- main
- develop

jobs:
test:
name: CI
runs-on: ubuntu-latest

permissions:
checks: write
pull-requests: write

steps:
- name: 레포지토리를 가져온다
uses: actions/checkout@v4

- name: 자바 17을 설치한다
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Gradle 명령 실행을 위해 권한을 부여한다
run: chmod +x gradlew

- name: Gradle 로 테스트를 실행한다
run: ./gradlew test

- name: 테스트 결과를 PR 에 반영한다
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'

# 테스트 코드를 새로 작성하면 재설정
# - name: Add coverage to PR
# id: jacoco
# if: always()
# uses: madrapps/[email protected]
# with:
# paths: ${{ github.workspace }}/build/jacoco/jacocoTestReports.xml
# token: ${{ secrets.GIT_TOKEN }}
# title: Code Coverage
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
HELP.md
.gradle
.DS_Store
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### private ###
.idea
.DS_Store

### application.yml ###
application-dev.yml
/src/main/generated/

### sql ###
**/src/main/resources/sql/
Expand All @@ -34,7 +29,7 @@ bin/
### IntelliJ IDEA ###
.idea
*.iws
*.iml경
*.iml
*.ipr
out/
!**/src/main/**/out/
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {

//DB
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'

//네이버 클라우드
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Expand Down
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
83 changes: 83 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
server:
port: 8080

spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test_db;MODE=MySQL;
username: sa
password:
h2:
console:
enabled: true

jpa:
hibernate:
ddl-auto: create

properties:
hibernate:
default_batch_fetch_size: 100
show_sql: true
format_sql: true

open-in-view: false

mail:
host: smtp.gmail.com
port: 587
username: ${MAIL}
password: ${MAIL_PW}
protocol: smtp
properties:
mail:
smtp:
starttls:
enable: true
auth: true

servlet:
multipart:
max-file-size: 10MB

# 포인트 메일 수신자 #
mail:
point-mail-receiver: ${POINT_MAIL}

# Flask domain #
flask:
domain: ${FLASK_DOMAIN}

# 서버 런시 발생하는 에러 로그 방지
logging:
level:
com:
amazonaws:
util:
EC2MetadataUtils: error

#p6spy 설정
decorator:
datasource:
p6spy:
enable-logging: true

#JWT key
jwt:
secret-key: ${JWT_SECRET_KEY}
access-token-validity: ${ACCESS_TOKEN_VALIDITY}
refresh-token-validity: ${REFRESH_TOKEN_VALIDITY}

# 네이버 클라우드 오브젝트 스토리지
cloud:
aws:
credentials:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
stack:
auto: false
region:
static: ap-northeast-2
s3:
endpoint: https://kr.object.ncloudstorage.com
bucket: ${BUCKET_NAME}
82 changes: 79 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
spring:
profiles:
default: dev
server:
port: 8080

spring:
datasource:
url: jdbc:mysql://localhost:3306/wish_hair_db
username: root
password: 1234!
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: create

properties:
hibernate:
default_batch_fetch_size: 100
show_sql: true
format_sql: true

open-in-view: false

mail:
host: smtp.gmail.com
port: 587
username: ${MAIL} # [email protected]
password: ${MAIL_PW} # qkvpxhpgyuywcbgh
protocol: smtp
properties:
mail:
smtp:
starttls:
enable: true
auth: true

servlet:
multipart:
max-file-size: 10MB

# 포인트 메일 수신자 #
mail:
point-mail-receiver: ${POINT_MAIL} #[email protected]

# Flask domain #
flask:
domain: ${FLASK_DOMAIN}

# 서버 런시 발생하는 에러 로그 방지
logging:
level:
com:
amazonaws:
util:
EC2MetadataUtils: error

#p6spy 설정
decorator:
datasource:
p6spy:
enable-logging: true

#JWT key
jwt:
secret-key: ${JWT_SECRET_KEY} # wishhairOiJIUzI1NiIvLoAR5cCI6IkpXSCJ9.eyJzdWIiOiIiLCLoCP1lIjoiSm9obiBEV9UiLCJpYXBCusE1MTYyMzkwMjJ9.163aevla8s7d6f987qweahqwculaoxce80k1i2o387tg
access-token-validity: ${ACCESS_TOKEN_VALIDITY} # 1800000
refresh-token-validity: ${REFRESH_TOKEN_VALIDITY} # 259200000

# 네이버 클라우드 오브젝트 스토리지
cloud:
aws:
credentials:
access-key: ${S3_ACCESS_KEY} # N3JCSJUtgse4alKEaOqX
secret-key: ${S3_SECRET_KEY} #rRamLrfUV8v6ZziJFEN4CVLjE9rl4kCBnEOLje5f
stack:
auto: false
region:
static: ap-northeast-2
s3:
endpoint: https://kr.object.ncloudstorage.com
bucket: ${BUCKET_NAME} # wswh-storage

0 comments on commit 0295f93

Please sign in to comment.