orf / gping

Ping, but with a graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to build the image with the Dockerfile?

mrjones-plip opened this issue · comments

Hi there! I'm trying to build an image with the included Dockerfile but get an error.

First I tried just building like so:

git clone  https://github.com/orf/gping.git
cd gping
docker build -f ../Dockerfile . -t gping

DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  1.372MB
Step 1/9 : FROM rust as builder
 ---> b13e19078869
Step 2/9 : WORKDIR /usr/src/gping
 ---> Using cache
 ---> 3ccc72e158e0
Step 3/9 : COPY src/ src/
COPY failed: file not found in build context or excluded by .dockerignore: stat src/: file does not exist

Noting the src directory it was looking for was in gping/src, I tried this:

git clone  https://github.com/orf/gping.git
cd gping/src
docker build -f ../Dockerfile . -t gping 
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  34.35kB
Step 1/9 : FROM rust as builder
 ---> b13e19078869
Step 2/9 : WORKDIR /usr/src/gping
 ---> Using cache
 ---> 3ccc72e158e0
Step 3/9 : COPY src/ src/
 ---> Using cache
 ---> e6be7f9dafba
Step 4/9 : COPY Cargo.* ./
 ---> Using cache
 ---> bf6903d44564
Step 5/9 : RUN cargo install --path .
 ---> Running in 3f5d388cb449
  Installing gping v1.12.0 (/usr/src/gping)
    Updating crates.io index
error: failed to compile `gping v1.12.0 (/usr/src/gping)`, intermediate artifacts can be found at `/usr/src/gping/target`

Caused by:
  failed to get `pinger` as a dependency of package `gping v1.12.0 (/usr/src/gping)`

Caused by:
  failed to load source for dependency `pinger`

Caused by:
  Unable to update /usr/src/pinger

Caused by:
  failed to read `/usr/src/pinger/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
The command '/bin/sh -c cargo install --path .' returned a non-zero code: 101

Hey, I forgot about the Dockerfile. It’s not been updated and no longer works. If you’re up for fixing that I’m happy to accept a pull request, otherwise I will probably just remove it.

I might could take a crack at a PR for a fix! I've never used rust - can you quickly enumerate the steps needed to compile outside of docker? I'll try and reproduce inside the container using the scaffold already in place.

Sure! To compile outside of docker you just need to run “cargo build —release” (or better yet, cargo install). There are likely other dockerfiles you can use as a reference: https://www.docker.com/blog/simplify-your-deployments-using-the-rust-official-image/ for example.

I think i'll have to give up on this. I tried a number of different ways, but couldn't get it to compile w/i docker.

My last attempt I had this docker file:

FROM rust as builder
WORKDIR /usr/src/
COPY * ./ 
RUN cargo install --path .

FROM debian:buster-slim
RUN apt-get update && apt-get install -y inetutils-ping && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/gping /usr/local/bin/gping
ENTRYPOINT ["gping"]

and this is the error I got:

docker build  . -t gping 
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  1.372MB
Step 1/8 : FROM rust as builder
 ---> b13e19078869
Step 2/8 : WORKDIR /usr/src/
 ---> Using cache
 ---> d5fe8420c837
Step 3/8 : COPY * ./
 ---> 8429bc8d551f
Step 4/8 : RUN cargo install --path .
 ---> Running in f2f7ccb1ff30
  Installing pinger v0.11.0 (/usr/src)
    Updating crates.io index
 Downloading crates ...
  Downloaded thiserror-impl v1.0.40
  Downloaded thiserror v1.0.40
  Downloaded quote v1.0.28
  Downloaded aho-corasick v1.0.1
  Downloaded syn v2.0.18
  Downloaded regex v1.8.3
  Downloaded unicode-ident v1.0.9
  Downloaded lazy_static v1.4.0
  Downloaded proc-macro2 v1.0.59
  Downloaded memchr v2.5.0
  Downloaded anyhow v1.0.71
  Downloaded regex-syntax v0.7.2
   Compiling proc-macro2 v1.0.59
   Compiling quote v1.0.28
   Compiling unicode-ident v1.0.9
   Compiling memchr v2.5.0
   Compiling thiserror v1.0.40
   Compiling anyhow v1.0.71
   Compiling regex-syntax v0.7.2
   Compiling pinger v0.11.0 (/usr/src)
   Compiling lazy_static v1.4.0
error[E0433]: failed to resolve: use of undeclared crate or module `shadow_rs`
 --> build.rs:1:14
  |
1 | fn main() -> shadow_rs::SdResult<()> {
  |              ^^^^^^^^^ use of undeclared crate or module `shadow_rs`

error[E0433]: failed to resolve: use of undeclared crate or module `shadow_rs`
 --> build.rs:2:5
  |
2 |     shadow_rs::new()
  |     ^^^^^^^^^ use of undeclared crate or module `shadow_rs`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `pinger` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `pinger v0.11.0 (/usr/src)`, intermediate artifacts can be found at `/usr/src/target`

This is closed by #319, you should now be able to do:

docker run ghcr.io/orf/gping:master (package here).

The next time I do a release it should be tagged properly, right now only master is available.