diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..b5dbe9424 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/secrets.dev.yaml +**/values.dev.yaml +./bin +./target +/bin +/target +LICENSE +README.md +accounts +genesis.dat +miden-store.* +store.* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad8e18276..af5cc2278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,7 @@ +# Runs the CI + name: CI + on: push: branches: diff --git a/Makefile.toml b/Makefile.toml index 3843976f7..2266170e7 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,8 +1,11 @@ # Cargo Makefile +# If running cargo-make in a workspace you need to add this env variable to make sure it function correctly. +# See docs: https://github.com/sagiegurari/cargo-make?tab=readme-ov-file#usage [env] CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true +# linting [tasks.format] toolchain = "nightly" command = "cargo" @@ -30,11 +33,7 @@ dependencies = [ [tasks.doc] env = { "RUSTDOCFLAGS" = "-D warnings" } command = "cargo" -args = ["doc", "--all-features", "--keep-going", "--release"] - -[tasks.test] -command = "cargo" -args = ["test", "--all-features", "--workspace", "--", "--nocapture"] +args = ["doc", "--verbose", "--all-features", "--keep-going", "--release"] [tasks.lint] dependencies = [ @@ -43,3 +42,37 @@ dependencies = [ "clippy", "docs" ] + +# testing +[tasks.test] +command = "cargo" +args = ["test", "--all-features", "--workspace", "--", "--nocapture"] + +# docker +[tasks.docker-build-node] +workspace = false +script = ''' +CREATED=$(date) +VERSION=$(cat node/Cargo.toml | grep -m 1 '^version' | cut -d '"' -f 2) +COMMIT=$(git rev-parse HEAD) + +docker build --build-arg CREATED="$CREATED" \ + --build-arg VERSION="$VERSION" \ + --build-arg COMMIT="$COMMIT" \ + -f node/Dockerfile \ + -t miden-node-image . +''' + +[tasks.docker-run-node] +workspace = false +script = ''' +docker volume create miden-db + +ABSOLUTE_PATH="$(pwd)/node/miden-node.toml" + +docker run --name miden-node \ + -p 57291:57291 \ + -v miden-db:/db \ + -v "${ABSOLUTE_PATH}:/miden-node.toml" \ + -d miden-node-image +''' diff --git a/README.md b/README.md index 7ca94f900..4dad628e1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Before you can build and run the Miden node or any of its components, you'll nee Depending on the platform, you may need to install additional libraries. For example, on Ubuntu 22.04 the following command ensures that all required libraries are installed. ```sh -sudo apt install gcc llvm clang bindgen pkg-config libssl-dev libsqlite3-dev +sudo apt install llvm clang bindgen pkg-config libssl-dev libsqlite3-dev ``` ### Installing the node @@ -91,5 +91,33 @@ Please, refer to each component's documentation: Each directory containing the executables also contains an example configuration file. Make sure that the configuration files are mutually consistent. That is, make sure that the URLs are valid and point to the right endpoint. +### Running the node using Docker + +If you intend on running the node inside a Docker container, you will need to follow these steps: + +1. Build the docker image from source + + ```sh + cargo make docker-build-node + ``` + + This command will build the docker image for the Miden node and save it locally. + +2. Run the Docker container + + ```sh + docker run --name miden-node -p 57291:57291 -d miden-node-image + ``` + + This command will run the node as a container named `miden-node` using the `miden-node-image` and make port `57291` available (rpc endpoint). + +3. Monitor container + + ```sh + docker ps + ``` + + After running this command you should see the name of the container `miden-node` being outputed and marked as `Up`. + ## License This project is [MIT licensed](./LICENSE). diff --git a/miden-node.toml b/miden-node.toml new file mode 100644 index 000000000..04f582981 --- /dev/null +++ b/miden-node.toml @@ -0,0 +1,21 @@ +# This is an example configuration file for the Miden node. + +[block_producer] +# port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-block-producer', 1)) % 2**16 +endpoint = { host = "localhost", port = 48046 } +store_url = "http://localhost:28943" +# enables or disables the verification of transaction proofs before they are accepted into the +# transaction queue. +verify_tx_proofs = true + +[rpc] +# port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-rpc', 1)) % 2**16 +endpoint = { host = "0.0.0.0", port = 57291 } +block_producer_url = "http://localhost:48046" +store_url = "http://localhost:28943" + +[store] +# port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-store', 1)) % 2**16 +endpoint = { host = "localhost", port = 28943 } +database_filepath = "db/miden-store.sqlite3" +genesis_filepath = "genesis.dat" diff --git a/node/Dockerfile b/node/Dockerfile new file mode 100644 index 000000000..6fc95e69c --- /dev/null +++ b/node/Dockerfile @@ -0,0 +1,56 @@ +# Miden node Dockerfile + +# Setup image builder +FROM rust:1.76-slim-bookworm AS builder + +# Install dependencies +RUN apt-get update && \ + apt-get -y upgrade && \ + apt-get install -y llvm clang bindgen pkg-config libssl-dev libsqlite3-dev && \ + rm -rf /var/lib/apt/lists/* + +# Copy source code +WORKDIR /app +COPY . . + +# Build the node crate +RUN cargo install --features testing --path node +RUN miden-node make-genesis --inputs-path node/genesis.toml + +# Run Miden node +FROM debian:bookworm-slim + +# Update machine & install required packages +# The instalation of sqlite3 is needed for correct function of the SQLite database +RUN apt-get update && \ + apt-get -y upgrade && \ + apt-get install -y --no-install-recommends \ + sqlite3 \ + && rm -rf /var/lib/apt/lists/* + +# Copy artifacts from the builder stage +COPY --from=builder /app/genesis.dat genesis.dat +COPY --from=builder /app/accounts accounts +COPY --from=builder /usr/local/cargo/bin/miden-node /usr/local/bin/miden-node + +# Set labels +LABEL org.opencontainers.image.authors=miden@polygon.io \ + org.opencontainers.image.url=https://0xpolygonmiden.github.io/ \ + org.opencontainers.image.documentation=https://github.com/0xPolygonMiden/miden-node \ + org.opencontainers.image.source=https://github.com/0xPolygonMiden/miden-node \ + org.opencontainers.image.vendor=Polygon \ + org.opencontainers.image.licenses=MIT + +ARG CREATED +ARG VERSION +ARG COMMIT +LABEL org.opencontainers.image.created=$CREATED \ + org.opencontainers.image.version=$VERSION \ + org.opencontainers.image.revision=$COMMIT + +# Expose RPC port +EXPOSE 57291 + +# Start the Miden node +# Miden node does not spawn sub-processes, so it can be used as the PID1 +CMD miden-node start --config miden-node.toml diff --git a/node/miden-node.toml b/node/miden-node.toml index f0811acd7..04f582981 100644 --- a/node/miden-node.toml +++ b/node/miden-node.toml @@ -10,12 +10,12 @@ verify_tx_proofs = true [rpc] # port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-rpc', 1)) % 2**16 -endpoint = { host = "localhost", port = 57291 } +endpoint = { host = "0.0.0.0", port = 57291 } block_producer_url = "http://localhost:48046" store_url = "http://localhost:28943" [store] # port defined as: sum(ord(c)**p for (p, c) in enumerate('miden-store', 1)) % 2**16 endpoint = { host = "localhost", port = 28943 } -database_filepath = "miden-store.sqlite3" +database_filepath = "db/miden-store.sqlite3" genesis_filepath = "genesis.dat"