Update the custom command mirror

This commit is contained in:
Nikolai Rodionov 2024-03-25 12:40:10 +01:00
parent aabcb21f3b
commit f40fea7955
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
7 changed files with 30 additions and 17 deletions

View File

@ -21,4 +21,5 @@ patches:
git: git:
path: ../patches/git/zot.patch path: ../patches/git/zot.patch
mirrors: mirrors:
- apps-git # - apps-git
- custom-command

View File

@ -4,10 +4,6 @@ variables:
include: include:
- kind: Charts - kind: Charts
path: ./charts/zot.yaml path: ./charts/zot.yaml
- kind: Charts
path: ./charts/gitops-server.yaml
- kind: Charts
path: ./charts/external-secrets-operator.yaml
patches: patches:
- name: yamlfmt - name: yamlfmt
custom_command: custom_command:
@ -56,3 +52,10 @@ mirrors:
commit: |- commit: |-
chore: mirror {{ name }}-{{ version }} chore: mirror {{ name }}-{{ version }}
upstream_repo: {{ repo_url }} upstream_repo: {{ repo_url }}
- name: custom-commands
custom_command:
package:
- helm package -d package .
upload:
- helm push ./package/{{ name }}-{{ version }}.tgz oci://registry.badhouseplants.net
- rm -rf ./package

View File

@ -61,6 +61,7 @@ fn exec(args: Args) -> Result<(), Box<dyn Error>> {
// First step is to pull the chart to the working dir // First step is to pull the chart to the working dir
let current_repo = chart.chart.find_repo(config.repositories.clone())?; let current_repo = chart.chart.find_repo(config.repositories.clone())?;
let chart_path = current_repo.pull_chart(chart.chart.clone(), workdir_path.clone())?; let chart_path = current_repo.pull_chart(chart.chart.clone(), workdir_path.clone())?;
chart.chart.version = current_repo.get_version(chart_path.clone())?;
if let Some(extensions) = chart.extensions.clone() { if let Some(extensions) = chart.extensions.clone() {
extensions extensions
.into_iter() .into_iter()
@ -89,7 +90,7 @@ fn exec(args: Args) -> Result<(), Box<dyn Error>> {
message_empty(&format!("{}", chart.chart.name)); message_empty(&format!("{}", chart.chart.name));
Ok(()) Ok(())
})?; })?;
todo!() Ok(())
} }
fn main() { fn main() {

View File

@ -12,7 +12,7 @@ pub(crate) struct CustomCommands {
impl Target for CustomCommands { impl Target for CustomCommands {
fn push( fn push(
&self, &self,
workdir_path: String, _: String,
chart_path: String, chart_path: String,
chart_local: ChartExtended, chart_local: ChartExtended,
dry_run: bool, dry_run: bool,
@ -21,14 +21,14 @@ impl Target for CustomCommands {
let mut reg = helmzoo_lib::template::register_handlebars(); let mut reg = helmzoo_lib::template::register_handlebars();
reg.register_template_string("cmd", cmd_tmpl)?; reg.register_template_string("cmd", cmd_tmpl)?;
let cmd = reg.render("cmd", &chart_local)?; let cmd = reg.render("cmd", &chart_local)?;
cli_exec_from_dir(cmd, workdir_path.clone())?; cli_exec_from_dir(cmd, chart_path.clone())?;
} }
if !dry_run { if !dry_run {
for cmd_tmpl in self.upload.clone() { for cmd_tmpl in self.upload.clone() {
let mut reg = template::register_handlebars(); let mut reg = template::register_handlebars();
reg.register_template_string("cmd", cmd_tmpl)?; reg.register_template_string("cmd", cmd_tmpl)?;
let cmd = reg.render("cmd", &chart_local)?; let cmd = reg.render("cmd", &chart_local)?;
cli_exec_from_dir(cmd, workdir_path.clone())?; cli_exec_from_dir(cmd, chart_path.clone())?;
} }
} }
Ok(()) Ok(())

View File

@ -73,4 +73,10 @@ impl RepositoryImpl for GitRepo {
fn get_url(&self) -> String { fn get_url(&self) -> String {
self.url.clone() self.url.clone()
} }
fn get_version(&self, chart_path: String) -> Result<String, Box<dyn Error>> {
let cmd = "helm show chart . | yq '.version'".to_string();
let version = cli_exec_from_dir(cmd, chart_path.clone())?;
Ok(version)
}
} }

View File

@ -30,6 +30,12 @@ impl RepositoryImpl for HelmRepo {
fn get_url(&self) -> String { fn get_url(&self) -> String {
self.url.clone() self.url.clone()
} }
fn get_version(&self, chart_path: String) -> Result<String, Box<dyn Error>> {
let cmd = "helm show chart . | yq '.version'".to_string();
let version = cli_exec_from_dir(cmd, chart_path.clone())?;
Ok(version)
}
} }
pub(crate) enum RepoKind { pub(crate) enum RepoKind {
@ -54,7 +60,7 @@ impl HelmRepo {
} }
} }
fn pull_oci(&self, chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>> { fn pull_oci(&self, mut chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>> {
let args = match chart.version.as_str() { let args = match chart.version.as_str() {
LATEST_VERSION => "".to_string(), LATEST_VERSION => "".to_string(),
_ => format!("--version {}", chart.version.clone()), _ => format!("--version {}", chart.version.clone()),
@ -85,13 +91,11 @@ impl HelmRepo {
Err(err) => return Err(Box::from(err)), Err(err) => return Err(Box::from(err)),
}; };
// TODO: Do we really need it?
let cmd = "helm show chart . | yq '.version'".to_string();
let _version = cli_exec_from_dir(cmd, new_dir_name.clone())?;
Ok(new_dir_name) Ok(new_dir_name)
} }
fn pull_default(&self, chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>> {
fn pull_default(&self, mut chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>> {
// Add repo and update // Add repo and update
let repo_local_name = general_purpose::STANDARD_NO_PAD.encode(self.get_url()); let repo_local_name = general_purpose::STANDARD_NO_PAD.encode(self.get_url());
let cmd = format!("helm repo add {} {}", repo_local_name, self.get_url()); let cmd = format!("helm repo add {} {}", repo_local_name, self.get_url());
@ -125,9 +129,6 @@ impl HelmRepo {
let cmd = format!("helm repo remove {}", repo_local_name); let cmd = format!("helm repo remove {}", repo_local_name);
cli_exec(cmd)?; cli_exec(cmd)?;
// TODO: Do we really need it?
let cmd = "helm show chart . | yq '.version'".to_string();
let _version = cli_exec_from_dir(cmd, new_dir_name.clone())?;
Ok(new_dir_name) Ok(new_dir_name)
} }
} }

View File

@ -27,6 +27,7 @@ pub(crate) enum RepositoryKind {
pub trait RepositoryImpl { pub trait RepositoryImpl {
fn pull_chart(&self, chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>>; fn pull_chart(&self, chart: Chart, workdir_path: String) -> Result<String, Box<dyn Error>>;
fn get_version(&self, chart_path: String) -> Result<String, Box<dyn Error>>;
fn get_url(&self) -> String; fn get_url(&self) -> String;
} }