Skip to content
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

๐ŸŒ Deploy - CICD Pipeline ๊ตฌ์ถ• #21

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

dongkyeomjang
Copy link
Collaborator

@dongkyeomjang dongkyeomjang commented Nov 18, 2024

Related issue ๐Ÿ› 

closed #20

์–ด๋–ค ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์—ˆ๋‚˜์š”?

  • ๐Ÿž BugFix Something isn't working
  • ๐Ÿ’ป CrossBrowsing Browser compatibility
  • ๐ŸŒ Deploy Deploy
  • ๐ŸŽจ Design Markup & styling
  • ๐Ÿ“ƒ Docs Documentation writing and editing (README.md, etc.)
  • โœจ Feature Feature
  • ๐Ÿ”จ Refactor Code refactoring
  • โš™๏ธ Setting Development environment setup
  • โœ… Test Test related (storybook, jest, etc.)

CheckPoint โœ…

PR์ด ๋‹ค์Œ ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•˜๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.

  • PR ์ปจ๋ฒค์…˜์— ๋งž๊ฒŒ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. (ํ•„์ˆ˜)
  • Docker Container ํ™˜๊ฒฝ์œผ๋กœ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ํ–ˆ์Šต๋‹ˆ๋‹ค.(๋ฒ„๊ทธ ์ˆ˜์ •/๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ). (ํ•„์ˆ˜)
  • Feature์˜ ๊ฒฝ์šฐ, API ๋ฌธ์„œ ์—…๋ฐ์ดํŠธ๋ฅผ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. (์„ ํƒ)
  • BugFix์˜ ๊ฒฝ์šฐ, ๋ฒ„๊ทธ์˜ ์›์ธ์„ ํŒŒ์•…ํ•˜์˜€์Šต๋‹ˆ๋‹ค. (์„ ํƒ)

Work Description โœ๏ธ

  • add dev-cicd.yml

Uncompleted Tasks ๐Ÿ˜…

N/A

To Reviewers ๐Ÿ“ข

Summary by CodeRabbit

  • New Features

    • Introduced a GitHub Actions workflow for Continuous Integration and Continuous Deployment of the web application.
  • Bug Fixes

    • Enhanced the .gitignore file to track the gradle-wrapper.jar and ignore specific IntelliJ IDEA and macOS files, improving project cleanliness.

@dongkyeomjang dongkyeomjang added ๐ŸŒ Deploy ๋ฐฐํฌ ๊ด€๋ จ dongkyeomjang assigned to dongkyeomjang labels Nov 18, 2024
@dongkyeomjang dongkyeomjang self-assigned this Nov 18, 2024
Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

A new GitHub Actions workflow file named dev-cicd.yml has been added to automate Continuous Integration (CI) and Continuous Deployment (CD) processes for a web application. This workflow is triggered on pull requests to the dev branch and includes steps for building the project and deploying it via Docker upon merging. Additionally, the .gitignore file has been updated to track specific Gradle wrapper files and to refine the list of ignored files, particularly related to IntelliJ IDEA and macOS.

Changes

File Path Change Summary
.github/workflows/dev-cicd.yml Introduced a new CI/CD workflow for the web application, including build and deployment steps.
.gitignore Added exceptions for gradle-wrapper.jar, included IntelliJ IDEA plugin files, and macOS .icloud files.

Assessment against linked issues

Objective Addressed Explanation
CICD Pipeline ๊ตฌ์ถ• (#20) โœ…

๐Ÿฐ In the meadow, we leap and play,
With CI/CD, we pave the way.
Gradle builds with a joyful cheer,
Deploying apps, we hold so dear.
IntelliJ's clutter, now out of sight,
Hop along, everything feels right! ๐ŸŒผ


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

โค๏ธ Share
๐Ÿชง 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

๐Ÿงน Outside diff range and nitpick comments (4)
.github/workflows/dev-cicd.yml (3)

3-9: Consider adding more PR event types for comprehensive coverage

The current configuration might miss important PR events. Consider adding these event types:

  • reopened: For handling reopened PRs
  • ready_for_review: For PRs coming out of draft state
 on:
   pull_request:
     branches: [ "dev" ]
     types:
       - opened
       - synchronize
       - closed
+      - reopened
+      - ready_for_review

1-93: Add security scanning step to the pipeline

Consider adding a security scanning step to identify vulnerabilities early in the pipeline.

Add this step before the Docker build:

- name: Run Trivy vulnerability scanner
  uses: aquasecurity/trivy-action@master
  with:
    image-ref: '${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}'
    format: 'table'
    exit-code: '1'
    ignore-unfixed: true
    vuln-type: 'os,library'
    severity: 'CRITICAL,HIGH'
๐Ÿงฐ Tools
๐Ÿช› yamllint

[error] 93-93: no new line character at the end of file

(new-line-at-end-of-file)


93-93: Add newline at end of file

Add a newline character at the end of the file to comply with YAML best practices and improve compatibility.

 docker run -d -p 8080:8080 --name api-server --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
+
๐Ÿงฐ Tools
๐Ÿช› yamllint

[error] 93-93: no new line character at the end of file

(new-line-at-end-of-file)

.gitignore (1)

208-209: LGTM! Essential change for CI/CD pipeline.

The explicit inclusion of gradle-wrapper.jar is crucial for the CI/CD pipeline implementation. This ensures that:

  1. Builds are reproducible across different environments
  2. CI/CD workflows can execute Gradle tasks without requiring Gradle to be pre-installed
  3. All developers and CI systems use the same Gradle version

This follows Gradle's best practices for version control.

For team members: The Gradle wrapper should always be committed to version control. If you need to update the wrapper version in the future, use:

./gradlew wrapper --gradle-version=<version>
๐Ÿ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between db3916c and c950ce3.

โ›” Files ignored due to path filters (1)
  • gradle/wrapper/gradle-wrapper.jar is excluded by !**/*.jar
๐Ÿ“’ Files selected for processing (2)
  • .github/workflows/dev-cicd.yml (1 hunks)
  • .gitignore (1 hunks)
๐Ÿงฐ Additional context used
๐Ÿช› yamllint
.github/workflows/dev-cicd.yml

[error] 93-93: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +48 to +50
- name: Build with Gradle
run: |
./gradlew clean build -x test
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ Potential issue

Skipping tests in the build process is risky

The -x test flag skips all tests, which could lead to quality issues. Consider:

  1. Running essential tests at minimum
  2. Using test categories to run critical tests only
 - name: Build with Gradle
   run: |
-    ./gradlew clean build -x test
+    ./gradlew clean build
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Build with Gradle
run: |
./gradlew clean build -x test
- name: Build with Gradle
run: |
./gradlew clean build

Comment on lines +38 to +41
- name: Set YML
run: |
echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > ./src/main/resources/application-dev.yml

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

Improve YAML file handling robustness

The current base64 decoding might be susceptible to newline issues. Consider using a more robust approach:

 - name: Set YML
   run: |
-    echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > ./src/main/resources/application-dev.yml
+    echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 -d | tr -d '\r' > ./src/main/resources/application-dev.yml
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Set YML
run: |
echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > ./src/main/resources/application-dev.yml
- name: Set YML
run: |
echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 -d | tr -d '\r' > ./src/main/resources/application-dev.yml

Comment on lines +64 to +71
- name: Build and push
if: github.event.pull_request.merged == true
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

Add version tagging for Docker images

Using only the latest tag makes rollbacks difficult and version tracking impossible.

 - name: Build and push
   if: github.event.pull_request.merged == true
   uses: docker/build-push-action@v4
   with:
     context: .
     file: ./Dockerfile
     push: true
-    tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
+    tags: |
+      ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest
+      ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ github.sha }}
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Build and push
if: github.event.pull_request.merged == true
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
- name: Build and push
if: github.event.pull_request.merged == true
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ github.sha }}

Comment on lines +89 to +93
script: |
docker stop api-server
docker rm api-server
docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
docker run -d -p 8080:8080 --name api-server --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

Improve deployment reliability and minimize downtime

The current deployment process has several areas for improvement:

  1. No health checks after deployment
  2. No rollback strategy
  3. Potential downtime during container replacement
 script: |
+  # Pull new image first to minimize downtime
+  docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
+  
+  # Backup current container name if exists
+  CURRENT_CONTAINER=$(docker ps -q -f name=api-server)
+  
+  # Start new container on different port
+  docker run -d -p 8081:8080 --name api-server-new --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
+  
+  # Wait for container to be healthy
+  sleep 10
+  if ! curl -f http://localhost:8081/health; then
+    echo "New container failed health check"
+    docker stop api-server-new
+    docker rm api-server-new
+    exit 1
+  fi
+  
+  # Stop and remove old container
   docker stop api-server
   docker rm api-server
-  docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
-  docker run -d -p 8080:8080 --name api-server --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
+  
+  # Rename new container
+  docker rename api-server-new api-server
+  
+  # Cleanup old images
+  docker image prune -f
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
script: |
docker stop api-server
docker rm api-server
docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
docker run -d -p 8080:8080 --name api-server --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
script: |
# Pull new image first to minimize downtime
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
# Backup current container name if exists
CURRENT_CONTAINER=$(docker ps -q -f name=api-server)
# Start new container on different port
docker run -d -p 8081:8080 --name api-server-new --network ${{secrets.DOCKER_NETWORKNAME}} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
# Wait for container to be healthy
sleep 10
if ! curl -f http://localhost:8081/health; then
echo "New container failed health check"
docker stop api-server-new
docker rm api-server-new
exit 1
fi
# Stop and remove old container
docker stop api-server
docker rm api-server
# Rename new container
docker rename api-server-new api-server
# Cleanup old images
docker image prune -f
๐Ÿงฐ Tools
๐Ÿช› yamllint

[error] 93-93: no new line character at the end of file

(new-line-at-end-of-file)

@dongkyeomjang dongkyeomjang merged commit d56c4b7 into dev Nov 18, 2024
3 checks passed
@dongkyeomjang dongkyeomjang deleted the Deploy/#20 branch November 18, 2024 16:35
dongkyeomjang added a commit that referenced this pull request Nov 22, 2024
* ๐ŸŒDeploy/#20: add dev-cicd.yml

* ๐ŸŒDeploy/#20: add gradle-wrapper.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐ŸŒ Deploy ๋ฐฐํฌ ๊ด€๋ จ dongkyeomjang assigned to dongkyeomjang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

๐ŸŒ Deploy - CICD Pipeline ๊ตฌ์ถ•
1 participant