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

chore: dockerize #384

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

chore: dockerize #384

wants to merge 9 commits into from

Conversation

kirisaki
Copy link
Contributor

@kirisaki kirisaki commented Jul 30, 2024

Overview

  • Dockerize
    • WebSocket
    • API
    • UI
    • Worker
  • Bundle docker-compose.yml

Summary by CodeRabbit

  • New Features

    • Updated Dockerfiles for the API and UI components, enhancing build and deployment processes.
    • Simplified Node.js application deployment by removing multi-stage build steps and directly starting the app.
  • Bug Fixes

    • None reported.
  • Refactor

    • Restructured Dockerfile paths and working directories to improve organization and modularity.
    • Implemented a multi-stage build process for the WebSocket server, optimizing performance and security.

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

The recent changes introduce a restructured Docker setup for a multi-service application, enhancing modularity and organization. Key modifications include updated Dockerfile configurations for the api, ui, and websocket services, optimizing their build processes and file structures. The introduction of Docker Compose facilitates seamless service orchestration, while new .dockerignore files optimize image size by excluding unnecessary files. These enhancements aim to streamline development workflows and improve dependency management.

Changes

Files Change Summary
api/Dockerfile Updated file paths and working directory. Shifted to a modular structure for the application.
ui/Dockerfile, ui/.dockerignore Changed base image to node:20.16-bullseye-slim, simplified build process, and added .dockerignore to optimize image size.
compose.yml Introduced Docker Compose for four services: api, mongo, websocket, and ui.
websocket/Dockerfile, websocket/.dockerignore Implemented multi-stage build for Rust application and added .dockerignore to ignore build artifacts.
websocket/Cargo.toml, websocket/bin/Cargo.toml Updated workspace members and added new dependencies for enhanced functionality.
websocket/bin/src/main.rs Modified import paths, logging configurations, and listening address for network accessibility.
websocket/crates/infra/Cargo.toml Renamed package from infra to flow-websocket-infra for clarity.
worker/Dockerfile Removed Dockerfile syntax directive, potentially altering build behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant API
    participant MongoDB
    participant WebSocket

    User->>UI: Request interface
    UI->>API: Call API service
    API->>MongoDB: Fetch data
    MongoDB-->>API: Return data
    API-->>UI: Send response
    User->>WebSocket: Establish connection
    WebSocket-->>User: Stream data
Loading

🐰 In a world where code takes flight,
Docker dances, shining bright.
Services spin, a seamless show,
Modular joy, watch it grow!
Changes bring a hop and cheer,
Code's new rhythm, loud and clear!
🥕✨


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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

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

netlify bot commented Jul 30, 2024

Deploy Preview for reearth-flow ready!

Name Link
🔨 Latest commit 781454e
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/66af1391dc07250008f30dc5
😎 Deploy Preview https://deploy-preview-384--reearth-flow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kirisaki kirisaki changed the title feat(websocket): /infra websocket communicating chore: dockerize Jul 30, 2024
@github-actions github-actions bot added the worker label Aug 1, 2024
@kirisaki kirisaki marked this pull request as ready for review August 1, 2024 10:16
@kirisaki kirisaki requested review from pyshx, KaWaite and a team as code owners August 1, 2024 10:16
Copy link
Contributor

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
websocket/bin/src/main.rs (1)

Import path issue detected.

The import path flow_websocket_infra::socket does not appear to be valid. The flow_websocket_infra crate or its modules (socket, handler, state) could not be found in the codebase. Please verify that the correct path is being used and that all necessary modules are included in the repository.

  • Ensure the flow_websocket_infra crate is defined in the Cargo.toml file.
  • Verify the presence of the socket module and its submodules (handler, state) within the flow_websocket_infra crate.
Analysis chain

Line range hint 4-9:
Verify the correctness of the new import path.

The import path for the socket module has been changed to flow_websocket_infra::socket. Ensure that this new path correctly resolves and that all necessary modules are available.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the new import path.

