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

Dockerize node #257

Merged
merged 30 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e1c2e9b
Working initial docker
phklive Feb 15, 2024
8f28a4d
Merge branch 'main' into phklive-dockerize-node
phklive Feb 28, 2024
80c60b3
fmt
phklive Feb 28, 2024
042ad7f
added script
phklive Feb 28, 2024
ac7ebe7
Removed docker script + updated integration
phklive Feb 29, 2024
2d01181
script works
phklive Mar 1, 2024
47a76e9
Need to install grpcurl
phklive Mar 1, 2024
20b4262
Docker works
phklive Mar 4, 2024
3e77d00
Working Dockerfile
phklive Mar 4, 2024
96f4a8b
ci: turn doc warnings into errors (#259)
hackaugusto Mar 5, 2024
8298f8f
Removed makefile, removing start.sh file moving in Dockerfile
phklive Mar 6, 2024
59e461d
Merge branch 'main' into phklive-dockerize-node
phklive Mar 6, 2024
891f77e
Added bookworm + alpine + removed gcc + added caching
phklive Mar 6, 2024
04a21d4
Merge branch 'main' into phklive-dockerize-node
phklive Mar 8, 2024
21ee551
Moved Dockerfile to node and added Makefile.toml
phklive Mar 9, 2024
29f38c5
cargo make works + builds dockerfile for node
phklive Mar 11, 2024
7b97987
Pull
phklive Mar 12, 2024
53d9c96
merge next + add docker build and doc in ci
phklive Mar 12, 2024
494bb55
remove start script
phklive Mar 12, 2024
c9ed28f
added comment regarding PID1
phklive Mar 12, 2024
5fb9679
Set labels at top of Dockerfile + added comments
phklive Mar 13, 2024
89883af
Added correct dependencies and explanation
phklive Mar 13, 2024
203f6b1
Volume works persisting db files between runs
phklive Mar 14, 2024
ddc3c88
Merge branch 'next' of github.com:0xPolygonMiden/miden-node into next
phklive Mar 14, 2024
eac99cd
Merge branch 'next' into phklive-dockerize-node
phklive Mar 14, 2024
8600cf5
Added documentation
phklive Mar 14, 2024
d04e71e
Moved labels + enable mounting of miden-node.toml
phklive Mar 14, 2024
d09f6f9
Added docker-run-node command + added build arguments
phklive Mar 14, 2024
8d138ec
Add git commit as arg to docker container
phklive Mar 14, 2024
1732666
Added spacing
phklive Mar 14, 2024
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
38 changes: 38 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not working for me. Maybe it is a different among podman and docker. But this is causing me to upload 11G of data to the docker VM, and at first sign it looked like podman wasn't working.

Can you change the paths from /bin and /target to ./bin and ./target? And also test on your machine?

Copy link
Contributor

Choose a reason for hiding this comment

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

I now wonder how the --mount is implemented on MacOs, because I may have given bad advice with the cargo cache below, if the data has to be copied to the VM.

LICENSE
README.md
accounts
genesis.dat
miden-store.*
store.*
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Runs the CI

name: CI

on:
push:
branches:
Expand Down
43 changes: 38 additions & 5 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -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
phklive marked this conversation as resolved.
Show resolved Hide resolved
[tasks.format]
toolchain = "nightly"
command = "cargo"
Expand Down Expand Up @@ -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 = [
Expand All @@ -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
'''
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
21 changes: 21 additions & 0 deletions miden-node.toml
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick question: why do we need to duplicate this file here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not need to, fixed it in the next PR.

Original file line number Diff line number Diff line change
@@ -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"
56 changes: 56 additions & 0 deletions node/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: The final image has an okay size:

REPOSITORY                  TAG                 IMAGE ID      CREATED             SIZE
localhost/miden-node-image  latest              63b9223ac3cb  About a minute ago  124 MB

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: start/stop is working, the state is not lost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: The final image has an okay size:

REPOSITORY                  TAG                 IMAGE ID      CREATED             SIZE
localhost/miden-node-image  latest              63b9223ac3cb  About a minute ago  124 MB

Do you have ideas in mind to improve on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: start/stop is working, the state is not lost

This is positive right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have ideas in mind to improve on it?

I think this size is good enough. I was just adding context to the PR.

Note: start/stop is working, the state is not lost

Yes. This was not a request. I was just adding context to the PR.


# 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 [email protected] \
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move all args to the top (line 27 or even top of file) and group all labels into one single LABEL?

Copy link
Contributor

@hackaugusto hackaugusto Mar 14, 2024

Choose a reason for hiding this comment

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

I think this is not a good idea. When I'm debugging the DockerFile, I will rebuild the same image multiple times using the same COMMIT, the same VERSION, and different CREATED timestamps.

The CREATED timestamps change will invalidate the cache, and force a rebuild of everything that follows it. Moving this to the top of the file means we never reuse the caching system when rebuilding images, and we spend tons of time with rebuilds.

Please move it down, as far as you can. Here is the docs

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
4 changes: 2 additions & 2 deletions node/miden-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading