Skip to content

Commit

Permalink
publish: Implement twoliter publish (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecpullen committed Oct 26, 2023
1 parent f617040 commit a47d724
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions twoliter/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod build;
mod debug;
mod make;
mod publish;

use self::build::BuildCommand;
use self::publish::PublishCommand;
use crate::cmd::debug::DebugAction;
use crate::cmd::make::Make;
use anyhow::Result;
Expand Down Expand Up @@ -34,6 +36,10 @@ pub(crate) enum Subcommand {

Make(Make),

/// Publish something, such as a Bottlerocket image or a kit of packages.
#[clap(subcommand)]
Publish(PublishCommand),

/// Commands that are used for checking and troubleshooting Twoliter's internals.
#[clap(subcommand)]
Debug(DebugAction),
Expand All @@ -43,6 +49,7 @@ pub(crate) enum Subcommand {
pub(super) async fn run(args: Args) -> Result<()> {
match args.subcommand {
Subcommand::Build(build_command) => build_command.run().await,
Subcommand::Publish(publish_command) => publish_command.run().await,
Subcommand::Make(make_args) => make_args.run().await,
Subcommand::Debug(debug_action) => debug_action.run().await,
}
Expand Down
57 changes: 57 additions & 0 deletions twoliter/src/cmd/publish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::cargo_make::CargoMake;
use crate::project;
use crate::tools::{install_tools, tools_tempdir};
use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;

#[derive(Debug, Parser)]
pub(crate) enum PublishCommand {
Ami(PublishAmi),
}

impl PublishCommand {
pub(crate) async fn run(self) -> Result<()> {
match self {
PublishCommand::Ami(publish_ami) => publish_ami.run().await,
}
}
}

/// Publish a Bottlerocket variant image.
#[derive(Debug, Parser)]
pub(crate) struct PublishAmi {
/// Path to Twoliter.toml. Will search for Twoliter.toml when absent.
#[clap(long, env = "TWOLITER_PROJECT")]
project_path: Option<PathBuf>,

/// The architecture to publish.
#[clap(long, env = "BUILDSYS_ARCH", default_value = "x86_64")]
arch: String,

/// The variant to publish.
#[clap(env = "BUILDSYS_VARIANT")]
variant: String,

/// Path to Infra.toml
#[clap(long, env = "PUBLISH_INFRA_CONFIG_PATH", default_value = "Infra.toml")]
infra_config_path: String,
}

impl PublishAmi {
pub(super) async fn run(&self) -> Result<()> {
let project = project::load_or_find_project(self.project_path.clone()).await?;
let tempdir = tools_tempdir()?;
install_tools(&tempdir).await?;
let makefile_path = tempdir.path().join("Makefile.toml");
CargoMake::new(&project, &self.arch)?
.env("TWOLITER_TOOLS_DIR", tempdir.path().display().to_string())
.env("PUBLISH_INFRA_CONFIG_PATH", &self.infra_config_path)
.env("BUILDSYS_ARCH", &self.arch)
.env("BUILDSYS_VARIANT", &self.variant)
.makefile(makefile_path)
.project_dir(project.project_dir())
._exec("ami")
.await
}
}

0 comments on commit a47d724

Please sign in to comment.