Skip to content

Chore/#5 Dockerfile 및 CI/CD 파이프라인 구성#11

Merged
Hooneybadger merged 7 commits into
devfrom
chore/#5_init_cicd
May 23, 2025
Merged

Chore/#5 Dockerfile 및 CI/CD 파이프라인 구성#11
Hooneybadger merged 7 commits into
devfrom
chore/#5_init_cicd

Conversation

@Hooneybadger
Copy link
Copy Markdown
Collaborator

#️⃣ 연관된 이슈

📝 작업 내용

수동 배포는 반복적이고 시간이 많이 소요되는 작업이므로 생산성을 위해 자동화 할 필요가 있다. 이를 위해 CI를 수행하는 test-pipeline.yml과 CD를 수행하는 ec2-pipeline.yml를 제작했다.

test-pipeline.yml

on:
  push:
    branches: [ dev ]
  pull_request:
    branches: [ dev ]

트리거를 통해 dev 브랜치로의 Push 나 PR이 발생할 시 동작

- name: Set up JDK 17
  uses: actions/setup-java@v4
  with:
    java-version: '17'
    distribution: 'temurin'

actions/setup-java@v4로 JAVA 17, Temurin 배포판을 설정

- name: Set up secret.yml
  run: |
    cd ./src/main/resources
    touch ./application-secret.yml
    echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml
    ls -a .

Git secrets에서 환경 변수를 가져와 application-secret의 파일을 만들어 ./src/main/resoucres 경로에 저장

- name: Grant execute permission for Gradle
  run: chmod +x ./gradlew

Graddle Wrapper 권한을 부여

- name: PR and PUSH Test Verification
  run: ./gradlew test

테스트를 시작

ec2-pipeline.yml

test-pipeline의 내용과 동일한 부분은 생략

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

트리거를 통해 main 브랜치로의 Push 나 PR이 발생할 시 동작

env:
  APP_NAME : Matzipbook
  BUILD_NAME : Matzipbook

env 환경변수 설정. 민감정보는 secrets에 저장하며 자주 사용 될 정보만 env에 저장

- name: Run asciidoc mv static/html
  run: |
    ./gradlew asciidoctor
    mkdir -p src/main/resources/static/docs
    cp -r build/docs/asciidoc/* src/main/resources/static/docs/
  • asciidoctor Gradle TASK를 실행
  • buildle/docs/asciidoc/ 디렉토리에문서 생성
  • static/docs로 복사

- name: Docker push image
  run: |
    docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
    docker build --platform linux/arm64/v8 -t app .
    docker tag app ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest
    docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest
  • GitHub Secrets 환경 변수로 Docker 로그인
  • ARM 아키텍쳐도 호환가능하도록 빌드
  • latest 태그를 달아서 Docker Hub로 도커 이미지 push

- name: AWS deploy
  uses: appleboy/ssh-action@master
  with:
    host: ${{ secrets.EC2_HOST }}
    username: ${{ secrets.EC2_USER }}
    key: ${{ secrets.EC2_KEY }}

    script: |
      sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest

      sudo docker stop Matzipbook || true
      sudo docker rm Matzipbook || true

      sudo docker run -v /home/${{ secrets.EC2_USER }}/elk/logs:/logs -d --log-driver=syslog -p 443:8080 --name Matzipbook --network Matzipbook-network -e spring.profiles.active=release -e TZ=Asia/Seoul ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest

      sudo docker container prune -f

      sudo docker image prune -f

      sudo docker images ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }} -q | awk 'NR>1' | xargs -r sudo docker rmi -f
  • GitHub Secrets 환경 변수로 EC2 SSH 접속
  • Docker Hub에서 도커 이미지 pull
  • 기존에 실행 중인 컨테이너가 있다면 중지하고 제거
  • newtork = Matzipbook-newtork, profile = release로 새 이미지로 컨테이너 실행
  • 사용하지 않는 이미지 정리

applicaion.yml 컨벤션

배포 자동화와 원만한 협업을 위해 Applicaion.yml 컨벤션을 다음과 같이 한다

applicaion.yml

spring:
  profiles:
    active: dev

상황에 따라 적용할 프로파일을 선택

applicaion-secret.yml

kakao-api-key: ~
jwt-secret: ~

코드 복사하여 GITHUB > Settings > Actions secrets and variables > Actions 에서 적용

applicaion-release.yml

datasource:
  url: jdbc:mysql://localhost:3306.....
  username: root
  password: qwer1234

EC2 배포 시 필요한 정보 관리

@Hooneybadger Hooneybadger added 🔗 chore 빌드 관련 이슈 🌏 server 서버 관련 이슈 labels May 23, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Hooneybadger Hooneybadger changed the title Chore/#5 init cicd Chore/#5 Dockerfile 및 CI/CD 파이프라인 구성 May 23, 2025
@Hooneybadger Hooneybadger self-assigned this May 23, 2025
@Hooneybadger Hooneybadger merged commit 08e236b into dev May 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔗 chore 빌드 관련 이슈 🌏 server 서버 관련 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant