Skip to content

Commit

Permalink
Revert "Revert "Github Actions 배포 workflow 테스트""
Browse files Browse the repository at this point in the history
  • Loading branch information
yujamint authored Jun 1, 2024
1 parent 79a47d4 commit 672e385
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 286 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: deploy

on:
pull_request:
branches: [dev, test/cd]
types: [closed]

env:
AWS_ACCESS_KEY: ${{ secrets.STG_AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.STG_AWS_SECRET_KEY }}
AWS_S3_BUCKET_NAME: ${{ secrets.STG_AWS_S3_BUCKET_NAME }}
AWS_S3_REGION: ${{ secrets.STG_AWS_S3_REGION }}

jobs:
deploy:

runs-on: ubuntu-latest
if: github.event.pull_request.merged

steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: JDK 11 설치
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '11'
cache: 'gradle'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: 빌드
run: ./gradlew build -x test

- name: zip 파일 생성
run: zip -r ./qtudy.zip .
shell: bash

- name: AWS credentials 설정
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: $AWS_ACCESS_KEY
aws-secret-access-key: $AWS_SECRET_KEY
aws-region: $AWS_S3_REGION

- name: S3에 zip 파일 업로드
run: aws s3 cp \
--region $AWS_S3_REGION \
./qtudy.zip s3://$AWS_S3_BUCKET_NAME/qtudy.zip

- name: Code Deploy 통해 배포
run: aws deploy create-deployment \
--application-name $AWS_CODE_DEPLOY_APPLICATION_NAME \
--file-exists-behavior OVERWRITE \
--deployment-config-name QtudyStageCodeDeploy \
--deployment-group-name QtudyStageCodeDeploy-DepGrp \
--s3-location bucket=$AWS_S3_BUCKET_NAME, bundleType=zip, key=qtudy.zip \
--region $AWS_S3_REGION




38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: run test

on:
pull_request:
branches: [main, dev]
types: [opened, synchronize, reopened]

permissions:
checks: write
pull-requests: write

jobs:
test:

runs-on: ubuntu-latest

steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: JDK 11 설치
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '11'
cache: 'gradle'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: Test 실행
run: ./gradlew clean test

- name: Test 결과를 PR에 코멘트로 등록
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'
21 changes: 21 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu
overwrite: yes

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

hooks:
BeforeInstall:
- location: scripts/shutdown-prev-application.sh
runas: ubuntu

AfterInstall:
- location: scripts/build-and-run-new-application.sh
runas: ubuntu
5 changes: 5 additions & 0 deletions scripts/build-and-run-new-application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROJECT_PATH=/home/ubuntu/Qtudy-BE
BUILD_PATH=$PROJECT_PATH/build/libs
BUILD_JAR=$BUILD_PATH/Qtudy-server-0.0.1-SNAPSHOT.jar

nohup java -jar $BUILD_JAR --spring.profiles.active=stage &
7 changes: 7 additions & 0 deletions scripts/shutdown-prev-application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
JAVA_PID=`sudo lsof -i :8080 -t`
if [ -z $JAVA_PID ]
then echo "실행되고 있는 애플리케이션이 없습니다."
else
sudo kill -9 $JAVA_PID
echo "기존에 실행되고 있던 애플리케이션을 종료했습니다."
fi
220 changes: 0 additions & 220 deletions src/test/java/com/app/gpt/GPTResponseFormatTest.java

This file was deleted.

Loading

0 comments on commit 672e385

Please sign in to comment.