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

feat: docker && docker-compose #2906

Closed
wants to merge 1 commit into from

Conversation

847850277
Copy link
Contributor

@847850277 847850277 commented Jan 14, 2025

Description

Hi, @glihm Docker support has been provided for Dojo. Please review it when you have free time

add docker folder to support build docker image && run docker-compose with config

close #2902

Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

Ohayo, sensei! This pull request introduces a comprehensive Docker setup for the Dojo game engine, including a multi-stage Dockerfile, a Docker Compose configuration, an image build script, and a detailed Torii configuration file. The changes aim to simplify deployment and provide a standardized containerized environment for running Dojo services like Katana and Torii.

Changes

File Change Summary
docker/Dockerfile Multi-stage build process using Debian Bookworm, installing development tools and Dojo engine components
docker/docker-compose.yml Added services for Katana and Torii, configuring ports and runtime parameters
docker/image_build.sh New script for building and pushing Docker image to Docker Hub
docker/torii.toml Comprehensive configuration file for Torii service with detailed settings for world address, indexing, events, and metrics

Assessment against linked issues

Objective Addressed Explanation
Support Docker Compose for Katana and Torii
Enable easy deployment of services
Provide configuration for Sepolia/Mainnet services

The changes fully address the requirements outlined in issue #2902, providing a complete Docker and Docker Compose setup for Dojo engine services.


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. (Beta)
  • @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.

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: 8

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fde72d7 and d044ea3.

📒 Files selected for processing (4)
  • docker/Dockerfile (1 hunks)
  • docker/docker-compose.yml (1 hunks)
  • docker/image_build.sh (1 hunks)
  • docker/torii.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docker/torii.toml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: clippy

Comment on lines +8 to +9
# Build the Docker image
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
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 error handling and build context path, sensei!

The build command needs error handling and explicit build context.

-docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
+if ! docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f docker/Dockerfile .; then
+    echo "Failed to build image"
+    exit 1
+fi
📝 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
# Build the Docker image
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
# Build the Docker image
if ! docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f docker/Dockerfile .; then
echo "Failed to build image"
exit 1
fi

Comment on lines +11 to +12
# Log in to Docker Hub
docker login --username ${DOCKERHUB_USERNAME}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Secure the Docker Hub authentication, sensei!

Consider using Docker config or environment variables for secure credential handling.

-docker login --username ${DOCKERHUB_USERNAME}
+if [ -z "${DOCKERHUB_TOKEN}" ]; then
+    echo "DOCKERHUB_TOKEN is required"
+    exit 1
+fi
+echo "${DOCKERHUB_TOKEN}" | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
📝 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
# Log in to Docker Hub
docker login --username ${DOCKERHUB_USERNAME}
# Log in to Docker Hub
if [ -z "${DOCKERHUB_TOKEN}" ]; then
echo "DOCKERHUB_TOKEN is required"
exit 1
fi
echo "${DOCKERHUB_TOKEN}" | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin

Comment on lines +4 to +6
IMAGE_NAME="dojoengine"
IMAGE_TAG="latest"
DOCKERHUB_USERNAME="your_dockerhub_username"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo! Let's make the image configuration more flexible, sensei!

Consider using environment variables instead of hardcoded values:

-IMAGE_NAME="dojoengine"
-IMAGE_TAG="latest"
-DOCKERHUB_USERNAME="your_dockerhub_username"
+IMAGE_NAME="${DOCKER_IMAGE_NAME:-dojoengine}"
+IMAGE_TAG="${DOCKER_IMAGE_TAG:-latest}"
+DOCKERHUB_USERNAME="${DOCKERHUB_USERNAME:?'DOCKERHUB_USERNAME is required'}"
📝 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
IMAGE_NAME="dojoengine"
IMAGE_TAG="latest"
DOCKERHUB_USERNAME="your_dockerhub_username"
IMAGE_NAME="${DOCKER_IMAGE_NAME:-dojoengine}"
IMAGE_TAG="${DOCKER_IMAGE_TAG:-latest}"
DOCKERHUB_USERNAME="${DOCKERHUB_USERNAME:?'DOCKERHUB_USERNAME is required'}"

Comment on lines +4 to +8
katana:
image: dojoengine:latest
command: katana --dev --dev.no-fee --http.cors_origins "*" --http.addr 0.0.0.0
ports:
- "5050:5050"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance the katana service configuration, sensei!

Add health check, restart policy, and resource limits for better reliability:

   katana:
     image: dojoengine:latest
     command: katana --dev --dev.no-fee --http.cors_origins "*" --http.addr 0.0.0.0
     ports:
       - "5050:5050"
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost:5050/is_alive"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+    restart: unless-stopped
+    deploy:
+      resources:
+        limits:
+          memory: 1G
+        reservations:
+          memory: 512M
📝 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
katana:
image: dojoengine:latest
command: katana --dev --dev.no-fee --http.cors_origins "*" --http.addr 0.0.0.0
ports:
- "5050:5050"
katana:
image: dojoengine:latest
command: katana --dev --dev.no-fee --http.cors_origins "*" --http.addr 0.0.0.0
ports:
- "5050:5050"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5050/is_alive"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M

Comment on lines +9 to +19
torii:
image: dojoengine:latest
command: torii --config /etc/torii/torii.toml
volumes:
- ./torii.toml:/etc/torii/torii.toml
ports:
- "8080:8080"
- "9090:9090"
- "9091:9091"
- "9092:9092"
- "9200:9200"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance the torii service configuration, sensei!

Add dependency on katana, health check, and resource management:

   torii:
     image: dojoengine:latest
     command: torii --config /etc/torii/torii.toml
     volumes:
       - ./torii.toml:/etc/torii/torii.toml
     ports:
       - "8080:8080"
       - "9090:9090"
       - "9091:9091"
       - "9092:9092"
       - "9200:9200"
+    depends_on:
+      katana:
+        condition: service_healthy
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+    restart: unless-stopped
+    deploy:
+      resources:
+        limits:
+          memory: 1G
+        reservations:
+          memory: 512M
📝 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
torii:
image: dojoengine:latest
command: torii --config /etc/torii/torii.toml
volumes:
- ./torii.toml:/etc/torii/torii.toml
ports:
- "8080:8080"
- "9090:9090"
- "9091:9091"
- "9092:9092"
- "9200:9200"
torii:
image: dojoengine:latest
command: torii --config /etc/torii/torii.toml
volumes:
- ./torii.toml:/etc/torii/torii.toml
ports:
- "8080:8080"
- "9090:9090"
- "9091:9091"
- "9092:9092"
- "9200:9200"
depends_on:
katana:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M

Comment on lines +19 to +22
LABEL description="Dojo is a provable game engine and toolchain for building onchain games and autonomous worlds with Cairo" \
authors="tarrence <[email protected]>" \
source="https://github.com/dojoengine/dojo" \
documentation="https://book.dojoengine.org/"
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 ENTRYPOINT and default CMD, sensei!

Use tini as entry point and set a default command:

 LABEL description="Dojo is a provable game engine and toolchain for building onchain games and autonomous worlds with Cairo" \
     authors="tarrence <[email protected]>" \
     source="https://github.com/dojoengine/dojo" \
     documentation="https://book.dojoengine.org/"
+
+ENTRYPOINT ["/tini", "--"]
+CMD ["katana", "--help"]

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +3 to +6
RUN apt-get update && apt install -y git libtool automake autoconf make tini curl

## install dojoengine
RUN curl -L https://install.dojoengine.org | bash
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Secure the package installation and script download, sensei!

Add checksum verification and cleanup unnecessary packages:

