Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/wsb0722/recordary_pc
Browse files Browse the repository at this point in the history
  • Loading branch information
jueun275 committed Apr 9, 2020
2 parents 5bb64dd + 549c6b0 commit 8bea483
Show file tree
Hide file tree
Showing 25 changed files with 345 additions and 124 deletions.
23 changes: 16 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: java

before_install:
- chmod +x gradlew

jdk:
- openjdk8

Expand All @@ -11,18 +8,30 @@ branches:
- master
- try-ci

env:
- TRAVIS_NODE_VERSION="lts/*"

# Travis CI 서버의 Home
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.gradle'

script: "./gradlew clean build"
before_install:
- chmod +x gradlew
- nvm install --lts
- nvm use stable

script: "./gradlew -x clean build"

before_deploy:
- zip -r recordary_pc *
- mkdir -p deploy
- mv recordary_pc.zip deploy/recordary_pc.zip
- mkdir -p before-deploy
- cp scripts/*.sh before-deploy/
- cp appspec.yml before-deploy/
- cp build/libs/*.jar before-deploy/
- cd before-deploy && zip -r before-deploy *
- cd ../ && mkdir -p deploy
- mv before-deploy/before-deploy.zip deploy/recordary_pc.zip

deploy:
- provider: s3
Expand Down
26 changes: 24 additions & 2 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,27 @@ version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/app/step2/zip/
overwrite: yes
destination: /home/ec2-user/app/step3/zip/
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ec2-user
group: ec2-user

hooks:
AfterInstall:
- location: stop.sh
timeout: 60
runas: ec2-user

ApplicationStart:
- location: start.sh
timeout: 60
runas: ec2-user

ValidateService:
- location: health.sh
timeout: 60
runas: ec2-user
29 changes: 9 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.moowork.node'

group 'com.fairy_pitt'
version '1.0-SNAPSHOT'
version '1.0.1-SNAPSHOT-' + new Date().format("yyyyMMddHHmmss")

mainClassName = 'com.fairy_pitt.recordary.RecordaryApplication'
sourceCompatibility = 1.8

repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.projectlombok:lombok')
implementation('org.springframework.boot:spring-boot-configuration-processor')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
Expand All @@ -59,34 +61,21 @@ dependencies {

def webappDir = "$projectDir/frontend"

node {
version = '12.16.1'
download=true
workDir = file("${project.buildDir}/nodejs")
npmWorkDir=file("${project.buildDir}/npm")
}

task appNpmInstall(type: NpmTask) {
workingDir = file("${webappDir}")
args = ['run-script', 'build']
args = ['install']
}

task yarnBuild(type: YarnTask) {
task npmBuild(type: NpmTask) {
workingDir = file("${webappDir}")
args = ['build']
args = ['run-script', 'build']
}

task copyWebApp(type: Copy) {
from 'frontend/build'
into 'build/resources/main/static/.'
}

task copyHtmlApp(type: Copy) {
from 'build/resources/main/static/index.html'
into 'build/resources/main/templates/.'
}

yarnBuild.dependsOn appNpmInstall
yarnBuild.dependsOn yarnBuild
compileJava.dependsOn copyWebApp
compileJava.dependsOn copyHtmlApp
npmBuild.dependsOn("appNpmInstall")
copyWebApp.dependsOn("npmBuild")
compileJava.dependsOn("copyWebApp")
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -169,4 +169,4 @@ if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down Expand Up @@ -81,4 +81,4 @@ exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ echo "> $JAR_NAME 실행"

nohup java -jar \
-Dspring.config.location=classpath:/application.yml,classpath:/application-real.yml,/home/ec2-user/app/application-real-db.yml \
-Dspring.profiles.active-real \
-Dspring.profiles.active=real \
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
39 changes: 39 additions & 0 deletions scripts/health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSPATH=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh
source ${ABSDIR}/switch.sh

IDLE_PORT=$(find_idle_port)

echo "> Health Check Start!"
echo "> IDLE_PORT: $IDLE_PORT"
echo "> curl -s http://localhost:$IDLE_PORT/profile "
sleep 10

for RETRY_COUNT in {1..10}
do
RESPONSE=$(curl -s http://localhost:${IDLE_PORT}/profile)
UP_COUNT=$(echo ${RESPONSE} | grep 'real' | wc -l)

if [ ${UP_COUNT} -ge 1 ]
then # $up_count >= 1 ("real" 문자열이 있는지 검증)
echo "> Health check 성공"
switch_proxy
break
else
echo "> Health check의 응답을 알 수 없거나 혹은 실행 상태가 아닙니다."
echo "> Health check: ${RESPONSE}"
fi

if [ ${RETRY_COUNT} -eq 10 ]
then
echo "> Health check 실패"
echo "> 엔진엑스에 연결하지 않고 배포를 종료합니다."
exit 1
fi

echo "> Health check 연결 실패. 재시도..."
sleep 10
done
34 changes: 34 additions & 0 deletions scripts/profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# 쉬고 있는 profile
function find_idle_profile() {
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost/profile)

if [ ${RESPONSE_CODE} -ge 400 ]
then
CURRENT_PROFILE=real2
else
CURRENT_PROFILE=$(curl -s http://localhost/profile)
fi

if [ ${CURRENT_PROFILE} == real1 ]
then
IDLE_PROFILE=real2
else
IDLE_PROFILE=real1
fi

echo "${IDLE_PROFILE}"
}

#쉬고 있는 profile의 port
function find_idle_port() {
IDLE_PROFILE=$(find_idle_profile)

if [ ${IDLE_PROFILE} == real1 ]
then
echo "8081"
else
echo "8082"
fi
}
32 changes: 32 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSDIR=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh

REPOSITORY=/home/ec2-user/app/step3
PROJECT_NAME=recordary_pc

echo "> Build 파일 복사"
echo "> cp $REPOSITORY/zip/*.jar $REPOSITORY/"

cp $REPOSITORY/zip/*.jar $REPOSITORY/

echo "> 새 애플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1)

echo "> JAR NAME: $JAR_NAME"

echo "> $JAR_NAME 에 실행권한 추가"

chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"

IDLE_PROFILE=$(find_idle_profile)

echo "> $JAR_NAME 를 profile=$IDLE_PROFILE 로 실행합니다."
nohup java -jar \
-Dspring.config.location=classpath:/application.yml,classpath:/application-$IDLE_PROFILE.yml,/home/ec2-user/app/application-real-db.yml \
-Dspring.profiles.active=$IDLE_PROFILE \
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
19 changes: 19 additions & 0 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSDIR=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh

IDLE_PORT=$(find_idle_port)

echo "> $IDLE_PORT 에서 구동 중인 애플리케이션 pid 확인"
IDLE_PID=$(lsof -ti tcp:${IDLE_PORT})

if [ -z ${IDLE_PID} ]
then
echo "> 현재 구동 중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $IDLE_PID"
kill -15 ${IDLE_PID}
sleep 5
fi
16 changes: 16 additions & 0 deletions scripts/switch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

ABSPATH=$(readlink -f $0)
ABSDIR=$(dirname $ABSPATH)
source ${ABSDIR}/profile.sh

function switch_proxy() {
IDLE_PORT=$(find_idle_port)

echo "> 전환할 Port: $IDLE_PORT"
echo "> Port 전환"
echo "set \$service_url http://127.0.0.1:${IDLE_PORT};" | sudo tee /etc/nginx/conf.d/service_url.inc

echo "> 엔진엑스 Reload"
sudo service nginx reload
}
3 changes: 1 addition & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rootProject.name = 'recordary'

rootProject.name = 'recordary_pc'
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.fairy_pitt.recordary.common.entity;

import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.List;

@Data
@NoArgsConstructor
@Entity
@Table(name = "COMMENT_TB")
public class CommentEntity extends BaseTimeEntity{
Expand All @@ -27,6 +31,18 @@ public class CommentEntity extends BaseTimeEntity{
@JoinColumn(name = "COMMENT_ORIGIN_FK")
private CommentEntity commentOriginFK;

@Column(name = "COMMENT_EX")
@Type(type = "text")
private String commentEx;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "commentOriginFK")
private List<CommentEntity> applyGroups;
private List<CommentEntity> commentOriginList;

@Builder
public CommentEntity(String commentEx, UserEntity commentUserFK, PostEntity commentPostFK, CommentEntity commentOriginFK){
this.commentEx = commentEx;
this.commentUserFK = commentUserFK;
this.commentPostFK = commentPostFK;
this.commentOriginFK = commentOriginFK;
}
}
Loading

0 comments on commit 8bea483

Please sign in to comment.