Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build our images with the release profile #583

Merged
7 changes: 5 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ COPY --from=planner /build/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
COPY --from=cache /build .
ARG folder
RUN cargo build --bin shuttle-${folder}
ARG CARGO_PROFILE
# if CARGO_PROFILE is release, pass --release, else use default debug profile
RUN cargo build --bin shuttle-${folder} $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi)

ARG RUSTUP_TOOLCHAIN
FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common
Expand All @@ -43,7 +45,8 @@ FROM shuttle-common
ARG folder
COPY ${folder}/prepare.sh /prepare.sh
RUN /prepare.sh
COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service
ARG RUSTUP_TOOLCHAIN
ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN}
ENTRYPOINT ["/usr/local/bin/service"]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CONTAINER_REGISTRY=public.ecr.aws/shuttle
DD_ENV=production
# make sure we only ever go to production with `--tls=enable`
USE_TLS=enable
CARGO_PROFILE=release
else
DOCKER_COMPOSE_FILES=-f docker-compose.yml -f docker-compose.dev.yml
STACK?=shuttle-dev
Expand All @@ -57,6 +58,7 @@ DB_FQDN=db.unstable.shuttle.rs
CONTAINER_REGISTRY=public.ecr.aws/shuttle-dev
DD_ENV=unstable
USE_TLS?=disable
CARGO_PROFILE=debug
endif

POSTGRES_EXTRA_PATH?=./extras/postgres
Expand Down Expand Up @@ -112,6 +114,7 @@ shuttle-%: ${SRC} Cargo.lock
docker buildx build \
--build-arg folder=$(*) \
--build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \
--build-arg CARGO_PROFILE=$(CARGO_PROFILE) \
--tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \
--tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \
--tag $(CONTAINER_REGISTRY)/$(*):latest \
Expand Down
4 changes: 3 additions & 1 deletion codegen/src/next/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ pub(crate) fn wasi_bindings(app: App) -> proc_macro2::TokenStream {
let (parts, mut body) = res.into_parts();

// wrap and serialize response parts as rmp
let response_parts = shuttle_next::ResponseWrapper::from(parts).into_rmp();
let response_parts = shuttle_next::ResponseWrapper::from(parts)
.into_rmp()
.expect("failed to serialize response parts");

// write response parts
parts_fd.write_all(&response_parts).unwrap();
Expand Down
72 changes: 43 additions & 29 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,36 +287,50 @@ pub mod runtime {
Ok((runtime, runtime_client))
}

/// If the calling crate is cargo-shuttle, try to install shuttle-runtime from
/// a local version if this library is compiled in debug mode or from the production
/// branch of the shuttle repo if it's compiled in release mode.
///
/// If the calling crate is deployer, use the version of shuttle-runtime installed in
/// deployer/prepare.sh.
///
/// **Important:** When called by deployer, this function expects that shuttle-runtime
/// was installed in prepare.sh.
fn get_runtime_executable() -> PathBuf {
// When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`,
// install the checked-out local version of `shuttle-runtime
if cfg!(debug_assertions) {
// Path to cargo-shuttle
let manifest_dir = env!("CARGO_MANIFEST_DIR");

// Canonicalized path to shuttle-runtime
let path = std::fs::canonicalize(format!("{manifest_dir}/../runtime"))
.expect("failed to canonicalize path to runtime");

Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--path")
.arg(path)
.output()
.expect("failed to install the shuttle runtime");
// When this library is compiled in release mode with `cargo install cargo-shuttle`,
// install the latest released `shuttle-runtime`
} else {
Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--git")
.arg("https://github.com/shuttle-hq/shuttle")
.arg("--branch")
.arg("production")
.output()
.expect("failed to install the shuttle runtime");
let current_crate = env!("CARGO_PKG_NAME");

if current_crate == "cargo-shuttle" {
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
// When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`,
// install the checked-out local version of `shuttle-runtime
if cfg!(debug_assertions) {
// Path to calling crate root
let manifest_dir = env!("CARGO_MANIFEST_DIR");

// Canonicalized path to shuttle-runtime for dev to work on windows
let path = std::fs::canonicalize(format!("{manifest_dir}/../runtime"))
.expect("path to shuttle-runtime does not exist or is invalid");

Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--path")
.arg(path)
.output()
.expect("failed to install the shuttle runtime");

// When this library is compiled in release mode with `cargo install cargo-shuttle`,
// install the latest released `shuttle-runtime`
} else {
Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--git")
.arg("https://github.com/shuttle-hq/shuttle")
.arg("--branch")
.arg("production")
.output()
.expect("failed to install the shuttle runtime");
}
}

let cargo_home = home::cargo_home().expect("failed to find cargo home directory");
Expand Down
4 changes: 3 additions & 1 deletion runtime/tests/resources/axum-wasm-expanded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ pub extern "C" fn __SHUTTLE_Axum_call(
let (parts, mut body) = res.into_parts();

// wrap and serialize response parts as rmp
let response_parts = shuttle_next::ResponseWrapper::from(parts).into_rmp();
let response_parts = shuttle_next::ResponseWrapper::from(parts)
.into_rmp()
.expect("failed to serialize response parts");

// write response parts
parts_fd.write_all(&response_parts).unwrap();
Expand Down