Skip to content

Instantly share code, notes, and snippets.

@olix0r
Last active November 4, 2019 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olix0r/cd34cdb9730e2e63a85e725135617011 to your computer and use it in GitHub Desktop.
Save olix0r/cd34cdb9730e2e63a85e725135617011 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -eq 0 ]; then
echo "usage: $0 [cargo options]" >&2
exit 64
fi
if [ ! -r Cargo.lock ]; then
echo "Not a cargo project: missing Cargo.lock" >&2
exit 1
fi
# buildx is still experimental by default.
export DOCKER_CLI_EXPERIMENTAL=enabled
# We don't actually need to (necessarily) push artifacts, but we need a valid
# repo we own. We sha the lockfile to bust the cache when dependencies change.
CACHE_REF="olix0r/cache:$(sha256sum Cargo.lock |cut -f1 -d' ')"
docker buildx build --load --cache-from="type=registry,ref=$CACHE_REF" --cache-to="type=registry,ref=$CACHE_REF" -f- . <<EOF
# syntax=docker/dockerfile:experimental
FROM rust:1.38.0-buster
COPY . .
RUN --mount=type=cache,target=\$CARGO_HOME --mount=type=cache,target=./target cargo $@
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment