Skip to content

Commit

Permalink
[ADD] #67 CircleCI 및 AWS 배포 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cbinarycastle committed Jan 26, 2019
1 parent 9e4c4fe commit 5487025
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
87 changes: 87 additions & 0 deletions circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
settings: &settings
docker:
- image: circleci/openjdk:8-jdk
working_directory: ~/yellowcard-api
environment:
JVM_OPTS: -Xmx3200m
TERM: dumb

version: 2.1
commands:
prepare-steps:
steps:
- run:
name: Add Permission
command: chmod +x ./gradlew
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Download Dependencies
command: ./gradlew dependencies
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}
jobs:
test:
<<: *settings
steps:
- checkout
- prepare-steps
- run:
name: Run Tests
command: ./gradlew test
- store_artifacts:
path: build/reports/tests/test
- store_test_results:
path: build/test-results/test
build:
<<: *settings
steps:
- checkout
- prepare-steps
- run:
name: Build
command: ./gradlew build -x test
- store_artifacts:
path: build/libs
- persist_to_workspace:
root: ~/yellowcard-api/target
paths:
- build/libs/yellowcard-api-*.jar
deploy:
<<: *settings
steps:
- attach_workspace:
at: ~/yellowcard-api/target
- add_ssh_keys:
fingerprints:
- "2b:7a:75:0b:9d:f0:8c:11:ed:3c:7c:31:db:b8:e7:33"
- run:
name: Stop App
command: ssh -o StrictHostKeyChecking=no 52.78.221.147 '~/web/deploy.sh stop'
- run:
name: Copy App
command: scp -o ~/yellowcard-api/target/depromeet-4th-final-0.0.1.jar 52.78.221.147:~/web
- run:
name: Start App
command: ssh -o 52.78.221.147 '~/web/deploy.sh start'
workflows:
version: 2
build-deploy:
jobs:
- test
- build:
requires:
- test
filters:
branches:
only:
- develop
- feature/*
- deploy:
requires:
- build
42 changes: 42 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# FIELD
PROFILE_NAME="production"
PROJECT_NAME="yellowcard-api"

NEW_JAR_FULL_PATH="/home/ec2-user/web/${PROJECT_NAME}-0.0.1.jar"
JAR_FULL_PATH="/home/ec2-user/web/${PROJECT_NAME}.jar"
PID_FULL_PATH="/home/ec2-user/web/${PROJECT_NAME}.pid"

JAVA_OPTS="-server --spring.profiles.active=${PROFILE_NAME}"

# COMMAND (OPTION)
case $1 in
start)
echo "Starting $PROJECT_NAME ..."
if [ -f ${PID_FULL_PATH} ]; then
echo "$PROJECT_NAME is already running ..."
else
if [ -f ${NEW_JAR_FULL_PATH} ]; then
chmod +x ${NEW_JAR_FULL_PATH}
rm ${JAR_FULL_PATH}
mv ${NEW_JAR_FULL_PATH} ${JAR_FULL_PATH}
fi

# java -jar ${JAR_FULL_PATH} ${JAVA_OPTS}
nohup java -jar ${JAR_FULL_PATH} ${JAVA_OPTS} /tmp 2>> /dev/null >> /dev/null & echo $! > ${PID_FULL_PATH}
echo "$PROJECT_NAME started ..."
fi
;;
stop)
if [ -f ${PID_FULL_PATH} ]; then
PID=$(cat ${PID_FULL_PATH});
echo "$PROJECT_NAME stopping ..."
kill ${PID};
echo "$PROJECT_NAME stopped ..."
rm ${PID_FULL_PATH}
else
echo "$PROJECT_NAME is not running ..."
fi
;;
esac

0 comments on commit 5487025

Please sign in to comment.