Skip to content

Add secondary Nix-based build system #212

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

Merged
merged 5 commits into from
Feb 13, 2023
Merged

Add secondary Nix-based build system #212

merged 5 commits into from
Feb 13, 2023

Conversation

nightkr
Copy link
Member

@nightkr nightkr commented Nov 24, 2022

This won't be used for prod builds (for now), but allows Nix to cache library builds, which gives us much faster feedback loops during development (for operators that need to run inside of the K8s cluster).

This is based on (and obsoletes) the Nix build system from secret-op and listener-op.

This requires some minor changes to the operator, such as the following for Airflow:

diff --git a/rust/operator-binary/build.rs b/rust/operator-binary/build.rs
index c1b491b..a2564dd 100644
--- a/rust/operator-binary/build.rs
+++ b/rust/operator-binary/build.rs
@@ -1,10 +1,18 @@
-use stackable_airflow_crd::airflowdb::AirflowDB;
-use stackable_airflow_crd::AirflowCluster;
+use stackable_airflow_crd::{airflowdb::AirflowDB, AirflowCluster};
 use stackable_operator::crd::CustomResourceExt;
+use std::path::PathBuf;
 
 fn main() {
-    built::write_built_file().expect("Failed to acquire build-time information");
+    let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR is required"));
+    built::write_built_file_with_opts(
+        // built's env module depends on a whole bunch of variables that crate2nix doesn't provide
+        // so we grab the specific env variables that we care about out ourselves instead.
+        built::Options::default().set_env(false),
+        "Cargo.toml".as_ref(),
+        &out_dir.join("built.rs"),
+    )
+    .unwrap();
 
-    AirflowCluster::write_yaml_schema("../../deploy/crd/airflowcluster.crd.yaml").unwrap();
-    AirflowDB::write_yaml_schema("../../deploy/crd/airflowdb.crd.yaml").unwrap();
+    // AirflowCluster::write_yaml_schema("../../deploy/crd/airflowcluster.crd.yaml").unwrap();
+    // AirflowDB::write_yaml_schema("../../deploy/crd/airflowdb.crd.yaml").unwrap();
 }
diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs
index 654a92c..2cd1dd5 100644
--- a/rust/operator-binary/src/main.rs
+++ b/rust/operator-binary/src/main.rs
@@ -6,7 +6,7 @@ mod util;
 
 use crate::airflow_controller::AIRFLOW_CONTROLLER_NAME;
 
-use clap::Parser;
+use clap::{crate_description, crate_version, Parser};
 use futures::StreamExt;
 use stackable_airflow_crd::{
     airflowdb::{AirflowDB, AIRFLOW_DB_CONTROLLER_NAME},
@@ -32,10 +32,11 @@ use std::sync::Arc;
 
 mod built_info {
     include!(concat!(env!("OUT_DIR"), "/built.rs"));
+    pub const TARGET: Option<&str> = option_env!("TARGET");
 }
 
 #[derive(Parser)]
-#[clap(about = built_info::PKG_DESCRIPTION, author = stackable_operator::cli::AUTHOR)]
+#[clap(about, author)]
 struct Opts {
     #[clap(subcommand)]
     cmd: Command,
@@ -61,10 +62,10 @@ async fn main() -> anyhow::Result<()> {
                 tracing_target,
             );
             stackable_operator::utils::print_startup_string(
-                built_info::PKG_DESCRIPTION,
-                built_info::PKG_VERSION,
+                crate_description!(),
+                crate_version!(),
                 built_info::GIT_VERSION,
-                built_info::TARGET,
+                built_info::TARGET.unwrap_or("unknown target"),
                 built_info::BUILT_TIME_UTC,
                 built_info::RUSTC_VERSION,
             );

@nightkr
Copy link
Member Author

nightkr commented Nov 25, 2022

I have tested a bit against darwin/macOS and the basic principles still work (using a remote Linux builder). However, there are some surrounding papercuts that need to be resolved for that setup to be usable (for example, we need to configure the target platform, streamLayeredImage produces a Linux-only script that won't run on darwin, and crate2nix doesn't build native darwin binaries correctly because of some dependency issues).

soenkeliebau added a commit to stackabletech/hdfs-operator that referenced this pull request Feb 12, 2023
In stackabletech/operator-templating#212 we are planning to add a more developer friendly workflow for building and deploying artifacts to Kubernetes during development.

This workflow uses crate2nix, which uses rustc directly and does not provide all environment variables required by the built crate we use (see nix-community/crate2nix#158).
The content of these PR are the fixes needed to work around those limitations.
soenkeliebau added a commit to stackabletech/documentation that referenced this pull request Feb 12, 2023
 - Only add properties.yaml if it exists
 - Correctly calculate port for Tilt instead of using string concatenation
@soenkeliebau
Copy link
Member

addressed comments @nightkr

@nightkr
Copy link
Member Author

nightkr commented Feb 13, 2023

LGTM now. I can't approve since it was my PR originally.

@soenkeliebau
Copy link
Member

I can :)

@nightkr
Copy link
Member Author

nightkr commented Feb 13, 2023

Want the honours of merging/starting the rollout? :P

@soenkeliebau
Copy link
Member

I only did some drudge work here, its your brainchild :)

@nightkr nightkr merged commit abda0c0 into main Feb 13, 2023
@nightkr nightkr deleted the spike/nixify branch February 13, 2023 15:29
@soenkeliebau
Copy link
Member

Should we try and get stackabletech/hdfs-operator#312 in as well, to give people something to test with?

bors bot pushed a commit to stackabletech/hdfs-operator that referenced this pull request Feb 13, 2023
# Description

In stackabletech/operator-templating#212 we are planning to add a more developer friendly workflow for building and deploying artifacts to Kubernetes during development.

This workflow uses crate2nix, which uses rustc directly and does not provide all environment variables required by the built crate we use (see nix-community/crate2nix#158). The content of these PR are the fixes needed to work around those limitations.
bors bot pushed a commit to stackabletech/hdfs-operator that referenced this pull request Feb 13, 2023
# Description

In stackabletech/operator-templating#212 we are planning to add a more developer friendly workflow for building and deploying artifacts to Kubernetes during development.

This workflow uses crate2nix, which uses rustc directly and does not provide all environment variables required by the built crate we use (see nix-community/crate2nix#158). The content of these PR are the fixes needed to work around those limitations.



Co-authored-by: Sönke Liebau <[email protected]>
soenkeliebau added a commit to stackabletech/documentation that referenced this pull request Feb 14, 2023
…the docs (#360)

* Adds explanation of crate2nix and tilt based development workflow to the docs.

For implementation, see:
 - stackabletech/operator-templating#212
 - stackabletech/hdfs-operator#312

Co-authored-by: Natalie <[email protected]>
bors bot pushed a commit to stackabletech/druid-operator that referenced this pull request Feb 15, 2023
bors bot pushed a commit to stackabletech/hbase-operator that referenced this pull request Feb 20, 2023
bors bot pushed a commit to stackabletech/airflow-operator that referenced this pull request Feb 21, 2023
bors bot pushed a commit to stackabletech/nifi-operator that referenced this pull request Feb 23, 2023
bors bot pushed a commit to stackabletech/spark-k8s-operator that referenced this pull request Feb 23, 2023
bors bot pushed a commit to stackabletech/hive-operator that referenced this pull request Feb 24, 2023
bors bot pushed a commit to stackabletech/superset-operator that referenced this pull request Feb 24, 2023
bors bot pushed a commit to stackabletech/opa-operator that referenced this pull request Mar 22, 2023
bors bot pushed a commit to stackabletech/trino-operator that referenced this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants