diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..7e0422b7 --- /dev/null +++ b/.github/workflows/cd.yml @@ -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/redis-github-action@1.7.0 + with: + redis-version: ${{ matrix.redis-version }} + redis-port: ${{ secrets.TEST_REDIS_PORT }} + + - name: Set up MySQL + uses: samin/mysql-action@v1.3 + 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c1e59f5..88828b98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitmodules b/.gitmodules index 0fe3b2f4..3f0020f4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 + diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..6e80bddf --- /dev/null +++ b/appspec.yml @@ -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 diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 00000000..2316d7d7 --- /dev/null +++ b/scripts/deploy.sh @@ -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 λ°°ν¬ν•©λ‹ˆλ‹€!" +nohup java -jar -Dspring.profiles.active=dev build/libs/$JAR_NAME > $REPOSITORY/nohup.out 2>&1 & diff --git a/sidepeek_backend_secret b/sidepeek_backend_secret index 4a3a6e5b..6d0ac71b 160000 --- a/sidepeek_backend_secret +++ b/sidepeek_backend_secret @@ -1 +1 @@ -Subproject commit 4a3a6e5b021a3f94ec8f15103693fcb6d8e43948 +Subproject commit 6d0ac71b154c1957dd64b452995149db2db97757 diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 00000000..fceca3d5 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,3 @@ +spring: + config: + import: /home/ubuntu/app/sidepeek_backend_secret/application-dev.yml diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 1ba63baa..7f3e2e14 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -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 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index eb6e22de..00000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,13 +0,0 @@ -spring: - config: - import: file:./sidepeek_backend_secret/application.yml - profiles: - active: local - servlet: - multipart: - max-file-size: 100MB - max-request-size: 100MB - -server: - servlet: - context-path: /api/v1 diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 49ee2015..1a2b5162 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -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