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

Docker-in-Docker fails with Mounted Volumes in Workspaces #901

Closed
4 of 11 tasks
Alexhuszagh opened this issue Jul 2, 2022 · 1 comment · Fixed by #904
Closed
4 of 11 tasks

Docker-in-Docker fails with Mounted Volumes in Workspaces #901

Alexhuszagh opened this issue Jul 2, 2022 · 1 comment · Fixed by #904
Labels

Comments

@Alexhuszagh
Copy link
Contributor

Checklist

Describe your issue

When running docker-in-docker, if using a workspace and not at the root directory, the mounted volumes in the workspace are not properly adjusted to the the mounted prefix. This is because docker_mount does not use the mount finder.

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.2 (00c1de2)

Example

While testing the integration tests in #873, the following script fails, producing the subsequent output:

Script

#!/usr/bin/env bash

# test to see that running docker-in-docker works

set -x
set -eo pipefail

if [[ -z "${TARGET}" ]]; then
    export TARGET="aarch64-unknown-linux-gnu"
fi

source=$(dirname "${BASH_SOURCE[0]}")
source=$(realpath "${source}")
home=$(dirname "${source}")

main() {
    docker run -v "${home}":/project \
        -w /project --rm -e TARGET \
        -v /var/run/docker.sock:/var/run/docker.sock \
        docker:18.09-dind sh -c '
#!/usr/bin/env sh
set -x
set -euo pipefail

apk add curl
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "${HOME}/.cargo/env"

# building on release is slow
apk add libgcc gcc musl-dev
cargo test --workspace
cargo install --path . --force --debug

export CROSS_CONTAINER_IN_CONTAINER=1

apk add git
td="$(mktemp -d)"
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
cd "${td}"
cross run --target "${TARGET}" --verbose

td="$(mktemp -d)"
git clone --depth 1 https://github.com/cross-rs/test-workspace "${td}"
cd "${td}"
cross build --target "${TARGET}" --workspace \
    --manifest-path="./workspace/Cargo.toml" --verbose
cd workspace
cross build --target "${TARGET}" --workspace --verbose
cd binary
cross run --target "${TARGET}" --verbose
'
}

main

Output

/usr/local/bin/docker run --userns host -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/xargo' -e 'CARGO_HOME=/cargo' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e 'USER=root' -v /tmp/tmp.hppfjI/external/external_lib:/tmp/tmp.hppfjI/external/external_lib --rm --user 0:0 -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.xargo:/xargo:Z -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.cargo:/cargo:Z -v /cargo/bin -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace:/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace:Z -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:/rust:Z,ro -v /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace/target:/target:Z -w /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.2 sh -c 'PATH=$PATH:/rust/bin cargo build --target aarch64-unknown-linux-gnu --workspace --verbose'
error: failed to load manifest for workspace member `/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/workspace/binary`

Caused by:
  failed to load manifest for dependency `test-workspace`

Caused by:
  failed to load manifest for dependency `external_lib`

Caused by:
  failed to read `/var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/external/external_lib/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

We can see that external_lib is mounted at /tmp/tmp.hppfjI/external/external_lib:/tmp/tmp.hppfjI/external/external_lib , and not at /var/lib/docker/overlay2/4f20476a48228131897c42ce45df9e9ef74864fc590040ebfa4bce7f086f375e/merged/tmp/tmp.hppfjI/test-workspace/external/external_lib/. Likewise, we only mount workspace, and not test-workspace.

Additional information / notes

No response

@Emilgardis
Copy link
Member

nice! this should be an easy fix though

@Emilgardis Emilgardis self-assigned this Jul 3, 2022
@Emilgardis Emilgardis removed their assignment Jul 3, 2022
@bors bors bot closed this as completed in 74c3ba6 Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants