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: beta builder args #1813

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ use ignore::WalkBuilder;
use indicatif::ProgressBar;
use indoc::{formatdoc, printdoc};
use shuttle_common::models::deployment::{
BuildMetaBeta, DeploymentRequestBuildArchiveBeta, DeploymentRequestImageBeta,
BuildArgsBeta, BuildMetaBeta, DeploymentRequestBuildArchiveBeta, DeploymentRequestImageBeta,
};
use shuttle_common::{
constants::{
@@ -1821,23 +1821,31 @@ impl Shuttle {
};

if self.beta {
let mut build_args = BuildArgsBeta::default();

let metadata = async_cargo_metadata(manifest_path.as_path()).await?;
let packages = find_shuttle_packages(&metadata)?;
// TODO: support overriding this
let package = packages
.first()
.expect("at least one shuttle crate in the workspace");
let package_name = package.name.to_owned();
deployment_req_buildarch_beta.package_name = package_name;
build_args.package_name = Some(package_name);

// TODO: add these to the request and builder
let (_no_default_features, _features) = if package.features.contains_key("shuttle") {
(true, vec!["shuttle".to_owned()])
// activate shuttle feature is present
let (no_default_features, features) = if package.features.contains_key("shuttle") {
(true, Some(vec!["shuttle".to_owned()]))
} else {
(false, vec![])
(false, None)
};
build_args.no_default_features = no_default_features;
build_args.features = features.map(|v| v.join(","));

// TODO: determine which (one) binary to build
// TODO: have the above be configurable in CLI and Shuttle.toml

deployment_req_buildarch_beta.build_args = Some(build_args);

// TODO: have all of the above be configurable in CLI and Shuttle.toml
}

if let Ok(repo) = Repository::discover(working_directory) {
6 changes: 1 addition & 5 deletions common/src/log.rs
Original file line number Diff line number Diff line change
@@ -57,13 +57,9 @@ pub struct LogItem {

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LogItemBeta {
/// Time log was captured
pub timestamp: DateTime<Utc>,

/// Stdout/stderr
/// Which container / log stream this line came from
pub source: String,

/// The log line
pub line: String,
}

55 changes: 51 additions & 4 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
@@ -285,7 +285,7 @@ pub struct DeploymentRequest {
}

#[derive(Deserialize, Serialize)]
#[serde(untagged)]
#[serde(tag = "type", content = "content")]
pub enum DeploymentRequestBeta {
/// Build an image from the source code in an attached zip archive
BuildArchive(DeploymentRequestBuildArchiveBeta),
@@ -298,15 +298,62 @@ pub enum DeploymentRequestBeta {
pub struct DeploymentRequestBuildArchiveBeta {
/// Zip archive
pub data: Vec<u8>,
/// The cargo package name to compile and run.
pub package_name: String,
// TODO: Binary name, feature flags?, other cargo args?
pub build_args: Option<BuildArgsBeta>,
/// Secrets to add before this deployment.
/// TODO: Remove this in favour of a separate secrets uploading action.
pub secrets: Option<HashMap<String, String>>,
pub build_meta: Option<BuildMetaBeta>,
}

#[derive(Deserialize, Serialize)]
pub struct BuildArgsBeta {
/// Use the built in cargo chef setup for caching
pub cargo_chef: bool,
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
/// Build with the built in `cargo build` setup
pub cargo_build: bool,
/// The cargo package name to compile
pub package_name: Option<String>,
/// The cargo binary name to compile
pub binary_name: Option<String>,
/// comma-separated list of features to activate
pub features: Option<String>,
/// Passed on to `cargo build`
pub no_default_features: bool,
/// Use the mold linker
pub mold: bool,
}

impl Default for BuildArgsBeta {
fn default() -> Self {
Self {
cargo_chef: true,
cargo_build: true,
package_name: Default::default(),
binary_name: Default::default(),
features: Default::default(),
no_default_features: Default::default(),
mold: Default::default(),
}
}
}

impl BuildArgsBeta {
pub fn into_vars(&self) -> [(&str, &str); 7] {
[
("CARGO_CHEF", if self.cargo_chef { "true" } else { "" }),
("CARGO_BUILD", if self.cargo_build { "true" } else { "" }),
("PACKAGE", self.package_name.as_deref().unwrap_or_default()),
("BIN", self.binary_name.as_deref().unwrap_or_default()),
("FEATURES", self.features.as_deref().unwrap_or_default()),
(
"NO_DEFAULT_FEATURES",
if self.no_default_features { "true" } else { "" },
),
("MOLD", if self.mold { "true" } else { "" }),
]
}
}

#[derive(Default, Deserialize, Serialize)]
pub struct BuildMetaBeta {
pub git_commit_id: Option<String>,