Im using cargo-wharf
to build my Rust project.
Cargo.toml:
# syntax = denzp/cargo-wharf-frontend:v0.1.0-alpha.2
[package]
name = "project_name"
version = "0.1.0"
edition = "2018"
[dependencies]
dep1 = {path = "../dep1", version = "0.2.0"}
...
[package.metadata.wharf.builder]
image = "clux/muslrust:nightly-2019-09-28"
target = "x86_64-unknown-linux-musl"
[package.metadata.wharf.output]
image = "scratch"
user = "root"
entrypoint = ["/usr/local/bin/project_name"]
[[package.metadata.wharf.binary]]
name = "project_name"
destination = "/usr/local/bin/project_name"
When I run docker build -f Cargo.toml . -t project_name
,
this error occurs:
[ ] Building 5.2s (11/11) FINISHED
=> [internal] load build definition from Cargo.toml 0.0s
=> => transferring dockerfile: 1.38kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/denzp/cargo-wharf-frontend:v0.1.0-alpha.2 3.3s
=> CACHED docker-image://docker.io/denzp/cargo-wharf-frontend:v0.1.0-alpha.2@sha256:a57861317aa7ae8010927d6e000c9be523d3b78c2b42f3e5c281c8cc3328b1a0 0.0s
=> Using build context 0.0s
=> => transferring dockerfile: 6.41kB 0.0s
=> CACHED docker-image://docker.io/denzp/cargo-container-tools:v0.2.0-alpha.1 0.0s
=> => resolve docker.io/denzp/cargo-container-tools:v0.2.0-alpha.1 0.7s
=> CACHED Collecting configuration metadata 0.0s
=> Resolving builder image 0.5s
=> Using build context 0.0s
=> => transferring context: 6.41kB 0.0s
=> CACHED docker-image://docker.io/clux/muslrust:nightly-2019-09-28@sha256:05cd14b73ae42a978d67a12e099eac8f6fe61daf2a963b7f401817a246ba4948 0.0s
=> ERROR Evaluating the build plan 0.3s
------
> Evaluating the build plan:
#11 0.259 error: failed to load source for a dependency on `dep1`
#11 0.259
#11 0.259 Caused by:
#11 0.259 Unable to update /dep1
#11 0.259
#11 0.259 Caused by:
#11 0.259 failed to read `/dep1/Cargo.toml`
#11 0.259
#11 0.259 Caused by:
#11 0.259 No such file or directory (os error 2)
#11 0.259 error: Child process failed
------
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = Unable to evaluate the Cargo build plan => caused by: Unable to read Cargo build plan => caused by: Unable to read the file => caused by: grpc-status: Unknown, grpc-message: "executor failed running [/usr/local/bin/cargo-build-plan --manifest-path /context/Cargo.toml --output /output/build-plan.json --target x86_64-unknown-linux-musl --release]: exit code: 1"
dep1
is a custom package that is at the same level as project_name
.
So it is C:\Users\me\shared_folder\project_name\Cargo.toml
and C:\Users\me\shared_folder\dep1\Cargo.toml
When running cargo run
from C:\Users\me\shared_folder\project_name\Cargo.toml
, everything just works fine.
I already tried:
- changing edition = "2018" as I read somewhere had no impact
- deleted Cargo.lock and target folder, also didn't work for me
Does anyone know how to get my program custom dependencies running in docker?
CodePudding user response:
I'm somewhat baffled that this is possible, but the solution to your problem is easy:
- You'll need to include the entire
shared_folder
(which contains bothlib1
andproject_name
) as build context, i.e. your build context must be..
not.
. Otherwise, the dockerized builder has no way of accessinglib1
. - You'll need to specify where to find your
Cargo.toml
since it's not in the working directory of the builder anymore. You could do that by adding a workspaceCargo.toml
toshared_folder
, but I think that using--build-arg manifest-path=…
is easier.
In summary:
buildx build -f Cargo.toml --build-arg manifest-path=project_name/Cargo.toml ..