Skip to content

Commit

Permalink
have a go at testing Dockerfile.context
Browse files Browse the repository at this point in the history
Feels wrong somehow.
  • Loading branch information
alsuren committed Dec 22, 2020
1 parent cd158ba commit 2741964
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 39 deletions.
1 change: 0 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ jobs:
condition: eq(variables['OS'], 'linux')
- bash: ci/test.sh
displayName: Test
condition: ne(variables['TARGET'], 'context')
- bash: cargo publish
displayName: Publish on crates.io
env:
Expand Down
16 changes: 15 additions & 1 deletion build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@ run() {
fi
fi

docker build ${cache_from_args[@]+"${cache_from_args[@]}"} --pull -t "${image_name}" -f "${dockerfile}" .
if [[ "${PULL:-1}" = "1" ]]; then
docker build ${cache_from_args[@]+"${cache_from_args[@]}"} --pull -t "${image_name}" -f "${dockerfile}" .
else
docker build ${cache_from_args[@]+"${cache_from_args[@]}"} -t "${image_name}" -f "${dockerfile}" .
fi

if ! [[ "${version}" =~ alpha ]] && ! [[ "${version}" =~ dev ]]; then
local versioned_image_name="${image_name}-${version}"
docker tag "${image_name}" "${versioned_image_name}"
fi

if [[ "${1}" = "context" ]]; then
# complex pipelines read better top to bottom
# shellcheck disable=SC2002
cat Dockerfile.context \
| sed -nE "s/^## ?//p" \
| sed "s@rustembedded/cross:context@${versioned_image_name}@" \
> Dockerfile.context.doctest
PULL=0 run context.doctest
fi
}

if [[ -z "${*}" ]]; then
Expand Down
21 changes: 21 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@ function retry {
return ${exit_code}
}

function setup_image() {
if [[ "${IMAGE:-}" != "" ]]; then
cat >> Cross.toml <<EOF
[target.arm-unknown-linux-gnueabihf]
image = "$IMAGE"
EOF
fi
}

main() {
local td=

if [[ "${BRANCH-}" = master ]] || [[ "${TAG-}" =~ ^v.* ]]; then
return
fi

if [[ "${TARGET}" == context ]]; then
IMAGE="rustembedded/cross:context.doctest"
TARGET="arm-unknown-linux-gnueabihf"
fi

retry cargo fetch
cargo install --force --path .


export QEMU_STRACE=1

if (( ${STD:-0} )); then
Expand All @@ -43,6 +58,7 @@ main() {
cargo init --lib --name foo "${td}"
pushd "${td}"
echo '#![no_std]' > src/lib.rs
setup_image
cross check --target "${TARGET}"
popd
rm -rf "${td}"
Expand Down Expand Up @@ -76,6 +92,7 @@ EOF
pushd "${td}"
cargo init --lib --name foo .
retry cargo fetch
setup_image
cross build --target "${TARGET}"
popd

Expand All @@ -87,6 +104,7 @@ EOF
# test that linking works
cargo init --bin --name hello .
retry cargo fetch
setup_image
cross build --target "${TARGET}"
popd

Expand All @@ -100,6 +118,7 @@ EOF

pushd "${td}"
cargo init --lib --name foo .
setup_image
cross_test --target "${TARGET}"
cross_bench --target "${TARGET}"
popd
Expand Down Expand Up @@ -132,6 +151,7 @@ EOF
mkdir examples tests
echo "fn main() { println!(\"Example!\"); }" > examples/e.rs
echo "#[test] fn t() {}" > tests/t.rs
setup_image
cross_run --target "${TARGET}"
cross_run --target "${TARGET}" --example e
cross_test --target "${TARGET}"
Expand All @@ -153,6 +173,7 @@ EOF
pushd "${td}"
cargo update -p gcc
retry cargo fetch
setup_image
if (( ${RUN:-0} )); then
cross_run --target "${TARGET}"
else
Expand Down
74 changes: 37 additions & 37 deletions docker/Dockerfile.context
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# This dockerfile creates a thin docker image that can be used for making custom
# cross Dockerfiles that live in other git repositories.
# It has been uploaded to `alsuren/cross-context` so it can be used like so:
# It has been uploaded to `rustembedded/cross:context` so it can be used like so:

## Fetch this image and use it as `context`:
# FROM alsuren/cross-context:latest as context
#
## Continue as normal, but copying `--from=context` rather than from your filesystem.
# FROM ubuntu:16.04
#
# COPY --from=context common.sh lib.sh /
# RUN /common.sh
#
# COPY --from=context cmake.sh /
# RUN /cmake.sh
#
# COPY --from=context xargo.sh /
# RUN /xargo.sh
#
# RUN apt-get install --assume-yes --no-install-recommends \
# g++-arm-linux-gnueabihf \
# libc6-dev-armhf-cross
#
# COPY --from=context qemu.sh /
# RUN /qemu.sh arm softmmu
#
# COPY --from=context dropbear.sh /
# RUN /dropbear.sh
#
# COPY --from=context linux-image.sh /
# RUN /linux-image.sh armv7
#
# COPY --from=context linux-runner /
#
# ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
# CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="/linux-runner armv7" \
# CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
# CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
# QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
# RUST_TEST_THREADS=1
### Fetch this image and use it as `context`:
## FROM rustembedded/cross:context as context
##
### Continue as normal, but copying `--from=context` rather than from your filesystem.
## FROM ubuntu:16.04
##
## COPY --from=context common.sh lib.sh /
## RUN /common.sh
##
## COPY --from=context cmake.sh /
## RUN /cmake.sh
##
## COPY --from=context xargo.sh /
## RUN /xargo.sh
##
## RUN apt-get install --assume-yes --no-install-recommends \
## g++-arm-linux-gnueabihf \
## libc6-dev-armhf-cross
##
## COPY --from=context qemu.sh /
## RUN /qemu.sh arm softmmu
##
## COPY --from=context dropbear.sh /
## RUN /dropbear.sh
##
## COPY --from=context linux-image.sh /
## RUN /linux-image.sh armv7
##
## COPY --from=context linux-runner /
##
## ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
## CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="/linux-runner armv7" \
## CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
## CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
## QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
## RUST_TEST_THREADS=1
FROM scratch

COPY common.sh lib.sh /
Expand Down

0 comments on commit 2741964

Please sign in to comment.