-RUN apt-get update && apt install -y git libtool automake autoconf make tini curl
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends \
+        git=1:2.39.2-1.1 \
+        libtool=2.4.7-5 \
+        automake=1:1.16.5-1.3 \
+        autoconf=2.71-3 \
+        make=4.3-4.1 \
+        tini=0.19.0-1 \
+        curl=7.88.1-10+deb12u5 \
+        ca-certificates && \
+    apt-get clean && \
+    rm -rf /var/lib/apt/lists/*

-RUN curl -L https://install.dojoengine.org | bash
+RUN curl -fsSL https://install.dojoengine.org -o install.sh && \
+    echo "${DOJO_INSTALLER_SHA256} install.sh" | sha256sum -c && \
+    bash install.sh && \
+    rm install.sh

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +12 to +17
FROM debian:bookworm-slim as base

COPY --from=builder /usr/bin/tini /tini
COPY --from=builder /root/.dojo/bin/katana /usr/local/bin/katana
COPY --from=builder /root/.dojo/bin/sozo /usr/local/bin/sozo
COPY --from=builder /root/.dojo/bin/torii /usr/local/bin/torii
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Create a non-root user and set proper permissions, sensei!

Add a non-root user for better security:

 FROM debian:bookworm-slim as base

+RUN groupadd -r dojo && useradd -r -g dojo dojo
+
 COPY --from=builder /usr/bin/tini /tini
 COPY --from=builder /root/.dojo/bin/katana /usr/local/bin/katana
 COPY --from=builder /root/.dojo/bin/sozo /usr/local/bin/sozo
 COPY --from=builder /root/.dojo/bin/torii /usr/local/bin/torii
+
+RUN chown -R dojo:dojo /usr/local/bin/katana /usr/local/bin/sozo /usr/local/bin/torii && \
+    chmod +x /tini /usr/local/bin/katana /usr/local/bin/sozo /usr/local/bin/torii
+
+USER dojo
📝 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
FROM debian:bookworm-slim as base
COPY --from=builder /usr/bin/tini /tini
COPY --from=builder /root/.dojo/bin/katana /usr/local/bin/katana
COPY --from=builder /root/.dojo/bin/sozo /usr/local/bin/sozo
COPY --from=builder /root/.dojo/bin/torii /usr/local/bin/torii
FROM debian:bookworm-slim as base
RUN groupadd -r dojo && useradd -r -g dojo dojo
COPY --from=builder /usr/bin/tini /tini
COPY --from=builder /root/.dojo/bin/katana /usr/local/bin/katana
COPY --from=builder /root/.dojo/bin/sozo /usr/local/bin/sozo
COPY --from=builder /root/.dojo/bin/torii /usr/local/bin/torii
RUN chown -R dojo:dojo /usr/local/bin/katana /usr/local/bin/sozo /usr/local/bin/torii && \
chmod +x /tini /usr/local/bin/katana /usr/local/bin/sozo /usr/local/bin/torii
USER dojo

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.82%. Comparing base (fde72d7) to head (d044ea3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2906   +/-   ##
=======================================
  Coverage   55.82%   55.82%           
=======================================
  Files         449      449           
  Lines       57824    57824           
=======================================
  Hits        32283    32283           
  Misses      25541    25541           

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

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Hey @847850277, thank you but not sure on how relevant this is, there's already a docker to build and work with dojo + a dev container.

Will close but don't hesitate to comment if you have further questions, or don't hesitate to pick an open issue. 👍

@glihm glihm closed this Jan 14, 2025
@847850277
Copy link
Contributor Author

847850277 commented Jan 14, 2025

Hey @847850277, thank you but not sure on how relevant this is, there's already a docker to build and work with dojo + a dev container.

Will close but don't hesitate to comment if you have further questions, or don't hesitate to pick an open issue. 👍

Hey @847850277, thank you but not sure on how relevant this is, there's already a docker to build and work with dojo + a dev container.

Will close but don't hesitate to comment if you have further questions, or don't hesitate to pick an open issue. 👍

thanks! sir,I found it docker-images
Thank you for your patient explanation

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.

support dojo docker && docker-compose
2 participants