-
Notifications
You must be signed in to change notification settings - Fork 0
[CI/CD] CI/CD 전략 변경 #5
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
Changes from all commits
b84ae5c
0d3f0c2
a842c21
830e423
7952741
46bcf62
674848a
6fce1e8
31c31a7
be8cf8f
e4ddd1e
b7c2f5a
7c76efd
237583f
46c831b
0fc0529
26bb79e
0d899f0
35c5ea7
5a66841
c1282b6
1e5ba90
5dd3cf3
2792b76
f2af454
5d8550a
103744e
69c66b2
8e23ed6
43a328c
43b92f7
bc2dcc0
b1d5faa
49bc789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: CI/CD Build, Upload, Deploy (Dev) | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ dev ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-and-upload: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: 21 | ||
| cache: gradle | ||
|
|
||
| - name: Create application-secret.yml | ||
| run: | | ||
| mkdir -p src/main/resources | ||
| echo "${{ secrets.DEV_SECRET_YML }}" > src/main/resources/application-secret.yml | ||
|
|
||
| - name: Create firebase-adminsdk-account.json | ||
| run: | | ||
| mkdir -p src/main/resources/firebase | ||
| echo '${{ secrets.FIREBASE_ADMINSDK_ACCOUNT_KEY }}' \ | ||
| > src/main/resources/firebase/firebase-adminsdk-account.json | ||
|
|
||
| - name: Gradle build | ||
| run: | | ||
| chmod +x ./gradlew | ||
| ./gradlew clean build | ||
|
|
||
| - name: Find executable jar | ||
| id: jar | ||
| run: | | ||
| JAR_PATH=$(find build/libs -name "*.jar" ! -name "*plain.jar" | head -n 1) | ||
| if [ -z "$JAR_PATH" ]; then | ||
| echo "No executable jar found"; exit 1; | ||
| fi | ||
| echo "jar_path=$JAR_PATH" >> "$GITHUB_OUTPUT" | ||
| echo "jar_name=$(basename "$JAR_PATH")" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Create deploy bundle | ||
| id: bundle | ||
| run: | | ||
| mkdir -p deploy | ||
| cp "${{ steps.jar.outputs.jar_path }}" deploy/ | ||
|
|
||
| cp infra/appspec.yml deploy/ 2>/dev/null || true | ||
| cp infra/*.sh deploy/ 2>/dev/null || true | ||
|
|
||
| cd deploy | ||
| ZIP_NAME="festabook-$(date +'%Y%m%d%H%M%S')-${GITHUB_SHA::7}.zip" | ||
| zip -r "$ZIP_NAME" . | ||
| echo "zip_name=$ZIP_NAME" >> "$GITHUB_OUTPUT" | ||
| echo "zip_path=$(pwd)/$ZIP_NAME" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-region: ${{ secrets.AWS_DEPLOY_REGION }} | ||
| role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} | ||
| role-session-name: festabook-ci-cd | ||
|
|
||
| - name: Upload artifact to S3 | ||
| run: | | ||
| aws s3 cp "${{ steps.bundle.outputs.zip_path }}" \ | ||
| "s3://${{ secrets.S3_ARTIFACT_BUCKET }}/dev/builds/${{ steps.bundle.outputs.zip_name }}" | ||
|
|
||
| - name: Trigger CodeDeploy deployment | ||
| run: | | ||
| aws deploy create-deployment \ | ||
| --application-name "${{ secrets.CODEDEPLOY_APP_NAME }}" \ | ||
| --deployment-group-name "${{ secrets.CODEDEPLOY_DEPLOYMENT_GROUP_DEV }}" \ | ||
| --s3-location bucket=${{ secrets.S3_ARTIFACT_BUCKET }},bundleType=zip,key=dev/builds/${{ steps.bundle.outputs.zip_name }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: CI/CD Build, Upload, Deploy (Prod) | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ prod ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-and-upload: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| id-token: write | ||
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: 21 | ||
| cache: gradle | ||
|
|
||
| - name: Create application-secret.yml | ||
| run: | | ||
| mkdir -p src/main/resources | ||
| echo "${{ secrets.PROD_SECRET_YML }}" > src/main/resources/application-secret.yml | ||
|
|
||
| - name: Create firebase-adminsdk-account.json | ||
| run: | | ||
| mkdir -p src/main/resources/firebase | ||
| echo '${{ secrets.FIREBASE_ADMINSDK_ACCOUNT_KEY }}' \ | ||
| > src/main/resources/firebase/firebase-adminsdk-account.json | ||
|
|
||
| - name: Gradle build | ||
| run: | | ||
| chmod +x ./gradlew | ||
| ./gradlew clean build | ||
|
|
||
| - name: Find executable jar | ||
| id: jar | ||
| run: | | ||
| JAR_PATH=$(find build/libs -name "*.jar" ! -name "*plain.jar" | head -n 1) | ||
| if [ -z "$JAR_PATH" ]; then | ||
| echo "No executable jar found"; exit 1; | ||
| fi | ||
| echo "jar_path=$JAR_PATH" >> "$GITHUB_OUTPUT" | ||
| echo "jar_name=$(basename "$JAR_PATH")" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Create deploy bundle | ||
| id: bundle | ||
| run: | | ||
| mkdir -p deploy | ||
| cp "${{ steps.jar.outputs.jar_path }}" deploy/ | ||
|
|
||
| cp infra/appspec.yml deploy/ 2>/dev/null || true | ||
| cp infra/*.sh deploy/ 2>/dev/null || true | ||
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cd deploy | ||
| ZIP_NAME="festabook-$(date +'%Y%m%d%H%M%S')-${GITHUB_SHA::7}.zip" | ||
| zip -r "$ZIP_NAME" . | ||
| echo "zip_name=$ZIP_NAME" >> "$GITHUB_OUTPUT" | ||
| echo "zip_path=$(pwd)/$ZIP_NAME" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-region: ${{ secrets.AWS_DEPLOY_REGION }} | ||
| role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} | ||
| role-session-name: festabook-ci-cd | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. role-session-name에
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 이 부분에 대해서 고민을 해봤는데, 다만, 두 권한이 모두 일치해서 하나의 OIDC만 만들었는데 후유는 어떻게 생각해요?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어느 배포 작업에서 권한을 부여했는지 별칭을 나타내는 것으로 생각하고 role-session-name에 어떤 상황에서 role-session-name을 확인할지 떠오르지 않네요. |
||
|
|
||
| - name: Upload artifact to S3 | ||
| run: | | ||
| aws s3 cp "${{ steps.bundle.outputs.zip_path }}" \ | ||
| "s3://${{ secrets.S3_ARTIFACT_BUCKET }}/prod/builds/${{ steps.bundle.outputs.zip_name }}" | ||
|
|
||
| - name: Trigger CodeDeploy deployment | ||
| run: | | ||
| aws deploy create-deployment \ | ||
| --application-name "${{ secrets.CODEDEPLOY_APP_NAME }}" \ | ||
| --deployment-group-name "${{ secrets.CODEDEPLOY_DEPLOYMENT_GROUP_PROD }}" \ | ||
| --s3-location bucket=${{ secrets.S3_ARTIFACT_BUCKET }},bundleType=zip,key=prod/builds/${{ steps.bundle.outputs.zip_name }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| name: Backend CI Test | ||
| name: CI Test | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 브랜치 변경해야합니다. |
||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - backend-prod | ||
| - backend-dev | ||
| - prod | ||
| - dev | ||
|
|
||
| jobs: | ||
| Run-PR-Test: | ||
|
|
@@ -30,27 +30,26 @@ jobs: | |
| path: | | ||
| ~/.gradle/caches | ||
| ~/.gradle/wrapper | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('backend/**/*.gradle*', 'backend/**/gradle-wrapper.properties') }} | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-gradle- | ||
|
|
||
| - name: Grant execute permission for gradlew | ||
| run: chmod +x backend/gradlew | ||
| run: chmod +x ./gradlew | ||
|
|
||
| - name: Create firebase-adminsdk-account.json | ||
| run: | | ||
| mkdir -p backend/src/main/resources/firebase | ||
| echo "${{ secrets.FIREBASE_ADMINSDK_ACCOUNT_KEY }}" > backend/src/main/resources/firebase/firebase-adminsdk-account.json | ||
| mkdir -p src/main/resources/firebase | ||
| echo "${{ secrets.FIREBASE_ADMINSDK_ACCOUNT_KEY }}" > src/main/resources/firebase/firebase-adminsdk-account.json | ||
|
|
||
| - name: Run Gradle Test | ||
| run: ./gradlew clean test | ||
| working-directory: backend | ||
|
|
||
| - name: Publish Unit Test Results | ||
| if: always() | ||
| uses: EnricoMi/publish-unit-test-result-action@v2 | ||
| with: | ||
| files: backend/build/test-results/test/TEST-*.xml | ||
| files: build/test-results/test/TEST-*.xml | ||
| check_name: '테스트 결과 🛠️' | ||
| check_run_annotations: 'none' | ||
| comment_mode: 'off' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,26 @@ | ||
| version: 0.0 | ||
| os: linux | ||
|
|
||
| files: | ||
| - source: backend/infra/output/ | ||
| - source: / | ||
| destination: /home/ubuntu/app | ||
|
|
||
| hooks: | ||
| ApplicationStop: | ||
| - location: stop.sh | ||
| timeout: 60 | ||
| runas: ubuntu | ||
|
|
||
| BeforeInstall: | ||
| - location: clean.sh | ||
| timeout: 60 | ||
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ApplicationStart: | ||
| - location: backend/infra/output/start.sh | ||
| - location: start.sh | ||
| timeout: 60 | ||
| runas: ubuntu | ||
|
|
||
| ValidateService: | ||
| - location: validate.sh | ||
| timeout: 90 | ||
| runas: ubuntu | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "> Cleaning old jar files" | ||
| rm -rf /home/ubuntu/app/* | ||
Uh oh!
There was an error while loading. Please reload this page.