Skip to content

Conversation

bytedream
Copy link

@bytedream bytedream commented Mar 18, 2022

This adds a dockerfile which has cross and docker already installed and can be directly used to cross compile and test. It mostly adopts a comment in #260.

It uses docker in docker (#387) so to work correctly it must be run with the docker socket mounted as volume.

$ docker run -v /var/run/docker.sock:/var/run/docker.sock cross
root@1e27ac2ed941:/# git clone https://github.com/cross-rs/cross
root@1e27ac2ed941:/# cd cross
root@1e27ac2ed941:/cross# cross build --target aarch64-unknown-linux-gnu

Although the README already describes how to achieve this, a provided Dockerfile that can be downloaded from Docker Hub in the best case would be much easier than writing your own. Especially when using a CI pipeline inside Docker, where creating a custom Dockerfile is not that easy, this could be a big help.
The directory of the Dockerfile may not be the best choice since only compile targets are in this directory but it was the best fit.

@bytedream bytedream requested a review from a team as a code owner March 18, 2022 10:45

ENV CROSS_DOCKER_IN_DOCKER=true

RUN wget -O- https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz | tar -C /usr/bin/ --strip-components=1 -xzf - docker/docker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check signature or checksum here so we don't rely on the file being unmodified in future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not rare for tarball files to change behind the scene, so ensuring it is valid is a good security matter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Docker image we can copy the binary from instead using a multi-stage build?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a docker in docker image but it has some other binaries which are not necessary and rust has to be installed manually which takes more steps than this multi-stage build.
The docker in docker image receives it binaries from download.docker.com (layer 6) just like here, so there is no big difference when using the docker in docker image (besides the unwanted binaries which it has).

@bytedream
Copy link
Author

The checksum check is now implemented (md5) and it only checks the docker binary inside of the tarball since this is the only file which is needed.

otavio
otavio previously approved these changes Mar 19, 2022
RUN wget -O- https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz | tar -C /usr/bin/ --strip-components=1 -xzf - docker/docker
RUN echo $checksum | md5sum -c

RUN cargo install cross
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should install the current version in this repository.

@@ -7,4 +7,4 @@ ARG checksum="d9d9b964d428733e98c2579b91772af4 /usr/bin/docker"
RUN wget -O- https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz | tar -C /usr/bin/ --strip-components=1 -xzf - docker/docker
RUN echo $checksum | md5sum -c

RUN cargo install cross
RUN cargo install --git https://github.com/cross-rs/cross
Copy link
Member

@Emilgardis Emilgardis Mar 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong imo, I'd expect this to be built in our CI and published as ghcr.io/cross-rs/cross-in-docker (or similar).

it should also if anything use --locked

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this needs to be something like

COPY . .
RUN cargo install --path . --locked

@otavio
Copy link
Contributor

otavio commented Jun 11, 2022

@bytedream could you rebase and add a changelog entry? So we could trigger CI and see if it'll succeed.

@otavio otavio added this to the v0.2.2 milestone Jun 11, 2022
@Emilgardis Emilgardis removed this from the v0.2.2 milestone Jun 11, 2022
RUN wget -O- https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz | tar -C /usr/bin/ --strip-components=1 -xzf - docker/docker
RUN echo $checksum | md5sum -c

RUN cargo install --git https://github.com/cross-rs/cross
Copy link
Member

@Emilgardis Emilgardis Jun 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong, it should copy from the checked out code, if this is kept the CI will work, but it'll check the most recent main branch changes, not the proposed changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it should use the checkout for building, thanks @Emilgardis for raising this up.

Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image needs to be added

@@ -170,6 +170,8 @@ jobs:
- { target: thumbv7em-none-eabi, os: ubuntu-latest, std: 1 }
- { target: thumbv7em-none-eabihf, os: ubuntu-latest, std: 1 }
- { target: thumbv7m-none-eabi, os: ubuntu-latest, std: 1 }

- { target: cross os: ubuntu-latest }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work either sadly, it'll have to be it's own task/action for the image to be built and published

Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 27, 2022
This uses the official Docker docker-in-docker image for the latest
stable, and installs the latest stable Rust version internally. It uses
an entrypoint to ensure cargo is on the path, and that cross is
installed from the latest git (locked), which when tagged will work well
with our releases. It exports the environment variable
`CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 27, 2022
This uses the official Docker docker-in-docker image for the latest
stable, and installs the latest stable Rust version internally. It uses
an entrypoint to ensure cargo is on the path, and that cross is
installed from the latest git (locked), which when tagged will work well
with our releases. It exports the environment variable
`CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 27, 2022
This uses the official Docker docker-in-docker image for the latest
stable, and installs the latest stable Rust version internally. It uses
an entrypoint to ensure cargo is on the path, and that cross is
installed from the latest git (locked), which when tagged will work well
with our releases. It exports the environment variable
`CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest
Ubuntu image stable, and installs the latest stable Rust version
internally. Cross is installed from the latest git (locked), which when
tagged will work well with our releases. It exports the environment
variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as
expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest
Ubuntu image stable, and installs the latest stable Rust version
internally. Cross is installed from the latest git (locked), which when
tagged will work well with our releases. It exports the environment
variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as
expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 28, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 29, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 29, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 29, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 30, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 30, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jun 30, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jul 1, 2022
This uses the installs Docker from the official sources using the latest
Ubuntu image stable, and installs the latest stable Rust version
internally. Cross is installed from the latest git (locked), which when
tagged will work well with our releases. It exports the environment
variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as
expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jul 1, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jul 1, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
Alexhuszagh added a commit to Alexhuszagh/cross that referenced this pull request Jul 1, 2022
This uses the installs Docker from the official sources using the latest Ubuntu image stable, and installs the latest stable Rust version internally. Cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Replaces cross-rs#667.
bors bot added a commit that referenced this pull request Jul 5, 2022
878: Add dockerfile for cross. r=Emilgardis a=Alexhuszagh

This uses the official Docker docker-in-docker image for the latest stable, and installs the latest stable Rust version internally. It uses an entrypoint to ensure cargo is on the path, and that cross is installed from the latest git (locked), which when tagged will work well with our releases. It exports the environment variable `CROSS_CONTAINER_IN_CONTAINER` so everything should work as expected.

Closes #468.
Replaces #667.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
@Alexhuszagh
Copy link
Contributor

Closed since #878 as merged.

@Alexhuszagh Alexhuszagh closed this Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants