Skip to content

Commit

Permalink
Merge pull request #5 from Leets-Official/4-CI-CD
Browse files Browse the repository at this point in the history
  • Loading branch information
leejuae authored Jul 16, 2024
2 parents 451dce6 + b96b043 commit 99f4809
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Commitato Dev Server CI/CD Workflows

on:
push:
branches: [ "develop" ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read

steps:
- name: ๋ธŒ๋žœ์น˜ ์ฒดํฌ์•„์›ƒ
uses: actions/checkout@v4

- name: JDK 17 ์„ค์ •
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}
- name: Gradle ๋นŒ๋“œ
run: ./gradlew build

- name: ๋นŒ๋“œ ๊ฒฐ๊ณผ ์••์ถ•
run: zip -qq -r $GITHUB_SHA.zip .

- name: AWS ์ ‘๊ทผ ์„ค์ •
uses: aws-actions/configure-aws-credentials@v2
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: S3๋กœ ์—…๋กœ๋“œ
run: aws s3 cp --region ${{ secrets.AWS_REGION }} ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME }}/${{ secrets.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip

- name: CodeDeploy๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ EC2์— ๋ฐฐํฌ
run: |
aws deploy create-deployment \
--application-name springboot-developer \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=${{ secrets.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip
15 changes: 15 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/enhance
permissions:
- object: /home/ubuntu/enhance/
owner: ubuntu
group: ubuntu
hooks:
AfterInstall:
- location: scripts/after-deploy.sh
timeout: 60
runas: ubuntu
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ dependencies {

// Database ์—ฐ๊ฒฐ
implementation 'com.h2database:h2:2.1.210' // ๊ฐœ๋ฐœ ๋ฐ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ H2 ์ธ๋ฉ”๋ชจ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค

// AWS
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.1.0")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store'
}

tasks.named('test') {
Expand Down
22 changes: 22 additions & 0 deletions scripts/after-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

REPOSITORY=/home/ubuntu/commitato-BE
cd $REPOSITORY

APP_NAME=commitato-BE
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1)
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME

CURRENT_PID=$(pgrep -f $APP_NAME)

if [ -z $CURRENT_PID ]
then
echo "> ์ข…๋ฃŒํ•  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—†์Šต๋‹ˆ๋‹ค."
else
echo "ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ข…๋ฃŒ: $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> Deploy - $JAR_PATH "
nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &
19 changes: 19 additions & 0 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
config:
activate:
on-profile: dev
import: aws-parameterstore:/Dev/DBServer/MySQL/
datasource:
url: ${DB_PATH}
username: ${DB_USER}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: create
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
properties:
hibernate:
format_sql: true
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
profiles:
default: dev

0 comments on commit 99f4809

Please sign in to comment.