Skip to content

Commit

Permalink
Merge pull request #1261 from innovationacademy-kr/dev
Browse files Browse the repository at this point in the history
dev to main
  • Loading branch information
sichoi42 authored Jul 21, 2023
2 parents 2d253a7 + 0203ea0 commit 35803ed
Show file tree
Hide file tree
Showing 530 changed files with 22,622 additions and 38,177 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/back-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI/CD
on:
push:
paths:
- "backend/**"
workflow_dispatch:

jobs:
backend-CI:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:10.3.39
env:
MYSQL_DATABASE: test_db
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
MYSQL_ROOT_PASSWORD: test_password
ports:
- 3310:3306
options: >-
--health-cmd "mysqladmin status -h 127.0.0.1 -P 3306 -u root -ptest_password"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 체크아웃
uses: actions/checkout@v2

- name: DB에 샘플 데이터 삽입
run: >-
mysql --force
--host="127.0.0.1"
--port="3310"
--database="test_db"
--user="test_user"
--password="test_password"
< "backend/src/test/resources/database/spring_test_db.sql"
- name: JDK 11 설정
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "corretto"

- name: Application YML 생성
run: |
mkdir -p backend/src/main/resources
echo "${{ secrets.APPLICATION_PROD_YML }}" | base64 --decode > backend/src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > backend/src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_AUTH_YML }}" | base64 --decode > backend/src/main/resources/application-auth.yml
echo "${{ secrets.APPLICATION_MAIL_YML }}" | base64 --decode > backend/src/main/resources/application-mail.yml
- name: Gradle 빌드
run: |
cd backend
mkdir -p build/generated-snippets/
chmod +x gradlew
./gradlew build
shell: bash

- name: Configure AWS credentials
if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main' }}
uses: aws-actions/configure-aws-credentials@v1
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: Dev S3에 업로드
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
mkdir -p before-deploy
cp backend/build/libs/cabinet-*.jar before-deploy/
cp scripts/deploy-dev.sh before-deploy/deploy.sh
cp appspec.yml before-deploy/
cp Dockerfile.dev before-deploy/Dockerfile
cd before-deploy && zip -r before-deploy *
cd ../ && mkdir -p deploy
mv before-deploy/before-deploy.zip deploy/deploy.zip
aws s3 cp deploy/deploy.zip s3://${{ secrets.AWS_S3_DEV_BUCKET_NAME }}/deploy.zip
aws deploy create-deployment \
--application-name ${{ secrets.AWS_CODEDEPLOY_DEV_APP_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_DEV_GROUP_NAME }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ secrets.AWS_S3_DEV_BUCKET_NAME }},bundleType=zip,key=deploy.zip
- name: Main S3에 업로드
if: ${{ github.ref == 'refs/heads/main' }}
run: |
mkdir -p before-deploy
cp backend/build/libs/cabinet-*.jar before-deploy/
cp scripts/deploy-main.sh before-deploy/deploy.sh
cp appspec.yml before-deploy/
cp Dockerfile.main before-deploy/Dockerfile
cd before-deploy && zip -r before-deploy *
cd ../ && mkdir -p deploy
mv before-deploy/before-deploy.zip deploy/deploy.zip
aws s3 cp deploy/deploy.zip s3://${{ secrets.AWS_S3_MAIN_BUCKET_NAME }}/deploy.zip
aws deploy create-deployment \
--application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ secrets.AWS_S3_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip
135 changes: 0 additions & 135 deletions .github/workflows/back-cicd.yaml

This file was deleted.

67 changes: 38 additions & 29 deletions .github/workflows/front-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,45 @@ jobs:
source $HOME/.bash_profile
echo "해당 리포지토리로 이동"
cd $HOME/42cabi_dev
echo "리포지토리 pull"
git pull origin dev
echo "앱 빌드"
cd $HOME/42cabi_dev/backend
npm run build:fe
npm run deploy:dev
npm run invalidate:dev
frontend-CD-main:
name: deploy-main
runs-on: ubuntu-latest
needs: [frontend-CI]
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: 리모트 쉘 접속
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_MAIN }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY_NEW }}
port: ${{ secrets.PORT }}
script_stop: true
script: |
source $HOME/.bash_profile
echo "해당 리포지토리로 이동"
cd $HOME/42cabi_main
echo "리포지토리 pull"
git pull origin main
echo "앱 빌드"
cd $HOME/42cabi_main/backend
npm run build:fe
npm run deploy:main
npm run invalidate:main
cd frontend
npm install
npm run build
mkdir -p dist/src/assets
cp -r src/assets/images dist/src/assets
echo "S3 배포"
aws s3 sync ./dist s3://dev.cabi --profile=CABI
echo "CloudFront 캐시 무효화"
aws cloudfront create-invalidation --profile=CABI --distribution-id EWPTW52IH5L5C --paths '/*'
# frontend-CD-main:
# name: deploy-main
# runs-on: ubuntu-latest
# needs: [frontend-CI]
# if: ${{ github.ref == 'refs/heads/main' }}
# steps:
# - name: 리모트 쉘 접속
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST_MAIN }}
# username: ${{ secrets.USERNAME }}
# key: ${{ secrets.KEY_NEW }}
# port: ${{ secrets.PORT }}
# script_stop: true
# script: |
# source $HOME/.bash_profile
# echo "해당 리포지토리로 이동"
# cd $HOME/42cabi_main
# echo "리포지토리 pull"
# git pull origin main
# echo "앱 빌드"
# cd $HOME/42cabi_main/backend
# npm run build:fe
# npm run deploy:main
# npm run invalidate:main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ aria_log.*
ib_logfile*
ibdata*
ibtmp*
*nohup.out
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 42Cabi.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
5 changes: 5 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM amazoncorretto:11

COPY cabinet-0.0.1-SNAPSHOT.jar .

CMD java -jar -Dspring.profiles.active=dev cabinet-0.0.1-SNAPSHOT.jar
5 changes: 5 additions & 0 deletions Dockerfile.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM amazoncorretto:11

COPY cabinet-0.0.1-SNAPSHOT.jar .

CMD java -jar -Dspring.profiles.active=main cabinet-0.0.1-SNAPSHOT.jar
18 changes: 18 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/deploy/zip/
overwrite: yes

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

hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ec2-user
Loading

0 comments on commit 35803ed

Please sign in to comment.