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

👷 Update CI/CD for cloudrun #113

Merged
merged 1 commit into from
Mar 2, 2024
Merged

👷 Update CI/CD for cloudrun #113

merged 1 commit into from
Mar 2, 2024

Conversation

Shion1305
Copy link
Member

@Shion1305 Shion1305 commented Mar 2, 2024

Cloud Run用にCI/CDを編集。

https://github.com/ynufes-tech/ynufes-cloudrun-cicd-demo
以上を参考に。

Summary by CodeRabbit

  • New Features

    • Introduced automated deployment workflows for Google Cloud Run, enhancing the CI/CD pipeline. This includes deployments for pull request previews, staging, and release environments.
    • Added a Dockerfile to streamline the building and running of the web application in a containerized environment.
  • Chores

    • Updated .dockerignore to enhance Docker build efficiency by excluding unnecessary files and directories.
  • Documentation

    • Implemented GitHub Actions workflows documentation for automated deployment processes, including cleanup actions for closed pull requests.

Copy link

coderabbitai bot commented Mar 2, 2024

Walkthrough

The recent updates introduce comprehensive automation for deploying web applications to Google Cloud Run, catering to various stages of the development lifecycle including PR previews, staging, and release deployments. Enhancements include ignoring unnecessary files in Docker builds, setting up a Node.js environment for the web app, and streamlining the deployment process through GitHub Actions workflows. These changes facilitate efficient and automated management of Cloud Run services and their associated artifacts.

Changes

Files Change Summaries
.dockerignore Added entries: .nuxt, .output, node_modules to ignore in Docker builds.
.../deploy-cloudrun-pr-closed.yaml New workflow to delete Cloud Run services and artifacts on PR close.
.../deploy-cloudrun-pr.yaml Automates deployment to Cloud Run for PR previews.
.../deploy-cloudrun-release.yaml Sets up deployment to Cloud Run on the "release" branch.
.../deploy-cloudrun-stg.yaml Automates deployment to Cloud Run for staging environment.
cloudrun/Dockerfile New Dockerfile for building and running a Node.js web app, with builder and production stages.

"In the realm of clouds so high, 🌥️
Where our code takes flight and fly. 🚀
We build, we push, we deploy with zest,
From PR to staging, to release, we never rest.
With Docker and GitHub, our allies true, 🐳💻
A rabbit’s touch, making deployments anew." 🐰✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 61e84c2 and 182b0e0.
Files selected for processing (6)
  • .dockerignore (1 hunks)
  • .github/workflows/deploy-cloudrun-pr-closed.yaml (1 hunks)
  • .github/workflows/deploy-cloudrun-pr.yaml (1 hunks)
  • .github/workflows/deploy-cloudrun-release.yaml (1 hunks)
  • .github/workflows/deploy-cloudrun-stg.yaml (1 hunks)
  • cloudrun/Dockerfile (1 hunks)
Files skipped from review due to trivial changes (1)
  • .dockerignore
Additional comments: 13
cloudrun/Dockerfile (5)
  • 4-4: Setting BASE_URL as an environment variable at build time is a good practice for configurability. However, ensure that this value aligns with the application's expected base URL in different environments (development, staging, production). If the base URL varies across environments, consider passing it as a runtime environment variable instead.
  • 20-22: Copying minimal files from the builder stage to the production stage is a good practice for keeping the Docker image size small. However, ensure that all necessary runtime dependencies are included. If your application depends on node_modules, you might need to adjust the build process to include only production dependencies in the final image.
  • 24-28: The environment variables HOST, BASE_URL, and PORT are correctly set for the application's runtime. However, ensure that these values are appropriate for the production environment and that they do not conflict with any external configuration management or deployment settings.
  • 31-31: The command to start the application is clear and specifies the path to the server's entry point. Ensure that the .output/server/index.mjs file is correctly generated by the build process and that it is the correct entry point for your application.
  • 34-34: Exposing port 8080 is standard for web applications. Ensure that this port aligns with the application's configuration and the deployment environment's requirements. If the application is expected to run on a different port in certain environments, consider making the port configurable through environment variables.
.github/workflows/deploy-cloudrun-pr-closed.yaml (8)
  • 1-1: The workflow name is descriptive and clearly indicates its purpose. This is good practice for maintainability and understanding the workflow's role within the CI/CD pipeline.
  • 3-7: Triggering the workflow on pull request closure for the main branch is appropriate for the intended cleanup task. This ensures that resources are only cleaned up when changes are merged or abandoned, preventing premature deletion.
  • 10-13: The permissions set for the workflow are minimal and appropriate for the tasks being performed, adhering to the principle of least privilege. This reduces the risk of unauthorized access or actions if the workflow's credentials were compromised.
  • 15-21: Using the google-github-actions/auth action for authentication is a secure and recommended way to handle Google Cloud credentials within GitHub Actions. Ensure that the service account used has only the necessary permissions for deleting Cloud Run services and Docker images.
  • 23-26: Setting up gcloud with the google-github-actions/setup-gcloud action is necessary for executing gcloud commands. Ensure that the specified version constraint ('>= 363.0.0') aligns with the features and commands used in the workflow.
  • 28-32: The command to delete the Cloud Run service is correctly formed and includes the --quiet flag to avoid interactive prompts. However, ensure that the naming convention for Cloud Run services (tokiwa23-stg-pr-${{ github.event.number }}) matches the convention used during deployment to avoid mismatches and failed deletions.
  • 34-38: Similarly, the command to delete the Docker image from Artifact Registry is well-formed. Ensure that the naming convention and path (asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/staging/tokiwa23-pr-${{ github.event.number }}:latest) match those used during the image push to ensure successful deletion.
  • 40-45: Posting a failure notification on the pull request if resource deletion fails is a good practice for visibility and troubleshooting. However, ensure that the GitHub token used has the necessary permissions to post comments on pull requests.

Comment on lines +1 to +2
FROM node:20-slim as builder
#nodeのイメージをベースにする
Copy link

Choose a reason for hiding this comment

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

The comment in line 2 is written in Japanese, which might not be universally understood by all team members or contributors. Consider translating comments into English to maintain consistency and ensure that the codebase is accessible to a wider audience.

Comment on lines +9 to +10
COPY ./ ./
#ynu-fes...の下を/appの下にコピー
Copy link

Choose a reason for hiding this comment

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

Ensure that copying the entire project directory into the Docker image does not inadvertently include sensitive files or unnecessary files that could bloat the image size. It's good practice to use a .dockerignore file to exclude files not needed in the build context, such as local environment configurations, logs, or temporary files.

Comment on lines +12 to +14
RUN yarn install

RUN yarn build
Copy link

Choose a reason for hiding this comment

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

The use of yarn install followed by yarn build is standard for Node.js applications. However, consider using yarn install --frozen-lockfile to ensure that the installed dependencies match the versions specified in yarn.lock, which can help prevent accidental updates and ensure consistent builds.

Copy link

github-actions bot commented Mar 2, 2024

@Shion1305 Shion1305 merged commit ec50d96 into main Mar 2, 2024
3 checks passed
@Shion1305 Shion1305 deleted the update-cicd-cloudrun branch March 2, 2024 15:29
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