-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#181] 기존 배포 방식을 Docker로 Migration #182
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e942b5
[FIX] docker 배포방식으로 변경
JungYoonShin bfdcc38
[CHORE] health check를 위한 actuator 의존성 추가
JungYoonShin 7dde358
[CHORE] Dockerfile 생성
JungYoonShin 5e1a164
[CHORE] docker compose 파일 생성
JungYoonShin 1927ce3
[CHORE] develop.yml 수정
JungYoonShin be4054b
[CHORE] develop.yml 수정
JungYoonShin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,81 @@ | ||
| name: Spring Boot & Gradle CI/CD | ||
| name: CICD-MAIN | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| branches: [ "main" ] | ||
|
|
||
|
|
||
| # 본인이 설정한 값을 여기서 채워넣습니다. | ||
| # 리전, 버킷 이름, CodeDeploy 앱 이름, CodeDeploy 배포 그룹 이름 | ||
| env: | ||
| AWS_REGION: ap-northeast-2 | ||
| S3_BUCKET_NAME: favoriteplace-bucket | ||
| CODE_DEPLOY_APPLICATION_NAME: favorite-place-app | ||
| CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: favorite-deploy-group | ||
|
|
||
| permissions: | ||
| contents: read | ||
| ECR_REGISTRY: 859043921675.dkr.ecr.ap-northeast-2.amazonaws.com | ||
| ECR_REPOSITORY: moemoe | ||
| IMAGE_TAG: ${{ github.sha }} | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy | ||
| ci: | ||
| runs-on: ubuntu-latest | ||
| environment: production | ||
|
|
||
| steps: | ||
| # (1) 기본 체크아웃 | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
| - name: Checkout source code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '17' | ||
|
|
||
| - name: Gradle Cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: | | ||
| ~/.gradle/caches | ||
| ~/.gradle/wrapper | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-gradle- | ||
|
|
||
| # (2) JDK 11 세팅 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '17' | ||
| - name: Create application.yml | ||
| run: | | ||
| mkdir -p ./src/main/resources | ||
| touch ./application.yml | ||
| echo "${{ secrets.YML }}" > ./src/main/resources/application.yml | ||
| cat ./src/main/resources/application.yml | ||
|
|
||
| # (3) Gradle build (Test 제외) | ||
| - name: Grant execute permission for gradlew | ||
| run: chmod +x ./gradlew | ||
| - name: Build with Gradle | ||
| run: | | ||
| chmod +x ./gradlew | ||
| ./gradlew clean build -x test --parallel --build-cache --daemon | ||
|
|
||
| - name: Build with Gradle | ||
| uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee | ||
| with: | ||
| arguments: clean build -x test | ||
| - name: 🔐 Configure AWS credentials | ||
| 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: ${{ env.AWS_REGION }} | ||
|
|
||
| # (4) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용) | ||
| - name: Configure AWS credentials | ||
| 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: ${{ env.AWS_REGION }} | ||
| - name: 🔑 Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| # (5) 빌드 결과물을 S3 버킷에 업로드 | ||
| - name: Upload to AWS S3 | ||
| run: | | ||
| aws deploy push \ | ||
| --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
| --ignore-hidden-files \ | ||
| --s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | ||
| --source . | ||
| - name: 🐳 Build, tag, and push Docker image | ||
| run: | | ||
| docker build -t $ECR_REPOSITORY:$IMAGE_TAG . | ||
| docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
|
|
||
| cd: | ||
| needs: ci | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: 🚀 Deploy via SSH | ||
| uses: appleboy/ssh-action@master | ||
| with: | ||
| host: ${{ secrets.SERVER_IP }} | ||
| username: ${{ secrets.SERVER_USER }} | ||
| key: ${{ secrets.SERVER_KEY }} | ||
| script: | | ||
| cd ~ | ||
| ./deploy.sh ${{ github.sha }} | ||
| docker image prune -f | ||
|
|
||
| # (6) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행 | ||
| - name: Deploy to AWS EC2 from S3 | ||
| run: | | ||
| aws deploy create-deployment \ | ||
| --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
| --deployment-config-name CodeDeployDefault.AllAtOnce \ | ||
| --deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | ||
| --s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip \ | ||
| --file-exists-behavior OVERWRITE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| FROM eclipse-temurin:17-jdk-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY build/libs/favoriteplace-0.0.1-SNAPSHOT.jar ./app.jar | ||
|
|
||
| RUN apk add --no-cache tzdata && \ | ||
| cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \ | ||
| echo "Asia/Seoul" > /etc/timezone && \ | ||
| apk del tzdata | ||
|
|
||
| CMD ["java", "-Duser.timezone=Asia/Seoul", "-jar", "-Dspring.profiles.active=prod", "app.jar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| services: | ||
| redis: | ||
| container_name: redis | ||
| image: redis:alpine | ||
| ports: | ||
| - "6379:6379" | ||
| networks: | ||
| - app-network | ||
|
|
||
| blue: | ||
| container_name: moemoe-blue | ||
| image: 859043921675.dkr.ecr.ap-northeast-2.amazonaws.com/moemoe:latest | ||
| expose: | ||
| - 8080 | ||
| ports: | ||
| - "8081:8080" | ||
| environment: | ||
| - TZ=Asia/Seoul | ||
| depends_on: | ||
| - redis | ||
| networks: | ||
| - app-network | ||
|
|
||
| green: | ||
|
JungYoonShin marked this conversation as resolved.
|
||
| container_name: moemoe-green | ||
| image: 859043921675.dkr.ecr.ap-northeast-2.amazonaws.com/moemoe:latest | ||
| expose: | ||
| - 8080 | ||
| ports: | ||
| - "8082:8080" | ||
| environment: | ||
| - TZ=Asia/Seoul | ||
| depends_on: | ||
| - redis | ||
| networks: | ||
| - app-network | ||
|
|
||
| networks: | ||
| app-network: | ||
| driver: bridge | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.