Skip to content

Commit 488249e

Browse files
authored
Add --build-mode to net up --kubernetes (#3741)
## Motivation While debugging the deadlock last week, it was evident that building an image for a local `kind` deployment in debug mode was not straight forward ## Proposal Added `--build-mode` option to make this easier ## Test Plan Deployed locally, it works ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent 77ffcb8 commit 488249e

File tree

7 files changed

+54
-11
lines changed

7 files changed

+54
-11
lines changed

docker/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# - `target` is a Rust target quadruple. Currently known to be
1010
# supported are `x86_64-unknown-linux-gnu` and
1111
# `aarch64-unknown-linux-gnu`.
12+
# - `build_flag` is either "--release" or an empty string.
13+
# - `build_folder` is either "release" or "debug".
1214

1315
# Stage 1 - Generate recipe file for dependencies
1416

@@ -20,10 +22,14 @@ ARG build_date
2022
ARG target=x86_64-unknown-linux-gnu
2123
ARG binaries=
2224
ARG copy=${binaries:+_copy}
25+
ARG build_flag=
26+
ARG build_folder=
2327

2428
FROM rust:1.74-slim-bookworm AS builder
2529
ARG git_commit
2630
ARG target
31+
ARG build_flag
32+
ARG build_folder
2733

2834
RUN apt-get update && apt-get install -y \
2935
pkg-config \
@@ -58,17 +64,17 @@ COPY rust-toolchain* Cargo.* ./
5864

5965
ENV GIT_COMMIT=${git_commit}
6066

61-
RUN cargo build --release \
67+
RUN cargo build ${build_flag:+"$build_flag"} \
6268
--target "$target" \
6369
--bin linera \
6470
--bin linera-proxy \
6571
--bin linera-server \
6672
--features scylladb,metrics
6773

6874
RUN mv \
69-
target/"$target"/release/linera \
70-
target/"$target"/release/linera-proxy \
71-
target/"$target"/release/linera-server \
75+
target/"$target"/"$build_folder"/linera \
76+
target/"$target"/"$build_folder"/linera-proxy \
77+
target/"$target"/"$build_folder"/linera-server \
7278
./
7379

7480
RUN strip linera linera-proxy linera-server

docker/compose.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ cd "$ROOT_DIR"
3636
GIT_COMMIT=$(git rev-parse --short HEAD)
3737

3838
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
39-
docker build --build-arg git_commit="$GIT_COMMIT" -f docker/Dockerfile . -t linera || exit 1
39+
docker build --build-arg git_commit="$GIT_COMMIT" --build-arg build_flag="--release" --build-arg build_folder="release" -f docker/Dockerfile . -t linera || exit 1
4040
elif [[ "$OSTYPE" == "darwin"* ]]; then
4141
CPU_ARCH=$(sysctl -n machdep.cpu.brand_string)
4242
if [[ "$CPU_ARCH" == *"Apple"* ]]; then
43-
docker build --build-arg git_commit="$GIT_COMMIT" --build-arg target=aarch64-unknown-linux-gnu -f docker/Dockerfile -t linera . || exit 1
43+
docker build --build-arg git_commit="$GIT_COMMIT" --build-arg target=aarch64-unknown-linux-gnu --build-arg build_flag="--release" --build-arg build_folder="release" -f docker/Dockerfile -t linera . || exit 1
4444
else
4545
echo "Unsupported Architecture: $CPU_ARCH"
4646
exit 1

linera-service/src/cli_wrappers/docker.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ impl DockerImage {
1717
&self.name
1818
}
1919

20-
pub async fn build(name: &str, binaries: &BuildArg, github_root: &PathBuf) -> Result<Self> {
20+
pub async fn build(
21+
name: &str,
22+
binaries: &BuildArg,
23+
github_root: &PathBuf,
24+
build_mode: &str,
25+
) -> Result<Self> {
2126
let build_arg = match binaries {
2227
BuildArg::Directory(bin_path) => {
2328
// Get the binaries from the specified path
@@ -57,6 +62,19 @@ impl DockerImage {
5762
.args(["-f", "docker/Dockerfile"])
5863
.args(["--build-arg", &build_arg]);
5964

65+
match build_mode {
66+
"release" => {
67+
command.args(["--build-arg", "build_flag=--release"]);
68+
command.args(["--build-arg", "build_folder=release"]);
69+
}
70+
"debug" => {
71+
command.args(["--build-arg", "build_folder=debug"]);
72+
}
73+
_ => {
74+
return Err(anyhow::anyhow!("Invalid build mode: {}", build_mode));
75+
}
76+
}
77+
6078
#[cfg(not(with_testing))]
6179
command
6280
.args([

linera-service/src/cli_wrappers/local_kubernetes_net.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct LocalKubernetesNetConfig {
4848
pub binaries: BuildArg,
4949
pub no_build: bool,
5050
pub docker_image_name: String,
51+
pub build_mode: String,
5152
pub policy_config: ResourceControlPolicyConfig,
5253
}
5354

@@ -66,6 +67,7 @@ pub struct LocalKubernetesNet {
6667
binaries: BuildArg,
6768
no_build: bool,
6869
docker_image_name: String,
70+
build_mode: String,
6971
kubectl_instance: Arc<Mutex<KubectlInstance>>,
7072
kind_clusters: Vec<KindCluster>,
7173
num_initial_validators: usize,
@@ -102,6 +104,7 @@ impl SharedLocalKubernetesNetTestingConfig {
102104
binaries,
103105
no_build: false,
104106
docker_image_name: String::from("linera:latest"),
107+
build_mode: String::from("release"),
105108
policy_config: ResourceControlPolicyConfig::Testnet,
106109
})
107110
}
@@ -130,6 +133,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
130133
self.binaries,
131134
self.no_build,
132135
self.docker_image_name,
136+
self.build_mode,
133137
KubectlInstance::new(Vec::new()),
134138
clusters,
135139
self.num_initial_validators,
@@ -308,6 +312,7 @@ impl LocalKubernetesNet {
308312
binaries: BuildArg,
309313
no_build: bool,
310314
docker_image_name: String,
315+
build_mode: String,
311316
kubectl_instance: KubectlInstance,
312317
kind_clusters: Vec<KindCluster>,
313318
num_initial_validators: usize,
@@ -321,6 +326,7 @@ impl LocalKubernetesNet {
321326
binaries,
322327
no_build,
323328
docker_image_name,
329+
build_mode,
324330
kubectl_instance: Arc::new(Mutex::new(kubectl_instance)),
325331
kind_clusters,
326332
num_initial_validators,
@@ -401,7 +407,13 @@ impl LocalKubernetesNet {
401407
let docker_image_name = if self.no_build {
402408
self.docker_image_name.clone()
403409
} else {
404-
DockerImage::build(&self.docker_image_name, &self.binaries, &github_root).await?;
410+
DockerImage::build(
411+
&self.docker_image_name,
412+
&self.binaries,
413+
&github_root,
414+
&self.build_mode,
415+
)
416+
.await?;
405417
self.docker_image_name.clone()
406418
};
407419

linera-service/src/linera/command.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,11 @@ pub enum NetCommand {
918918
#[arg(long, default_value = "linera:latest")]
919919
docker_image_name: String,
920920

921+
/// The build mode to use.
922+
#[cfg(feature = "kubernetes")]
923+
#[arg(long, default_value = "release")]
924+
build_mode: String,
925+
921926
/// Run with a specific path where the wallet and validator input files are.
922927
/// If none, then a temporary directory is created.
923928
#[arg(long)]

linera-service/src/linera/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,17 +1807,16 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
18071807
shards,
18081808
testing_prng_seed,
18091809
policy_config,
1810-
cross_chain_config: _,
18111810
kubernetes: true,
18121811
binaries,
18131812
no_build,
18141813
docker_image_name,
1815-
path: _,
1816-
external_protocol: _,
1814+
build_mode,
18171815
with_faucet,
18181816
faucet_chain,
18191817
faucet_port,
18201818
faucet_amount,
1819+
..
18211820
} => {
18221821
net_up_utils::handle_net_up_kubernetes(
18231822
*other_initial_chains,
@@ -1828,6 +1827,7 @@ async fn run(options: &ClientOptions) -> Result<i32, Error> {
18281827
binaries,
18291828
*no_build,
18301829
docker_image_name.clone(),
1830+
build_mode.clone(),
18311831
*policy_config,
18321832
*with_faucet,
18331833
*faucet_chain,

linera-service/src/linera/net_up_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub async fn handle_net_up_kubernetes(
115115
binaries: &Option<Option<PathBuf>>,
116116
no_build: bool,
117117
docker_image_name: String,
118+
build_mode: String,
118119
policy_config: ResourceControlPolicyConfig,
119120
with_faucet: bool,
120121
faucet_chain: Option<u32>,
@@ -147,6 +148,7 @@ pub async fn handle_net_up_kubernetes(
147148
binaries: binaries.clone().into(),
148149
no_build,
149150
docker_image_name,
151+
build_mode,
150152
policy_config,
151153
};
152154
let (mut net, client) = config.instantiate().await?;

0 commit comments

Comments
 (0)