# Test: Check if the new import path is valid. Expect: No errors.
rg --type rust $'use flow_websocket_infra::socket'

Length of output: 113





Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 21fc177 and 4676815.

Files ignored due to path filters (1)
  • websocket/Cargo.lock is excluded by !**/*.lock, !**/*.lock
Files selected for processing (11)
  • api/Dockerfile (1 hunks)
  • compose.yml (1 hunks)
  • ui/.dockerignore (1 hunks)
  • ui/Dockerfile (1 hunks)
  • websocket/.dockerignore (1 hunks)
  • websocket/Cargo.toml (2 hunks)
  • websocket/Dockerfile (1 hunks)
  • websocket/bin/Cargo.toml (1 hunks)
  • websocket/bin/src/main.rs (3 hunks)
  • websocket/crates/infra/Cargo.toml (1 hunks)
  • worker/Dockerfile (1 hunks)
Files skipped from review due to trivial changes (4)
  • ui/.dockerignore
  • websocket/.dockerignore
  • websocket/bin/Cargo.toml
  • websocket/crates/infra/Cargo.toml
Additional comments not posted (24)
ui/Dockerfile (4)

1-1: LGTM!

The base image has been updated to node:20.16-bullseye-slim, which is a good choice for a lightweight and up-to-date Node.js environment.


3-3: LGTM!

Setting the working directory to /app is a common practice and helps organize application files within the container.


5-7: LGTM!

Using corepack to enable and prepare Yarn ensures that the specified version (4.2.2) is used for dependency management. The yarn install command correctly installs the dependencies.


9-9: LGTM!

The CMD instruction correctly starts the application using yarn start.

websocket/Dockerfile (6)

1-2: LGTM!

Using rust:1.80-slim-bullseye as the base image for the build stage is appropriate for building a Rust application.


3-4: LGTM!

Copying the source code to /websocket and setting the working directory is appropriate for organizing the application files.


5-7: LGTM!

Installing the necessary packages and building the application using cargo build --release is appropriate for a Rust application.


9-10: LGTM!

Using debian:bullseye-slim as the base image for the final stage is appropriate for running the application.


11-11: LGTM!

Copying the built application to /usr/local/bin/ is appropriate for running the application.


13-13: LGTM!

The CMD instruction correctly starts the application.

api/Dockerfile (5)

7-8: LGTM!

Updating the COPY commands and WORKDIR instruction to use the /api directory aligns with the new file structure and is appropriate for organizing the application files.


11-13: LGTM!

Updating the COPY commands to use the /api directory aligns with the new file structure and is appropriate for organizing the application files.


20-20: LGTM!

Updating the final COPY command to copy the entire /api directory from the build stage aligns with the new file structure and is appropriate for organizing the application files.


22-22: LGTM!

Updating the WORKDIR instruction to use the /api directory aligns with the new file structure and is appropriate for organizing the application files.


24-24: LGTM!

The CMD instruction correctly starts the application from the /api directory.

compose.yml (4)

26-31: LGTM!

The websocket service configuration looks good.


16-24: Verify the volume configuration.

The volume reearth-flow-mongo is configured with nocopy: true. Ensure this is the intended behavior.

Verification successful

Verify the volume configuration.

The volume reearth-flow-mongo is correctly configured with nocopy: true and the local driver. Ensure this is the intended behavior for your use case.

  • compose.yml:
    • Volume configuration for reearth-flow-mongo with nocopy: true
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the volume configuration for `reearth-flow-mongo`.

# Test: Search for the usage of `reearth-flow-mongo` in the codebase. Expect: Correct volume configuration and usage.
rg --type yaml -A 5 $'reearth-flow-mongo'

Length of output: 326


1-14: Ensure environment variables are correctly set.

The environment variable REEARTH_FLOW_DB is set to mongodb://mongo. Verify that this is the correct database connection string.

Verification successful

Environment variable REEARTH_FLOW_DB is correctly set.

