Skip to content

Commit

Permalink
Merge pull request #38 from molnett/add-image-name-arg
Browse files Browse the repository at this point in the history
feat: make it possible to choose image name
  • Loading branch information
tmlye authored Jun 15, 2024
2 parents ffdf33e + a185cd4 commit 17790f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Once you have Rust setup, a simple `cargo build --release` should produce your v
## Use with Github Actions

We created a Github Action to make it easy to use molnctl in your builds, see [setup-molnctl-action](https://github.com/molnett/setup-molnctl-action).
There is also a Github Action for working with ephemeral environments, see [ephemeral-environment-action](https://github.com/molnett/ephemeral-environment-action)

## Usage

Expand Down
20 changes: 14 additions & 6 deletions src/commands/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl ManifestBuilder {

pub fn get_image(mut self) -> Result<Self> {
self.manifest.service.image =
get_image_name(&self.api_client, &self.token, &self.org_name, &None)?;
get_image_name(&self.api_client, &self.token, &self.org_name, &None, &None)?;
Ok(self)
}

Expand All @@ -305,12 +305,18 @@ fn get_image_name(
token: &str,
org_name: &str,
tag: &Option<String>,
name: &Option<String>,
) -> Result<String> {
let cur_dir = env::current_dir()?;
let image_name = if let Some(dir_name) = cur_dir.file_name() {
dir_name.to_str().unwrap()
let image_name = if name.is_some() {
name.as_ref().unwrap().to_string()
} else {
return Err(anyhow!("Unable to get current directory for image name"));
let cur_dir = env::current_dir()?;
let image_name = if let Some(dir_name) = cur_dir.file_name() {
dir_name.to_str().unwrap()
} else {
return Err(anyhow!("Unable to get current directory for image name"));
};
image_name.to_string()
};
let org_id = api_client.get_org(token, org_name)?.id;

Expand All @@ -337,6 +343,8 @@ pub struct ImageName {
tag: Option<String>,
#[arg(short, long, help = "Path to a molnett manifest. The manifest's image field will be updated to the returned image name")]
update_manifest: Option<String>,
#[arg(short, long, help = "Override image name. Default is directory name")]
image_name: Option<String>,
}

impl ImageName {
Expand All @@ -346,7 +354,7 @@ impl ImageName {
.get_token()
.ok_or_else(|| anyhow!("No token found. Please login first."))?;

let image_name = get_image_name(&base.api_client(), token, &base.get_org()?, &self.tag)?;
let image_name = get_image_name(&base.api_client(), token, &base.get_org()?, &self.tag, &self.image_name)?;
if let Some(path) = self.update_manifest.clone() {
let mut manifest = read_manifest(&path)?;
manifest.service.image = image_name.clone();
Expand Down
1 change: 0 additions & 1 deletion src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl Token {
}

pub struct UserConfigLoader {
pub path: Utf8PathBuf,
}

impl UserConfig {
Expand Down

0 comments on commit 17790f0

Please sign in to comment.