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

CD 구축 #90

Merged
merged 18 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
66 changes: 66 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: SidePeek CD with Gradle

on:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [ latest ]

steps:
- name: Repository Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

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

- name: Set up Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}
redis-port: ${{ secrets.TEST_REDIS_PORT }}

- name: Set up MySQL
uses: samin/[email protected]
with:
mysql user: ${{ secrets.TEST_DB_USER }}
mysql password: ${{ secrets.TEST_DB_PASSWORD }}
mysql database: ${{ secrets.TEST_DB }}
host port: ${{ secrets.TEST_DB_PORT }}

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -Dspring.profiles.active=dev

- name: Make Zip File
run: zip -qq -r ./$GITHUB_SHA.zip .

- name: Configure AWS credentials
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: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME }}/deploy/$GITHUB_SHA.zip

- name: Deploy with AWS codeDeploy
run: aws deploy create-deployment
--application-name ${{ secrets.CODE_DEPLOY_APP_NAME }}
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{ secrets.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }}
--s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=deploy/$GITHUB_SHA.zip
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build
run: ./gradlew build -Dspring.profiles.active=local

- name: Test Jacoco Coverage Report
id: jacoco
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "sidepeek_backend_secret"]
path = sidepeek_backend_secret
url = https://github.com/side-peek/sidepeek_backend_secret.git
branch = dev
url = git@github.com:side-peek/sidepeek_backend_secret.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 요거는 문법이 따로 있는건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에는 HTTP로 서브모듈 연결(ex. https://XXX ) 했는데, EC2에서는 HTTP가 아니라 SSH로 연결을 해야되서 url만 변경한 것입니당!

[submodule "[submodule 디렉토리 경로]"]
path = [submodule 디렉토리 경로]
url = [submodule git repository 주소]
branch = [추적할 서브모듈 브랜치]

branch는 제가 실수로 서브모듈 브랜치가 아니라, 저희 개발 레포 브랜치를 적었어서 수정했습니당!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아아 ssh 였군요! 알려주셔서 감사합니당! :)


19 changes: 19 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.0
os: linux

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

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

hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
23 changes: 23 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

REPOSITORY=/home/ubuntu/app
echo "👀 [$REPOSITORY] 경로로 이동합니다."
cd $REPOSITORY

APP_NAME=sidepeek
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.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 "❌ 실행 중인 애플리케이션이 있어 이를 종료합니다. [PID = $CURRENT_PID]"
kill -15 "$CURRENT_PID"
sleep 5
fi

echo "👀 $JAR_PATH 배포합니다!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메시지가 귀엽군요,,👀

nohup java -jar -Dspring.profiles.active=dev build/libs/$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
2 changes: 1 addition & 1 deletion sidepeek_backend_secret
3 changes: 3 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
config:
import: /home/ubuntu/app/sidepeek_backend_secret/application-dev.yml
8 changes: 0 additions & 8 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
spring:
config:
import: file:./sidepeek_backend_secret/application-local.yml
jpa:
show-sql: true
open-in-view: false
hibernate:
ddl-auto: validate
flyway:
enabled: true
locations: classpath:db/migration, classpath:db/data
13 changes: 0 additions & 13 deletions src/main/resources/application.yml

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
spring:
config:
import: file:./sidepeek_backend_secret/application-test.yml
jpa:
show-sql: true
open-in-view: false
hibernate:
ddl-auto: validate
flyway:
enabled: true
Loading