Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INFRA] CD 구축 #197

Merged
merged 18 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: gohigher-backend-dev-cd

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Checkout source code
uses: actions/checkout@v4

- name: Set Encryption Key
run: |
echo "encryption-key: $ENCRYPTION_KEY" >> $RESOURCE_PATH
env:
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
RESOURCE_PATH: './bootstrap/src/main/resources/application.yml'

- name: Change gradlew permission
run: sudo chmod 755 gradlew

- name: Make Jar File
run: ./gradlew bootJar

- name: Make Zip File
run: zip -qq -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 }}
aws-secret-access-key: ${{ secrets.AWS_ACCESS_SECRET_KEY }}
aws-region: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://gohigher-backend-cd-bucket/backend/$GITHUB_SHA.zip

- name: Code Deploy To EC2 instance
run: aws deploy create-deployment
--application-name gohigher-backend-cd
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name gohigher-backend-cd
--s3-location bucket=gohigher-backend-cd-bucket,bundleType=zip,key=backend/$GITHUB_SHA.zip
17 changes: 17 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/gohigher

permissions:
- object: /home/ubuntu/gohigher/
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
30 changes: 30 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DEV_PORT=8080
TEST_PORT=8081

DEV_PROFILE="dev"
TEST_PROFILE="test"

DEPLOY_FOLDER="gohigher"
JAR_FILE="bootstrap-0.0.1-SNAPSHOT.jar"

TEST_FOLDER="test"
DEV_LOG_FILE="gohigher.out"
TEST_LOG_FILE="gohigher-test.out"

cd ~
cd ${DEPLOY_FOLDER}

echo "> kill spring port"
fuser -k -n tcp ${DEV_PORT}
fuser -k -n tcp ${TEST_PORT}

echo "> execute dev jar"
cd bootstrap/build/libs
nohup java -jar -Dspring.profiles.active=${DEV_PROFILE} ${JAR_FILE} 1>${DEV_LOG_FILE} 2>&1 &
sleep 3

echo "> execute test jar"
mkdir ${TEST_FOLDER}
sudo mv ${JAR_FILE} ${TEST_FOLDER}/
cd ${TEST_FOLDER}
nohup java -jar -Dspring.profiles.active=${TEST_PROFILE} -Dserver.port=${TEST_PORT} ${JAR_FILE} 1>${TEST_LOG_FILE} 2>&1 &