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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM debian:bookworm-slim as builder

RUN apt-get update && apt install -y git libtool automake autoconf make tini curl

## install dojoengine
RUN curl -L https://install.dojoengine.org | bash
Comment on lines +3 to +6
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.


SHELL ["/bin/bash", "-c"]

RUN source /root/.bashrc && dojoup

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
Comment on lines +12 to +17
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


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/"
Comment on lines +19 to +22
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.

20 changes: 20 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.8'

services:
katana:
image: dojoengine:latest
command: katana --dev --dev.no-fee --http.cors_origins "*" --http.addr 0.0.0.0
ports:
- "5050:5050"
Comment on lines +4 to +8
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

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"
Comment on lines +9 to +19
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


15 changes: 15 additions & 0 deletions docker/image_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Define the image name and tag
IMAGE_NAME="dojoengine"
IMAGE_TAG="latest"
DOCKERHUB_USERNAME="your_dockerhub_username"
Comment on lines +4 to +6
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'}"


# Build the Docker image
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
Comment on lines +8 to +9
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


# Log in to Docker Hub
docker login --username ${DOCKERHUB_USERNAME}
Comment on lines +11 to +12
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


# Push the Docker image to Docker Hub
docker push ${IMAGE_NAME}:${IMAGE_TAG}
60 changes: 60 additions & 0 deletions docker/torii.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The World address to index.
world_address = "0x0525177c8afe8680d7ad1da30ca183e482cfcd6404c1e09d83fd3fa2994fd4b8"

# Default RPC URL configuration
rpc = "http://host.docker.internal:5050"

# Database configuration
# Optional: If not specified, uses in-memory database
db_dir = "/tmp/torii"

# External URL for GraphQL Playground
# Optional: Used in hosted environments
# external_url = ""

# Whether to open World Explorer in browser
# Optional: Defaults to false
# explorer = false



# Server Options
[server]
http_addr = "0.0.0.0"
http_port = 8080
http_cors_origins = ["*"]

# Relay Options
[relay]
port = 9090 # TCP & UDP Quic transport
webrtc_port = 9091 # WebRTC transport
websocket_port = 9092 # WebSocket transport
# relay.local_key_path = "" # Optional: Path to identity key file, generated if none.
# relay.cert_path = "" # Optional: Path to certificate file for WebRTC

# Indexing Options
[indexing]
events_chunk_size = 1024 # Size of events page to fetch
blocks_chunk_size = 10240 # Blocks to process before DB commit
index_pending = true # Enable indexing pending blocks
polling_interval = 500 # Polling interval in milliseconds
max_concurrent_tasks = 100 # Maximum concurrent indexing tasks
index_transactions = false # Whether to index world transactions
contracts = [ # ERC contracts to index
"erc20:0x1234",
"erc721:0x5678"
]

# Events Options
[events]
raw = true # Whether to index raw events
historical = [ # Historical event message tags
"ns-E",
"ns-EH"
]

# Metrics Options
[metrics]
metrics = true # Enable metrics server
addr = "0.0.0.0" # Metrics server address
port = 9200 # Metrics server port
Loading