The environment variable REEARTH_FLOW_DB is set to mongodb://mongo in the Docker Compose file, which aligns with the expected configuration for a Dockerized environment.

  • compose.yml: REEARTH_FLOW_DB: mongodb://mongo
  • api/.env.example: REEARTH_FLOW_DB=mongodb://localhost
  • api/internal/app/config/config_test.go: t.Setenv("REEARTH_FLOW_DB", "mongodb://testdb")
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the environment variable `REEARTH_FLOW_DB`.

# Test: Search for the usage of `REEARTH_FLOW_DB` in the codebase. Expect: Correct usage and connection string.
rg --type python -A 5 $'REEARTH_FLOW_DB'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the correctness of the environment variable `REEARTH_FLOW_DB`.

# Test: Search for the usage of `REEARTH_FLOW_DB` in the codebase. Expect: Correct usage and connection string.
rg REEARTH_FLOW_DB -A 5

Length of output: 952


33-40: Ensure environment variables are correctly set.

The environment variables are loaded from ./ui/.env. Verify that this file contains all necessary variables.

worker/Dockerfile (1)

1-1: Verify the impact of removing the syntax directive.

The removal of # syntax=docker/dockerfile:1 might affect the build process. Ensure that the default Dockerfile syntax is compatible with the current configuration.

Verification successful

Let's analyze the Dockerfile for any syntax or features that might require a specific Dockerfile version.


The removal of the syntax directive does not impact the Dockerfile.

The Dockerfile uses multi-stage builds and the COPY --from directive, which are supported by Docker 17.05 and later. As long as the Docker version being used supports these features, the removal of the syntax directive will not cause any issues.

  • Multi-stage builds: FROM rust:1.80-slim-bookworm AS builder and FROM debian:bookworm-slim AS final
  • COPY --from=builder /tmp/reearth-flow /bin
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the Dockerfile syntax directive.

# Test: Check for any build issues related to the Dockerfile syntax. Expect: No build issues.
docker build -f worker/Dockerfile .

Length of output: 111


Script:

#!/bin/bash
# Description: Analyze the Dockerfile for any syntax or features that require a specific Dockerfile version.

# Search for multi-stage builds, which are supported from Docker 17.05 onwards.
rg 'FROM .+ AS .+' worker/Dockerfile

# Search for other Dockerfile features that might require a specific version.
rg 'RUN --mount|RUN --chown|COPY --from|COPY --chown' worker/Dockerfile

Length of output: 230

websocket/Cargo.toml (2)

4-4: LGTM!

The addition of the new member bin in the workspace configuration looks good.


40-40: LGTM!

The addition of the new dependency flow-websocket-infra in the workspace dependencies looks good.

websocket/bin/src/main.rs (2)

21-21: Verify the appropriateness of the new logging configuration.

The default environment filter string has been changed to "server=debug,tower_http=debug". Ensure that this change aligns with the overall application context and provides the necessary logging output.


45-45: Verify the security and functionality of the new binding address.

The TCP listener's binding address has been updated to "0.0.0.0:8000". Ensure that this change does not introduce any security risks and that it functions as expected.

worker/Dockerfile Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the worker label Aug 4, 2024
Copy link
Contributor

@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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4676815 and 781454e.

Files selected for processing (3)
  • api/Dockerfile (1 hunks)
  • ui/Dockerfile (1 hunks)
  • websocket/Dockerfile (1 hunks)
Files skipped from review due to trivial changes (1)
  • websocket/Dockerfile
Files skipped from review as they are similar to previous changes (2)
  • api/Dockerfile
  • ui/Dockerfile

Copy link

codecov bot commented Aug 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@47dbcd7). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             main    #384   +/-   ##
======================================
  Coverage        ?   6.05%           
======================================
  Files           ?      98           
  Lines           ?   15101           
  Branches        ?       0           
======================================
  Hits            ?     914           
  Misses          ?   14103           
  Partials        ?      84           
Flag Coverage Δ
api 6.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants