From e449476aab033ca5fe176e1cbbcc6f5da066ecd3 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Tue, 28 Jun 2022 10:01:35 -0500 Subject: [PATCH] Add dockerfile for cross. 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 #667. --- .github/workflows/ci.yml | 15 ++++++++++++++- CHANGELOG.md | 4 ++++ ci/test-cross-image.sh | 23 +++++++++++++++++++++++ docker/Dockerfile.cross | 22 ++++++++++++++++++++++ docker/cross.sh | 23 +++++++++++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 ci/test-cross-image.sh create mode 100644 docker/Dockerfile.cross create mode 100755 docker/cross.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3083e4cd1..aaefc5f7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,6 +204,7 @@ 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 } build: name: target (${{ matrix.pretty }},${{ matrix.os }}) @@ -270,7 +271,7 @@ jobs: IMAGE: ${{ steps.build-docker-image.outputs.image }} shell: bash - name: Test Image - if: steps.prepare-meta.outputs.has-image && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/trying') + if: (steps.prepare-meta.outputs.has-image && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/trying')) && matrix.target != 'cross' run: ./ci/test.sh env: TARGET: ${{ matrix.target }} @@ -287,6 +288,18 @@ jobs: target: ${{ matrix.target }} image: ${{ steps.build-docker-image.outputs.image }} + - name: Test Cross Image + if: (steps.prepare-meta.outputs.has-image && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/trying')) && matrix.target == 'cross' + run: ./ci/test-cross-image.sh + env: + TARGET: 'aarch64-unknown-linux-gnu' + shell: bash + - uses: ./.github/actions/cargo-install-upload-artifacts + if: matrix.deploy + with: + target: ${{ matrix.target }} + image: ${{ steps.build-docker-image.outputs.image }} + - name: Login to GitHub Container Registry if: steps.prepare-meta.outputs.has-image uses: docker/login-action@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b46ba777..884aa1cbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +### Added + +- #878 - added a dockerfile containing cross. + ### Changed - #869 - ensure cargo configuration environment variable flags are passed to the docker container. diff --git a/ci/test-cross-image.sh b/ci/test-cross-image.sh new file mode 100755 index 000000000..c4004bfe0 --- /dev/null +++ b/ci/test-cross-image.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2086 + +set -x +set -eo pipefail + +if [[ -z "${TARGET}" ]]; then + export TARGET="aarch64-unknown-linux-gnu" +fi + +main() { + docker run --rm -e TARGET \ + -v /var/run/docker.sock:/var/run/docker.sock \ + ghcr.io/cross-rs/cross:main sh -c ' +#!/usr/bin/env sh +td="$(mktemp -d)" +git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}" +cd "${td}" +cross run --target "${TARGET}" +' +} + +main "${@}" diff --git a/docker/Dockerfile.cross b/docker/Dockerfile.cross new file mode 100644 index 000000000..07c62f2e9 --- /dev/null +++ b/docker/Dockerfile.cross @@ -0,0 +1,22 @@ +# we build our images in 2 steps, to ensure we have a compact +# image, since we want to add our current subdirectory + +FROM ubuntu:20.04 as rust +ARG DEBIAN_FRONTEND=noninteractive +COPY lib.sh cross.sh / +RUN /cross.sh + +FROM ubuntu:20.04 +COPY --from=rust /root/.cargo /root/.cargo +COPY --from=rust /root/.rustup /root/.rustup + +# need some basic devtools, and requirements for docker +RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ + ca-certificates \ + curl \ + git + +RUN curl -fsSL https://get.docker.com | sh + +ENV CROSS_CONTAINER_IN_CONTAINER=1 \ + PATH=/root/.cargo/bin:$PATH diff --git a/docker/cross.sh b/docker/cross.sh new file mode 100755 index 000000000..80054f2f2 --- /dev/null +++ b/docker/cross.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# shellcheck disable=SC1091 + +set -x +set -euo pipefail + +. lib.sh + +main() { + install_packages ca-certificates curl gcc libc6-dev + + # since we can't share outside the current docker context, + # we need to install from git, rather than from path + curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + source "$HOME"/.cargo/env + cargo install cross --git https://github.com/cross-rs/cross --locked + + purge_packages + + rm -rf "${0}" +} + +main "${@}"