Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

+ Dockerfile #107

Merged
merged 3 commits into from
Feb 3, 2019
Merged

+ Dockerfile #107

merged 3 commits into from
Feb 3, 2019

Conversation

grigio
Copy link

@grigio grigio commented Jan 28, 2019

Dockerfile as reported here #78 (comment)

@ravidio
Copy link
Contributor

ravidio commented Jan 31, 2019

Hi @grigio, thanks for the contribution!

I wanted to suggest a number of small changes, let me know what you think.

Thanks,
Ravid

  1. you might want to add a .dockerignore file to ignore the target dir.
  2. to better utilise docker caching it's sometimes advisable to build the dependencies first, and then the code as a second stage, here's an example of how it might work and will make consecutive builds much faster:
# create a new empty shell project
WORKDIR /
RUN USER=root cargo new --bin wallet713
WORKDIR /wallet713

# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# this build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs

COPY ./src ./src

RUN rm ./target/release/deps/wallet713*
RUN cargo build --release
  1. You should get rid of the EXPOSE statement as currently the wallet does not expose any ports.

@grigio
Copy link
Author

grigio commented Jan 31, 2019

Hi @ravidio , this Dockerfile basically is the one from Grin, but if can be improved I accept suggestions.

  1. you might want to add a .dockerignore file to ignore the target dir.

The builder image is just temporary image, but i don't think it would change much because the final image already only contains the needed runtime deps and the wallet713 binary.

wallet713/Dockerfile

Lines 27 to 45 in db1a4c8

FROM debian:9.4
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales openssl ca-certificates
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
COPY --from=builder /usr/src/wallet713/target/release/wallet713 /usr/local/bin/wallet713
WORKDIR /root/.wallet713
VOLUME ["/root/.wallet713"]
EXPOSE 3413 3414 3415 3416
ENTRYPOINT ["wallet713"]

You mean a .dockerignore like this ?

.git
/target/
Cargo.lock

2 ...

I'm not sure of that optimization. With COPY . . you have what you expect (inside and outside Docker)
Caching deps could be usefull if the container is used as development environment, but building from scratch it's also a test that you are using lastest available deps and that the deps are available.
@jaspervdm ?

I don't like to cp just some project parts and then rm other parts.

3

OK

@ravidio
Copy link
Contributor

ravidio commented Feb 1, 2019

Hi @grigio,

  1. re .dockerignore - I agree it would not affect the final run image, however having it and copying only the required files will build much faster, especially in situation where the docker daemon communicates to a remote machine or a VM. Most important is the target dir - so yes, it looks good, however the Cargo.lock is actually crucial to have in the docker builder image since it locks the dependencies to the currently supported version.

  2. Having 2 separate stages in the docker build process allows docker to cache each stage. So if you first build the dependencies and only then the source code, changes to only the source code (and to none of the dependencies) will make the build run very quickly as the dependencies stage could use the cache. I can suggest to make these changes after we commit your Dockerfile as is.

  3. Cool.

Let me know once you're ready and we can merge this in!

Thanks again,
Ravid

@ravidio ravidio merged commit 3264137 into vault713:master Feb 3, 2019
yyangli pushed a commit to mwcproject/mwc713 that referenced this pull request May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants