Skip to content

Commit

Permalink
Merge pull request #4 from youKeon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
youKeon authored Aug 20, 2023
2 parents 094b9de + 8224e91 commit 473b3d9
Show file tree
Hide file tree
Showing 74 changed files with 2,845 additions and 228 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 파일명을 .env로 변경 후 원하시는 비밀번호를 설정해 주세요
// Github에 노출되지 않게 ignore 처리 부탁드립니다!

DB_USERNAME=root
DB_ROOT_PASSWORD=
DB_DATABASE=psq
DB_HOST=mysql
47 changes: 47 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CD

on:
push:
branches: ["master"]

env:
S3_BUCKET_NAME: problemsolvingqueue
PROJECT_NAME: psq

jobs:
build:
name: CD
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'zulu'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build with Gradle
run: ./gradlew build
shell: bash

- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash

- 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: ${{ secrets.AWS_REGION }}

- name: Copy script
run: cp ./scripts/*.sh ./deploy

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
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:
push:
branches: ["dev"]
pull_request:
branches: ["dev"]

jobs:
backend-test:
permissions:
contents: read
checks: write
id-token: write
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: "temurin"

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: backend/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('backend/**/*') }}
restore-keys: ${{ runner.os }}-gradle-

- name: Grant Execute Permission For Gradlew
run: chmod +x backend/gradlew


- name: Test with Gradle
run: |
cd backend
./gradlew build --info
- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: Tests Result
path: "backend/build/test-results/**/*.xml"
reporter: java-junit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.DS_Store

backend/src/main/resources/application-local.yml

.env

.idea/
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/PSQ.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/google-java-format.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

8 changes: 8 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM openjdk:11-jre-slim-buster
VOLUME /tmp

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
RUN chmod +x /wait

COPY ./build/libs/solving-0.0.1-SNAPSHOT.jar app.jar
CMD /wait && java -jar /app.jar --spring.profiles.active=prod
23 changes: 23 additions & 0 deletions backend/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/app
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: scripts/stop.sh
timeout: 60
runas: ubuntu
ApplicationStart:
- location: scripts/start.sh
timeout: 60
runas: ubuntu
116 changes: 113 additions & 3 deletions backend/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
plugins {
id 'java'
id 'jacoco'
id 'org.springframework.boot' version '2.7.8'
id 'io.spring.dependency-management' version '1.1.2'

// QueryDSL
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

group = 'com.problem'
Expand All @@ -15,25 +19,131 @@ configurations {
compileOnly {
extendsFrom annotationProcessor
}
// QueryDSL
querydsl.extendsFrom compileClasspath
}

repositories {
mavenCentral()
}

dependencies {
// Spring-Boot
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// Batch
implementation 'org.springframework.boot:spring-boot-starter-batch'

// DB
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'

// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

// Lombok
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'

// QueryDSL
implementation "com.querydsl:querydsl-jpa:5.0.0"
implementation "com.querydsl:querydsl-apt:5.0.0"

// Slack
implementation("com.slack.api:bolt:1.18.0")
implementation("com.slack.api:bolt-servlet:1.18.0")
implementation("com.slack.api:bolt-jetty:1.18.0")

// Swagger
implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.batch:spring-batch-test'
runtimeOnly 'com.h2database:h2'
}

tasks.named('test') {
useJUnitPlatform()
finalizedBy 'jacocoTestReport'
}

// ==================== QueryDSL ==================== //
def querydslDir = "$buildDir/generated/querydsl"

querydsl {
jpa = true
querydslSourcesDir = querydslDir
}

sourceSets {
main.java.srcDir querydslDir
}

compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}

// ==================== Jacoco ==================== //

jacoco {
toolVersion = "0.8.7"
}

jacocoTestReport {
reports {
xml.required = true
csv.required = true
html.required = true
}
finalizedBy 'jacocoTestCoverageVerification'
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
"**/Q*",
'**/dto/**',
'**/exception/**',
'**/batch/**',
"**/*Application*",
"**/global/**"
])
}))
}
}

jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'

limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.80
}

limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.70
}

limit {
counter = 'METHOD'
value = 'COVEREDRATIO'
minimum = 0.60
}
excludes = [
'*.*Application',
'*.Q*',
'*.*Exception',
'*.dto.*',
'*.batch.*',
'*.global.*',
'*.BaseEntity',
]
}
}
}

24 changes: 24 additions & 0 deletions backend/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_JAR)
echo "> build 파일명: $JAR_NAME" >> /home/ubuntu/app/deploy.log

echo "> build 파일 복사" >> /home/ubuntu/app/deploy.log
DEPLOY_PATH=/home/ubuntu/app/action/
cp $BUILD_JAR $DEPLOY_PATH

echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/app/deploy.log
CURRENT_PID=$(pgrep -f $JAR_NAME)

if [ -z $CURRENT_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/app/deploy.log
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo "> DEPLOY_JAR 배포" >> /home/ubuntu/app/deploy.log
nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2>/home/ubuntu/app/deploy_err.log &
2 changes: 2 additions & 0 deletions backend/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
Loading

0 comments on commit 473b3d9

Please sign in to comment.