-
Notifications
You must be signed in to change notification settings - Fork 0
feat(relay): promote attribute release to default #488
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
Changes from all commits
5e20ddf
fce408d
ad7fad5
b663f1d
3740ebe
2775956
83a96d0
2912d38
9e15035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
|
|
||
| ARG REGISTRY_RELAY_FEATURES="attribute-release,crosswalk-runtime" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After making the Docker ARG non-empty by default, Useful? React with 👍 / 👎. |
||
|
|
||
| # Keep the tag for humans and the digest for reproducible pulls. | ||
| FROM rust:1.95-trixie@sha256:f49565f188ee00bc2a18dd418183f2c5f23ef7d6e691890517ed341a598f67c3 AS builder | ||
| ARG REGISTRY_RELAY_FEATURES | ||
| WORKDIR /workspace/registry_relay | ||
|
|
||
| COPY Cargo.toml Cargo.lock ./ | ||
|
|
@@ -13,16 +16,19 @@ COPY --from=crosswalk /Cargo.toml /Cargo.lock /workspace/crosswalk/ | |
| COPY --from=crosswalk /crates /workspace/crosswalk/crates | ||
| COPY benches ./benches | ||
| COPY resources ./resources | ||
| COPY build.rs build_support.rs ./ | ||
| COPY scripts/validate-feature-profile.sh ./scripts/validate-feature-profile.sh | ||
| COPY src ./src | ||
|
|
||
| ARG REGISTRY_RELAY_FEATURES="" | ||
| RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
| --mount=type=cache,target=/workspace/registry_relay/target \ | ||
| find src benches resources -type f -exec touch {} + && \ | ||
| sh scripts/validate-feature-profile.sh "$REGISTRY_RELAY_FEATURES" && \ | ||
| if [ -n "$REGISTRY_RELAY_FEATURES" ]; then \ | ||
| cargo build --release --locked --features "$REGISTRY_RELAY_FEATURES"; \ | ||
| REGISTRY_RELAY_FEATURES="$REGISTRY_RELAY_FEATURES" \ | ||
| cargo build --release --locked --no-default-features --features "$REGISTRY_RELAY_FEATURES"; \ | ||
| else \ | ||
| cargo build --release --locked; \ | ||
| REGISTRY_RELAY_FEATURES="" cargo build --release --locked --no-default-features; \ | ||
| fi && \ | ||
| cp /workspace/registry_relay/target/release/registry-relay /usr/local/bin/registry-relay && \ | ||
| cp /workspace/registry_relay/target/release/registry-relay-rhai-worker /usr/local/bin/registry-relay-rhai-worker && \ | ||
|
|
@@ -35,11 +41,13 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ | |
|
|
||
| # Distroless cc keeps glibc and CA certificates while dropping shell/package tools. | ||
| FROM gcr.io/distroless/cc-debian13:nonroot@sha256:d97bc0a941b8d4be647dc0ee75b264ddbb772f1ac5ba690a4309c00723b23775 AS runtime | ||
| ARG REGISTRY_RELAY_FEATURES | ||
|
|
||
| COPY --from=builder --chown=65532:65532 /workspace/runtime-root/ / | ||
| COPY --from=builder /usr/local/bin/registry-relay /usr/local/bin/registry-relay | ||
| COPY --from=builder /usr/local/bin/registry-relay-rhai-worker /usr/local/bin/registry-relay-rhai-worker | ||
| COPY LICENSE /licenses/registry-relay/LICENSE | ||
| LABEL org.registrystack.registry-relay.features="${REGISTRY_RELAY_FEATURES}" | ||
|
jeremi marked this conversation as resolved.
|
||
|
|
||
| WORKDIR /var/lib/registry-relay | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| mod build_support; | ||
|
|
||
| use std::env; | ||
| use std::fs; | ||
| use std::path::PathBuf; | ||
|
|
||
| fn main() { | ||
| println!("cargo:rerun-if-changed=Cargo.toml"); | ||
| println!("cargo:rerun-if-env-changed=REGISTRY_RELAY_FEATURES"); | ||
|
|
||
| let manifest = | ||
| fs::read_to_string("Cargo.toml").expect("registry-relay Cargo.toml must be readable"); | ||
| let declared = build_support::declared_feature_names(&manifest) | ||
| .expect("registry-relay Cargo features must be readable"); | ||
| let mut enabled = declared | ||
| .iter() | ||
| .filter(|feature| { | ||
| let environment_name = | ||
| format!("CARGO_FEATURE_{}", feature.replace('-', "_").to_uppercase()); | ||
| env::var_os(environment_name).is_some() | ||
| }) | ||
| .cloned() | ||
| .collect::<Vec<_>>(); | ||
| enabled.sort(); | ||
|
|
||
| if let Ok(requested) = env::var("REGISTRY_RELAY_FEATURES") { | ||
| build_support::validate_requested_profile(&requested, &declared, &enabled) | ||
| .unwrap_or_else(|error| panic!("invalid Registry Relay feature profile: {error}")); | ||
| } | ||
|
|
||
| let generated = format!( | ||
| "const COMPILED_CARGO_FEATURES: &[&str] = &[\n{}\n];\n", | ||
| enabled | ||
| .iter() | ||
| .map(|feature| format!(" {feature:?},")) | ||
| .collect::<Vec<_>>() | ||
| .join("\n") | ||
| ); | ||
| let output = PathBuf::from(env::var_os("OUT_DIR").expect("Cargo must provide OUT_DIR")) | ||
| .join("compiled_cargo_features.rs"); | ||
| fs::write(output, generated).expect("compiled feature inventory must be writable"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::collections::BTreeSet; | ||
|
|
||
| pub fn declared_feature_names(manifest: &str) -> Result<Vec<String>, String> { | ||
| let document = manifest | ||
| .parse::<toml::Table>() | ||
| .map_err(|error| format!("Cargo.toml is not valid TOML: {error}"))?; | ||
| let features = document | ||
| .get("features") | ||
| .and_then(toml::Value::as_table) | ||
| .ok_or_else(|| "Cargo.toml must contain a [features] table".to_string())?; | ||
| Ok(features | ||
| .keys() | ||
| .filter(|feature| feature.as_str() != "default") | ||
| .cloned() | ||
| .collect()) | ||
| } | ||
|
|
||
| pub fn validate_requested_profile( | ||
| requested: &str, | ||
| declared: &[String], | ||
| enabled: &[String], | ||
| ) -> Result<(), String> { | ||
| if requested | ||
| .bytes() | ||
| .any(|byte| !matches!(byte, b'a'..=b'z' | b'0'..=b'9' | b'-' | b',')) | ||
| { | ||
| return Err("use comma-separated Cargo feature names".to_string()); | ||
| } | ||
| if requested.starts_with(',') || requested.ends_with(',') || requested.contains(",,") { | ||
| return Err("feature list must not contain empty entries".to_string()); | ||
| } | ||
|
|
||
| let requested = if requested.is_empty() { | ||
| Vec::new() | ||
| } else { | ||
| requested.split(',').map(str::to_string).collect::<Vec<_>>() | ||
| }; | ||
| let requested_set = requested.iter().collect::<BTreeSet<_>>(); | ||
| if requested_set.len() != requested.len() { | ||
| return Err("feature list must not contain duplicates".to_string()); | ||
| } | ||
|
|
||
| let mut canonical = requested.clone(); | ||
| canonical.sort(); | ||
| if requested != canonical { | ||
| return Err(format!( | ||
| "feature list must use canonical order: {}", | ||
| canonical.join(",") | ||
| )); | ||
| } | ||
|
|
||
| let declared = declared.iter().collect::<BTreeSet<_>>(); | ||
| let unknown = requested | ||
| .iter() | ||
| .filter(|feature| !declared.contains(feature)) | ||
| .cloned() | ||
| .collect::<Vec<_>>(); | ||
| if !unknown.is_empty() { | ||
| return Err(format!("unknown Cargo features: {}", unknown.join(","))); | ||
| } | ||
|
|
||
| let enabled = enabled.iter().collect::<BTreeSet<_>>(); | ||
| let missing = enabled | ||
| .difference(&requested_set) | ||
| .map(|feature| feature.as_str()) | ||
| .collect::<Vec<_>>(); | ||
| let inactive = requested_set | ||
| .difference(&enabled) | ||
| .map(|feature| feature.as_str()) | ||
| .collect::<Vec<_>>(); | ||
| if !missing.is_empty() || !inactive.is_empty() { | ||
| return Err(format!( | ||
| "requested profile does not match Cargo's effective feature set \ | ||
| (missing: [{}], inactive: [{}])", | ||
| missing.join(","), | ||
| inactive.join(",") | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| attribute-release,crosswalk-runtime |
Uh oh!
There was an error while loading. Please reload this page.