Skip to content

Commit

Permalink
feat: set containerfile rust version via makefile
Browse files Browse the repository at this point in the history
also set the RUSTUP_TOOLCHAIN env var via the dockerfile, and pass it to deployers
  • Loading branch information
oddgrd committed Dec 22, 2022
1 parent 0b43e77 commit bd20d9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#syntax=docker/dockerfile-upstream:1.4.0-rc1
FROM rust:1.65.0-buster as shuttle-build
ARG RUSTUP_TOOLCHAIN
FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build
RUN apt-get update &&\
apt-get install -y curl
# download protoc binary and unzip it in usr/bin
Expand All @@ -26,7 +27,8 @@ COPY --from=cache /build .
ARG folder
RUN cargo build --bin shuttle-${folder}

FROM rust:1.65.0-buster as shuttle-common
ARG RUSTUP_TOOLCHAIN
FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common
RUN apt-get update &&\
apt-get install -y curl
RUN rustup component add rust-src
Expand All @@ -37,4 +39,6 @@ ARG folder
COPY ${folder}/prepare.sh /prepare.sh
RUN /prepare.sh
COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service
ARG RUSTUP_TOOLCHAIN
ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN}
ENTRYPOINT ["/usr/local/bin/service"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ endif

BUILDX_FLAGS=$(BUILDX_OP) $(PLATFORM_FLAGS) $(CACHE_FLAGS)

# the rust version used by our containers
RUSTUP_TOOLCHAIN=1.65.0

TAG?=$(shell git describe --tags)
BACKEND_TAG?=$(TAG)
DEPLOYER_TAG?=$(TAG)
Expand Down Expand Up @@ -107,6 +110,7 @@ down: docker-compose.rendered.yml
shuttle-%: ${SRC} Cargo.lock
docker buildx build \
--build-arg folder=$(*) \
--build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \
--tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \
--tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \
--tag $(CONTAINER_REGISTRY)/$(*):latest \
Expand Down
2 changes: 1 addition & 1 deletion examples
11 changes: 3 additions & 8 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,8 @@ impl ProjectCreating {
name: self.container_name(ctx),
};

// Get the version of rustc gateway was compiled with, matching the deployer
// RUSTUP_TOOLCHAIN override with the version from our Containerfile
let rustc_version = rustc_version_runtime::version().to_string();
debug!(
"got installed rustc version for deployer toolchain override: {}",
rustc_version
);
let rustup_toolchain =
std::env::var("RUSTUP_TOOLCHAIN").expect("rustup toolchain should be set");

let container_config = self
.from
Expand Down Expand Up @@ -525,7 +520,7 @@ impl ProjectCreating {
"RUST_LOG=debug",
// If we don't set this, users' dependencies with a `rust-toolchain.toml`
// override will compile with incompatible versions of rust.
format!("RUSTUP_TOOLCHAIN={rustc_version}")
format!("RUSTUP_TOOLCHAIN={rustup_toolchain}")
]
})
});
Expand Down

0 comments on commit bd20d9e

Please sign in to comment.