-
Notifications
You must be signed in to change notification settings - Fork 40
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
Dockerize node #257
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left a few questions and suggestions.
Dockerfile
Outdated
RUN cd miden-node && make | ||
|
||
### Run Miden-Node | ||
FROM ubuntu:22.04 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
questions:
- why ubuntu here instead of debian like the builder image? if we can, debian slim/alpine would be better
- why 22.04 instead of 24.04?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This image should have LABEL
s. I suggest using open containers 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
LABEL org.opencontainers.image.created=$CREATED \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$COMMIT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a VOLUME
to have the store's db.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add a volume we would need to modify where the node reads and writes it's database files in order to persist them to the volume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add a volume we would need to modify where the node reads and writes it's database files in order to persist them to the volume.
The WORKDIR
setting should handle that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the last thing pending, have not yet been able to make it work correctly. Looking into it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Managed to fix this, now the node creates a db folder to put it's sqlite files, this volume is mounted from the host as a volume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left one nit comment inline, but overall it looks good!
|
||
ARG CREATED | ||
ARG VERSION | ||
ARG COMMIT |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
Dockerfile
Outdated
RUN cd miden-node && make | ||
|
||
### Run Miden-Node | ||
FROM ubuntu:22.04 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add a volume we would need to modify where the node reads and writes it's database files in order to persist them to the volume.
The WORKDIR
setting should handle that.
node/Dockerfile
Outdated
libssl-dev \ | ||
libsqlite3-dev \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these dependencies? If so, can you please add some docs about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hackaugusto IIRC, we need them for building under linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the runner image, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is indeed. Running the program failed when these were not installed on the machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is interesting. Can you please add a comment above the deps. It seems a bit off that the headers are needed to run the compiled binary. Also, what was the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024-03-12 16:55:51 miden-node: error while loading shared libraries: libsqlite3.so.0: cannot open shared object file: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, for that you shouldn't need the headers, you only need the library. libsqlite3
should be enough, it is only marginally better though (to avoid confusion like I had here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence what do you recommend to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what I have been proposing:
- keep dependencies to a minimum
- document why they are needed
why am I proposing the above?
- it is hard to maintain script files without this information, for example, the discussion of
gcc
andclang
being needed is something that happened because of lack of documentation. I'm trying to prevent that - the above is specially a problem when upgrade the file down the line, and usually causes issues were one doesn't know why something is there, so we default to "better not touch it since it is working", which can compound over time
so here, since libsqlite3-dev
is not needed, these are the headers, we would remove that dependency and have libsqlite3
instead. since that is the .so
file that is needed to run the software, and add a comment # sqlite3: used by the store
.
That way we have a minimum number of dependencies and some traceability on them, making it easier to maintain it.
edit: same thing for libssl-dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I got the node started and played around with it a bit :) Super neat. We have some few things to fix though.
node/Dockerfile
Outdated
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
cargo fetch --manifest-path node/Cargo.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just tested, the cache is not working, the VM is downloading everything fresh:
[1/2] STEP 10/12: RUN --mount=type=cache,target=/usr/local/cargo/registry cargo fetch --manifest-path node/Cargo.toml
info: syncing channel updates for '1.75-aarch64-unknown-linux-gnu'
info: latest update on 2023-12-28, rust version 1.75.0 (82e1608df 2023-12-21)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
(also compiling)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed for now the caching does not work. I am looking into doing it manually as we did or using cargo-chef
: https://github.com/LukeMathWalker/cargo-chef
What do you think?
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
/bin | ||
/target |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
RUN miden-node make-genesis --inputs-path node/genesis.toml | ||
|
||
# Run Miden node | ||
FROM debian:bookworm-slim |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
||
ARG CREATED | ||
ARG VERSION | ||
ARG COMMIT |
There was a problem hiding this comment.
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
Makefile.toml
Outdated
# docker | ||
[tasks.docker-build-node] | ||
command = "docker" | ||
args = ["build", "-f", "node/Dockerfile", "-t", "miden-node-image", "."] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not setting the ENV
vars:
time="2024-03-14T13:29:04+01:00" level=warning msg="missing \"CREATED\" build argument. Try adding \"--build-arg CREATED=<VALUE>\" to the command line"
time="2024-03-14T13:29:04+01:00" level=warning msg="missing \"VERSION\" build argument. Try adding \"--build-arg VERSION=<VALUE>\" to the command line"
time="2024-03-14T13:29:04+01:00" level=warning msg="missing \"COMMIT\" build argument. Try adding \"--build-arg COMMIT=<VALUE>\" to the command line"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I am curious from what data you would want to populate these fields ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the version and created from the crate version and date
shell command.
I am not sure how you would like to get the commit info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The COMMIT
should have the git commit.
The VERSION
should have the node's software version.
The CREATED
should have the created timestamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where can i get the created
timestamp and the git commit
?
node/Dockerfile
Outdated
VOLUME db | ||
|
||
# Copy artifacts from the builder stage | ||
COPY --from=builder /app/node/miden-node.toml miden-node.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we can't change the configuration without having to rebuild all images. This is not good. This should be mounted from the host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I enabled the manual mounting of the file using the -v
flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes sense, so this file is the default, and the user can overwrite it with the flag 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Tested. Last thing we could do would be to improve caching to reduce build time of the image, created a issue so we can merge this PR and go forward: #277 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* Working initial docker * fmt * added script * Removed docker script + updated integration * script works * Need to install grpcurl * Docker works * Working Dockerfile * ci: turn doc warnings into errors (#259) * Removed makefile, removing start.sh file moving in Dockerfile * Added bookworm + alpine + removed gcc + added caching * Moved Dockerfile to node and added Makefile.toml * cargo make works + builds dockerfile for node * remove start script * added comment regarding PID1 * Set labels at top of Dockerfile + added comments * Added correct dependencies and explanation * Volume works persisting db files between runs * Added documentation * Moved labels + enable mounting of miden-node.toml * Added docker-run-node command + added build arguments * Add git commit as arg to docker container * Added spacing --------- Co-authored-by: Augusto Hack <[email protected]>
Docker will help us end-to-end test our code & enable easier sharing and installation of our code by our users.
Closes: #93