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

Improve user story for creating a image/package with the cross compiled binary #1187

Open
1 of 2 tasks
Emilgardis opened this issue Jan 15, 2023 · 1 comment
Open
1 of 2 tasks

Comments

@Emilgardis
Copy link
Member

Emilgardis commented Jan 15, 2023

Checklist

Describe your request

We should provide a good story for doing something like

FROM magic_cross as cross
COPY . .
RUN cross build --release --target aarch64-unknown-linux-gnu

FROM ubuntu:20.04
COPY --from=cross ./target/release/binary .
CMD ["./binary"]

Describe why this would be a good inclusion for cross

This would make it easy to setup a dockerfile with the needed binary.

Today, this can be solved with

FROM ubuntu:20.04

COPY ./target/aarch64-unknown-linux-gnu/release/binary ./
CMD ["./binary"]
$ cross build --target aarch64-unknown-linux-gnu 
   Compiling binary v0.1.0 (/binary)
    Finished release [optimized] target(s) in 11.68s
$ docker build .
[+] Building 3.0s (7/7) FINISHED                                                                                                                                                                                     
 => [internal] load build definition from Dockerfile                                                                                                                                                            0.0s
 => => transferring dockerfile: 144B                                                                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                                                                                                                                 0.5s
 => [internal] load build context                                                                                                                                                                               0.1s
 => => transferring context: 4.32MB                                                                                                                                                                             0.1s
 => [1/2] FROM docker.io/library/ubuntu:20.04@sha256:0e0402cd13f68137edb0266e1d2c682f217814420f2d43d300ed8f65479b14fb                                                                                           2.3s
 => => resolve docker.io/library/ubuntu:20.04@sha256:0e0402cd13f68137edb0266e1d2c682f217814420f2d43d300ed8f65479b14fb                                                                                           0.0s
 => => sha256:0e0402cd13f68137edb0266e1d2c682f217814420f2d43d300ed8f65479b14fb 1.42kB / 1.42kB                                                                                                                  0.0s
 => => sha256:bfd9523988a26a8913fbced7d00b00805572d093c4d8cbc64252b45e032302d5 529B / 529B                                                                                                                      0.0s
 => => sha256:43ed104e759f96978d95473568dbaef829695dbade5c10be56f344948ab0caa1 1.48kB / 1.48kB                                                                                                                  0.0s
 => => sha256:f04b4bbe15805316c8fda79beedd3b77e6b1ffcd0acf81226c3089e63f6bffeb 27.19MB / 27.19MB                                                                                                                1.3s
 => => extracting sha256:f04b4bbe15805316c8fda79beedd3b77e6b1ffcd0acf81226c3089e63f6bffeb                                                                                                                       0.8s
 => [2/2] COPY ./target/aarch64-unknown-linux-gnu/release/binary ./                                                                                                                                         0.1s
 => exporting to image                                                                                                                                                                                          0.0s
 => => exporting layers                                                                                                                                                                                         0.0s
 => => writing image sha256:d45f5b6b5a01fbe01b3fe6d18a9b124c1586c0905ed92012bf3eb65dd18ae2b1    

Related

/r/rust ask a question comment
matrix discussion

@Emilgardis
Copy link
Member Author

The best solution would be

FROM ghcr.io/cross-rs/cross:edge as build
WORKDIR /build
COPY . .
RUN cross build --release --target aarch64-unknown-linux-gnu

FROM ubuntu:20.04

COPY --from=build ./target/release/binary ./
CMD ["./binary"]

and invoked with docker build -v /var/run/docker.sock:/var/run/docker.sock ., but docker build can't take a -v, and VOLUME binds at run time.

Technically, I think we could probably use CROSS_REMOTE with DOCKER_CONTEXT=tcp://host.docker.internal:2375 for this, but that seems like a bad idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant