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

Frontend CICD #23

Merged
merged 20 commits into from
Jan 24, 2025
Merged

Frontend CICD #23

merged 20 commits into from
Jan 24, 2025

Conversation

owenowenisme
Copy link
Collaborator

@owenowenisme owenowenisme commented Dec 11, 2024

Summary

架設測試站cicd

原本要使用ssh 進去機器部署
但由於我們的機器是在private network之中
因此需要用wireguard來連接tunnel並進入
但經過測試之後
不知為何 wireguard在github action 上會卡住 無法解決

因此目前先使用watchtower 監聽image 變化 (interval : 10s)
待之後scale up後再考量其他做法
因此目前github action只有CI部分 CD 部分 由 watchtower 負責

How Has This Been Tested?

附上如何測試的以及測試結果

Task:

https://ncku.atlassian.net/browse/NCKU-79

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow for frontend development.
    • Added a workflow to build and upload the frontend Docker image to GitHub Container Registry.
    • Implemented a new service for automatic updates of running Docker containers.
  • Chores

    • Configured workflows to enhance CI/CD processes for frontend applications.

Copy link

coderabbitai bot commented Dec 11, 2024

📝 Walkthrough

Walkthrough

This pull request introduces new GitHub Actions workflows and a Docker service configuration. A workflow named dev-frontend.yml is created to trigger frontend CI processes, while frontend-ci.yml is established to build and upload a Docker image of the frontend application to GitHub Container Registry. Additionally, a new service called watchtower is added to the Docker Compose configuration to manage automatic updates for running containers.

Changes

File Change Summary
.github/workflows/dev-frontend.yml New workflow to trigger frontend CI processes on specific branches.
.github/workflows/frontend-ci.yml New workflow to build and upload Docker image to GHCR.
watchtower/compose.yml New service watchtower added for automatic Docker container updates.

Poem

In the garden where code does bloom,
A rabbit hops with joy, dispelling gloom.
New workflows sprout, Docker images rise,
With watchtower's help, we reach for the skies!
Hooray for changes, let’s all cheer,
For a brighter future, the time is near! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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.

@owenowenisme owenowenisme requested review from AndresLie and a team and removed request for AndresLie December 11, 2024 03:48
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: 5

🧹 Outside diff range and nitpick comments (3)
.github/workflows/dev-frontend.yml (2)

5-6: Consider restricting branch pattern and adding environment checks

The current branch pattern dev/frontend@** might be too permissive. Consider:

  1. More specific pattern like dev/frontend@v*
  2. Adding environment validation step

Example:

on:
  push:
    branches:
      - 'dev/frontend@v*'
  workflow_dispatch:
    inputs:
      environment:
        description: 'Deployment environment'
        required: true
        default: 'development'
        type: choice
        options:
          - development
          - staging

13-13: Document migration plan from Watchtower

The comment indicates this is a temporary solution. Consider:

  1. Creating a tracking issue for the migration plan
  2. Documenting potential alternatives

Would you like me to create a GitHub issue to track the migration plan from Watchtower to a more robust CD solution?

🧰 Tools
🪛 yamllint (1.35.1)

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

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

.github/workflows/frontend-ci.yml (1)

9-10: Remove outdated comment

This comment refers to the release branch but the workflow triggers on workflow_dispatch and workflow_call.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 76c6f64 and a44d6fe.

📒 Files selected for processing (3)
  • .github/workflows/dev-frontend.yml (1 hunks)
  • .github/workflows/frontend-ci.yml (1 hunks)
  • watchtower/compose.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
watchtower/compose.yml

[error] 6-6: trailing spaces

(trailing-spaces)

.github/workflows/dev-frontend.yml

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

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

.github/workflows/frontend-ci.yml

[error] 1-1: trailing spaces

(trailing-spaces)


[warning] 8-8: too many blank lines

(3 > 2) (empty-lines)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 57-57: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)

Comment on lines +4 to +5
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security concern: Docker socket mounting creates a potential security risk

Mounting the Docker socket gives the container root-equivalent access to the host. Consider:

  1. Using a non-root user within the container
  2. Implementing socket proxy (e.g., docker-socket-proxy) to restrict API access

Example socket proxy configuration:

services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy
    privileged: false
    environment:
      - CONTAINERS=1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
  watchtower:
    image: containrrr/watchtower
    environment:
      - DOCKER_HOST=tcp://socket-proxy:2375
    depends_on:
      - socket-proxy

Comment on lines +6 to +7
command:
--interval 10 --cleanup
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Performance concern: 10-second update interval is too aggressive

Such a short interval could:

  1. Increase load on Docker registry
  2. Potentially hit rate limits
  3. Consume unnecessary resources

Consider increasing the interval to at least 5 minutes (300 seconds).

🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

Comment on lines +1 to +8
services:
watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command:
--interval 10 --cleanup
restart: always
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 container filters and authentication configuration

Current configuration will update all containers. Consider:

  1. Adding filters to target specific containers
  2. Configuring registry authentication
  3. Adding resource limits

Example enhanced configuration:

services:
  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - WATCHTOWER_POLL_INTERVAL=300
      - WATCHTOWER_LABEL_ENABLE=true
      - WATCHTOWER_CLEANUP=true
      - REGISTRY_USERNAME=${GHCR_USERNAME}
      - REGISTRY_PASSWORD=${GHCR_TOKEN}
    command: --label-enable
    deploy:
      resources:
        limits:
          memory: 256M
        reservations:
          memory: 128M
    restart: always
🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

Comment on lines +31 to +35
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use GITHUB_TOKEN with minimum required permissions

The workflow uses GITHUB_TOKEN with broad permissions. Consider:

  1. Using a fine-grained PAT for GHCR access
  2. Implementing OIDC authentication

[security]

Example configuration:

permissions:
  packages: write
  contents: read

steps:
  - name: Log in to the Container registry
    uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
    with:
      registry: ${{ env.REGISTRY }}
      username: ${{ github.actor }}
      password: ${{ secrets.GHCR_TOKEN }}

Comment on lines +49 to +56
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
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 security scanning and build optimization

Consider adding:

  1. Container vulnerability scanning
  2. Docker layer caching
  3. Build context optimization

Example enhancement:

steps:
  - name: Build and push Docker image
    uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
    with:
      context: ./frontend
      push: true
      tags: ${{ steps.meta.outputs.tags }}
      labels: ${{ steps.meta.outputs.labels }}
      cache-from: type=gha
      cache-to: type=gha,mode=max

  - name: Run Trivy vulnerability scanner
    uses: aquasecurity/trivy-action@master
    with:
      image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
      format: 'table'
      exit-code: '1'
      ignore-unfixed: true
      vuln-type: 'os,library'
      severity: 'CRITICAL,HIGH'

@owenowenisme owenowenisme merged commit cd39679 into dev/[email protected] Jan 24, 2025
2 checks passed
@owenowenisme owenowenisme deleted the frontend-cicd branch January 24, 2025 09:59
owenowenisme added a commit that referenced this pull request Mar 4, 2025
* testing ghcr pushing and tag

* testing latest tag on image

* testing frontend cd

* add job to dev-frontend

* modify ssh command

* modify ssh command

* modify ssh command

* modify ssh command

* update ssh

* update ssh

* update ssh

* update ssh

* update ssh

* update ssh

* test vpn connection

* add wireguard config to secret

* add resolve conf to apt install

* change another wireguard connection method

* use watchtower instead of ssh deployment

* update workflow for watch tower
owenowenisme added a commit that referenced this pull request Mar 4, 2025
* added starter task template

* init husky pre-commit

* add navbar

* Revert "add navbar"

This reverts commit 1aaa490.

* feat add file upload dropzone

* update pnpm-lock.yaml and package.json, set size for image in FileIpload

* File card initial commit

* remove wrong file

* Update ExamCard.tsx

* refine the exam card file

* refactor: simplify import paths

* feat add navbar

* Refactor: move repetitive code to separate file

* Refactor: refactor with coderabbitai review

* Refactor: refactor and remove some unnecessary tailwind css code

* Refactor: fix using the wrong variable

* Refactor: make css more prettier

* Refactor: remove style.css for following tailwind design pattern: only use @apply for repetitive style

* Refactor: change route names to lowercase and use prettier for unifying coding style

* update husky prepare command

* feat: add zustand state management for user data

* feat: add Navbar Login Button

* refactor: move state management logic in selectors.ts, UI logic in /hooks

* fix: update package.json and pnpm-lock.yaml

* Refactor: delete unuse selectors, fix syntax error.

* feats: using promise for async

* Frontend deploy adjust (#22)

* adjust dockerfile, nextjs config for deployment

* update compose.tml and dockerfile

* change base image to alpine & remove sharp from pnpm dependencies

* rename icon filename & adjust dockerfile

* Frontend CICD (#23)

* testing ghcr pushing and tag

* testing latest tag on image

* testing frontend cd

* add job to dev-frontend

* modify ssh command

* modify ssh command

* modify ssh command

* modify ssh command

* update ssh

* update ssh

* update ssh

* update ssh

* update ssh

* update ssh

* test vpn connection

* add wireguard config to secret

* add resolve conf to apt install

* change another wireguard connection method

* use watchtower instead of ssh deployment

* update workflow for watch tower

* Feature/tailwind config (#25)

* feat: config tailwind typography

* refactor: simplify tailwind typography classname

* feat: config design system colors

* fix: fix tailwind primary color wrong color code

* Feature/upload icons (#26)

* feat: upload svg icons

* feature: finish reusable icon components

* feat: uploads svg files: bookmark, bookmark-1, plus

* chore: add new three svgs to iconsMap

* Feature/basic components (#27)

* feature: basic UI components

* chore: fix some syntax and type problems.

* Refactor basic components (#29)

* refactor button

Signed-off-by: owenowenisme <[email protected]>

* remove React.FC from button component

Signed-off-by: owenowenisme <[email protected]>

* refactor Checkbox

Signed-off-by: owenowenisme <[email protected]>

* refactor MenuItem

Signed-off-by: owenowenisme <[email protected]>

* add Classname to Menuitem

Signed-off-by: owenowenisme <[email protected]>

* add onClick Event to MenuItem

Signed-off-by: owenowenisme <[email protected]>

* refactor textArea

Signed-off-by: owenowenisme <[email protected]>

* refactor icon

Signed-off-by: owenowenisme <[email protected]>

---------

Signed-off-by: owenowenisme <[email protected]>

* Refactor navbar (#30)

* refactor axios and finish usericon with login

Signed-off-by: owenowenisme <[email protected]>

* refactor api dir location, svg location, zustand location and usertype

Signed-off-by: owenowenisme <[email protected]>

* finish global Nav waiting for icon

Signed-off-by: owenowenisme <[email protected]>

* update baseurl, cn classValue

Signed-off-by: owenowenisme <[email protected]>

* fix logout loop

Signed-off-by: owenowenisme <[email protected]>

* update icon

Signed-off-by: owenowenisme <[email protected]>

---------

Signed-off-by: owenowenisme <[email protected]>

* added user setting page, enable profile update (#31)

Signed-off-by: owenowenisme <[email protected]>

---------

Signed-off-by: owenowenisme <[email protected]>
Co-authored-by: Max042004 <[email protected]>
Co-authored-by: Eroffff <[email protected]>
Co-authored-by: d-ben-b <[email protected]>
Co-authored-by: Max042004 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant