Skip to content

Commit e1068f8

Browse files
committed
pipeline-manager: copy overriding Cargo.lock for each Rust compilation
The `Cargo.lock` at the root of the repository is copied overriding to `.feldera/compiler/rust-compilation/Cargo.lock` at the start of each Rust compilation. This is such that the crate versions are generally the same for both main repository and pipeline compilation, with the exception of differences between that will be decided ad-hoc by the latter each Rust compilation anew. Signed-off-by: Simon Kassing <simon.kassing@feldera.com>
1 parent 60fceb0 commit e1068f8

7 files changed

Lines changed: 41 additions & 10 deletions

File tree

Earthfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ build-pipeline-manager-container:
324324
COPY +build-manager/pipeline-manager .
325325
COPY +build-sql/sql2dbsp-jar-with-dependencies.jar database-stream-processor/sql-to-dbsp-compiler/SQL-compiler/target/
326326

327-
# Reuse `Cargo.lock` to ensure consistent crate versions.
328-
RUN mkdir -p .feldera/compiler/rust-compilation
329-
COPY --chown=feldera Cargo.lock .feldera/compiler/rust-compilation/Cargo.lock
327+
# Copy over `Cargo.lock` into home directory (copied overriding at each pipeline Rust compilation)
328+
COPY --chown=feldera Cargo.lock Cargo.lock
330329

331330
# Copy over demos
332331
RUN mkdir -p demos
@@ -347,8 +346,8 @@ build-pipeline-manager-container:
347346
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
348347
ENV PATH="$PATH:/home/feldera/.cargo/bin"
349348

350-
RUN ./pipeline-manager --bind-address=0.0.0.0 --sql-compiler-home=/home/feldera/database-stream-processor/sql-to-dbsp-compiler --compilation-profile=unoptimized --dbsp-override-path=/home/feldera/database-stream-processor --precompile
351-
ENTRYPOINT ["./pipeline-manager", "--bind-address=0.0.0.0", "--sql-compiler-home=/home/feldera/database-stream-processor/sql-to-dbsp-compiler", "--dbsp-override-path=/home/feldera/database-stream-processor", "--compilation-profile=unoptimized", "--demos-dir", "/home/feldera/demos"]
349+
RUN ./pipeline-manager --bind-address=0.0.0.0 --sql-compiler-home=/home/feldera/database-stream-processor/sql-to-dbsp-compiler --compilation-cargo-lock-path=/home/feldera/Cargo.lock --compilation-profile=unoptimized --dbsp-override-path=/home/feldera/database-stream-processor --precompile
350+
ENTRYPOINT ["./pipeline-manager", "--bind-address=0.0.0.0", "--sql-compiler-home=/home/feldera/database-stream-processor/sql-to-dbsp-compiler", "--compilation-cargo-lock-path=/home/feldera/Cargo.lock", "--dbsp-override-path=/home/feldera/database-stream-processor", "--compilation-profile=unoptimized", "--demos-dir", "/home/feldera/demos"]
352351

353352
# Same as the above, but with a permissive CORS setting, else playwright doesn't work
354353
pipeline-manager-container-cors-all:

crates/pipeline-manager/src/compiler/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ mod test {
308308
compiler_working_directory: existing_path.to_string_lossy().to_string(),
309309
compilation_profile: CompilationProfile::Optimized,
310310
sql_compiler_home: "".to_string(),
311+
compilation_cargo_lock_path: "".to_string(),
311312
dbsp_override_path: "".to_string(),
312313
precompile: false,
313314
binary_ref_host: "".to_string(),
@@ -324,6 +325,7 @@ mod test {
324325
compiler_working_directory: non_existing_path.to_string_lossy().to_string(),
325326
compilation_profile: CompilationProfile::Optimized,
326327
sql_compiler_home: "".to_string(),
328+
compilation_cargo_lock_path: "".to_string(),
327329
dbsp_override_path: "".to_string(),
328330
precompile: false,
329331
binary_ref_host: "".to_string(),

crates/pipeline-manager/src/compiler/rust_compiler.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ fn calculate_source_checksum(
309309
"config.sql_compiler_home",
310310
config.sql_compiler_home.to_string().as_bytes(),
311311
),
312+
(
313+
"config.compilation_cargo_lock_path",
314+
config.compilation_cargo_lock_path.to_string().as_bytes(),
315+
),
312316
(
313317
"config.dbsp_override_path",
314318
config.dbsp_override_path.to_string().as_bytes(),
@@ -709,6 +713,14 @@ async fn prepare_workspace(
709713
.join("Cargo.toml");
710714
recreate_file_with_content(&cargo_toml_file_path, &cargo_toml).await?;
711715

716+
// Copy over the Cargo.lock such that it is the same for each compilation
717+
let cargo_lock_source_path = Path::new(&config.compilation_cargo_lock_path);
718+
let cargo_lock_target_path = config
719+
.working_dir()
720+
.join("rust-compilation")
721+
.join("Cargo.lock");
722+
copy_file(cargo_lock_source_path, &cargo_lock_target_path).await?;
723+
712724
Ok(())
713725
}
714726

@@ -1249,6 +1261,7 @@ mod test {
12491261
compiler_working_directory: "".to_string(),
12501262
compilation_profile: CompilationProfile::Dev,
12511263
sql_compiler_home: "".to_string(),
1264+
compilation_cargo_lock_path: "".to_string(),
12521265
dbsp_override_path: "".to_string(),
12531266
precompile: false,
12541267
binary_ref_host: "".to_string(),
@@ -1258,6 +1271,7 @@ mod test {
12581271
compiler_working_directory: "a".to_string(),
12591272
compilation_profile: CompilationProfile::Dev,
12601273
sql_compiler_home: "".to_string(),
1274+
compilation_cargo_lock_path: "".to_string(),
12611275
dbsp_override_path: "".to_string(),
12621276
precompile: false,
12631277
binary_ref_host: "".to_string(),
@@ -1267,6 +1281,7 @@ mod test {
12671281
compiler_working_directory: "".to_string(),
12681282
compilation_profile: CompilationProfile::Dev,
12691283
sql_compiler_home: "b".to_string(),
1284+
compilation_cargo_lock_path: "".to_string(),
12701285
dbsp_override_path: "".to_string(),
12711286
precompile: false,
12721287
binary_ref_host: "".to_string(),
@@ -1276,6 +1291,7 @@ mod test {
12761291
compiler_working_directory: "".to_string(),
12771292
compilation_profile: CompilationProfile::Dev,
12781293
sql_compiler_home: "".to_string(),
1294+
compilation_cargo_lock_path: "".to_string(),
12791295
dbsp_override_path: "c".to_string(),
12801296
precompile: false,
12811297
binary_ref_host: "".to_string(),

crates/pipeline-manager/src/compiler/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl CompilerTest {
3838
};
3939
let compiler_config = CompilerConfig {
4040
sql_compiler_home: "../../sql-to-dbsp-compiler".to_owned(),
41+
compilation_cargo_lock_path: "../../Cargo.lock".to_owned(),
4142
dbsp_override_path: "not-used".to_owned(),
4243
compilation_profile: CompilationProfile::Optimized,
4344
precompile: false,

crates/pipeline-manager/src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ fn default_sql_compiler_home() -> String {
106106
"sql-to-dbsp-compiler".to_string()
107107
}
108108

109+
/// Default location of the Rust compilation `Cargo.lock`.
110+
fn default_compilation_cargo_lock_path() -> String {
111+
"Cargo.lock".to_string()
112+
}
113+
109114
/// The default Rust compilation profile.
110115
fn default_compilation_profile() -> CompilationProfile {
111116
CompilationProfile::Optimized
@@ -353,6 +358,12 @@ pub struct CompilerConfig {
353358
#[arg(long, default_value_t = default_sql_compiler_home())]
354359
pub sql_compiler_home: String,
355360

361+
/// Location of the `Cargo.lock` file which will be copied overriding
362+
/// at each pipeline Rust compilation.
363+
#[serde(default = "default_compilation_cargo_lock_path")]
364+
#[arg(long, default_value_t = default_compilation_cargo_lock_path())]
365+
pub compilation_cargo_lock_path: String,
366+
356367
/// Override DBSP dependencies in generated Rust crates.
357368
///
358369
/// By default, the Rust crates generated by the SQL compiler depend on local
@@ -396,6 +407,8 @@ impl CompilerConfig {
396407
help_create_dir(&self.compiler_working_directory)?;
397408
self.compiler_working_directory = help_canonicalize_dir(&self.compiler_working_directory)?;
398409
self.sql_compiler_home = help_canonicalize_dir(&self.sql_compiler_home)?;
410+
self.compilation_cargo_lock_path =
411+
help_canonicalize_dir(&self.compilation_cargo_lock_path)?;
399412
self.dbsp_override_path = help_canonicalize_dir(&self.dbsp_override_path)?;
400413
Ok(self)
401414
}

crates/pipeline-manager/src/integration_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ async fn initialize_local_pipeline_manager_instance() -> TempDir {
118118
let compiler_config = CompilerConfig {
119119
compiler_working_directory: workdir.join("compiler").to_string_lossy().to_string(),
120120
sql_compiler_home: "../../sql-to-dbsp-compiler".to_owned(),
121+
compilation_cargo_lock_path: "../../Cargo.lock".to_owned(),
121122
dbsp_override_path: "../../".to_owned(),
122123
compilation_profile: CompilationProfile::Unoptimized,
123124
precompile: true,

deploy/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ COPY --from=builder /app/target/release/pipeline-manager pipeline-manager
111111
RUN mkdir -p lib/sql-to-dbsp-compiler/SQL-compiler/target
112112
COPY --from=javabuild /sql/sql-to-dbsp-compiler/SQL-compiler/target/sql2dbsp-jar-with-dependencies.jar lib/sql-to-dbsp-compiler/SQL-compiler/target/sql2dbsp-jar-with-dependencies.jar
113113

114-
# Reuse `Cargo.lock` to ensure consistent crate versions.
115-
RUN mkdir -p .feldera/compiler/rust-compilation
116-
COPY --chown=feldera Cargo.lock .feldera/compiler/rust-compilation/Cargo.lock
114+
# Copy over `Cargo.lock` into home directory (copied overriding at each pipeline Rust compilation)
115+
COPY --chown=feldera Cargo.lock Cargo.lock
117116

118117
# Copy over demos
119118
RUN mkdir -p demos
@@ -140,6 +139,6 @@ RUN arch=`dpkg --print-architecture | sed "s/arm64/aarch64/g" | sed "s/amd64/x86
140139
ENV PATH="$PATH:/home/feldera/.cargo/bin:/home/feldera/mold/bin"
141140
ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold"
142141
# Run the precompile phase to speed up Rust compilations during deployment
143-
RUN ./pipeline-manager --bind-address=0.0.0.0 --sql-compiler-home=/home/feldera/lib/sql-to-dbsp-compiler --dbsp-override-path=/home/feldera/lib --precompile
142+
RUN ./pipeline-manager --bind-address=0.0.0.0 --sql-compiler-home=/home/feldera/lib/sql-to-dbsp-compiler --compilation-cargo-lock-path=/home/feldera/Cargo.lock --dbsp-override-path=/home/feldera/lib --precompile
144143
ENV BANNER_ADDR=localhost
145-
ENTRYPOINT ["./pipeline-manager", "--bind-address=0.0.0.0", "--sql-compiler-home=/home/feldera/lib/sql-to-dbsp-compiler", "--dbsp-override-path=/home/feldera/lib", "--demos-dir", "/home/feldera/demos"]
144+
ENTRYPOINT ["./pipeline-manager", "--bind-address=0.0.0.0", "--sql-compiler-home=/home/feldera/lib/sql-to-dbsp-compiler", "--compilation-cargo-lock-path=/home/feldera/Cargo.lock", "--dbsp-override-path=/home/feldera/lib", "--demos-dir", "/home/feldera/demos"]

0 commit comments

Comments
 (0)