Skip to content

Commit

Permalink
Add dockerfile for cross.
Browse files Browse the repository at this point in the history
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 #667.
  • Loading branch information
Alexhuszagh committed Jun 27, 2022
1 parent eb2b8ad commit fbfb7a0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ jobs:
- { target: thumbv7em-none-eabihf, os: ubuntu-latest, std: 1 }
- { target: thumbv7m-none-eabi, os: ubuntu-latest, std: 1 }
build-cross:
name: Build Cross
runs-on: ubuntu-latest
needs: [shellcheck, test, generate-matrix, check]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: Build xtask
run: cargo build -p xtask

- name: Build Docker image
id: build-docker-image
timeout-minutes: 15
run: cargo xtask build-docker-image cross

build:
name: target (${{ matrix.pretty }},${{ matrix.os }})
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -309,7 +325,7 @@ jobs:
shell: bash

publish:
needs: [build, check]
needs: [build, check, build-cross]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM docker:20.10-dind

RUN apk add curl bash libgcc gcc musl-dev git

RUN curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# need to ensure cargo is in the path when we run this command,
# since we won't be sourcing the profile.
RUN PATH="$HOME/.cargo/bin:$PATH" cargo install cross --git https://github.com/cross-rs/cross --locked

COPY cross-entry.sh /
ENTRYPOINT ["/cross-entry.sh"]
7 changes: 7 additions & 0 deletions docker/cross-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# shellcheck disable=SC1090
. ~/.cargo/env
export CROSS_CONTAINER_IN_CONTAINER=1

exec "${@}"
14 changes: 14 additions & 0 deletions docker/cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

main() {
apk add gcc curl musl-dev

curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
PATH="$HOME/.cargo/bin:$PATH" cargo install cross --git https://github.com/cross-rs/cross --locked

apk del gcc curl musl-dev

rm -rf "${0}"
}

main "${@}"

0 comments on commit fbfb7a0

Please sign in to comment.