3 Commits

Author SHA1 Message Date
a40b622918 Add renovate.json 2024-09-11 14:07:44 +00:00
055072f491 Some updates 2024-06-15 20:54:19 +02:00
f40fea7955 Update the custom command mirror 2024-03-25 12:40:10 +01:00
13 changed files with 78 additions and 113 deletions

View File

@ -4,22 +4,22 @@
name: zot
repository: zot-git
extensions:
#- name: Add VPA
# source_dir: ../extensions/vpa
# target_dir: templates/gs-vpa
#- name: Add values for CI
# source_dir: ../extensions/ci-values
# target_dir: ci
- name: Add VPA
source_dir: ../extensions/vpa
target_dir: templates/gs-vpa
- name: Add values for CI
source_dir: ../extensions/ci-values
target_dir: ci
variables:
target_repo: zot-app
patches:
#- name: team annotation
#- name: set home
#- name: set engine
#- name: yamlfmt
- name: team annotation
- name: set home
- name: set engine
- name: yamlfmt
- name: Git patch
git:
path: ../patches/git/zot.patch
ref: d43aaea7bc0e21edb5cc391d4eb47866a5a94aba
mirrors:
- apps-git
# - apps-git
- custom-command

View File

@ -4,11 +4,6 @@ variables:
include:
- kind: Charts
path: ./charts/zot.yaml
- kind: Charts
path: ./charts/gitops-server.yaml
- kind: Charts
path: ./charts/external-secrets-operator.yaml
patches:
- name: yamlfmt
custom_command:
@ -41,7 +36,6 @@ repositories:
url: https://github.com/project-zot/helm-charts.git
git_ref: zot-0.1.42
path: charts
subtree: true
- name: weave
helm:
url: https://helm.gitops.weave.works
@ -52,9 +46,16 @@ mirrors:
- name: apps-git
git:
url: git@git.badhouseplants.net:allanger/{{ variables.target_repo }}.git
git_dir: app-{{ name }}
git_dir: app-{{ name }}-git
branch: upgrade-{{ name }}-to-{{ version }}
path: helm/{{ name }}
commit: |-
chore: mirror {{ name }}-{{ version }}
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

@ -109,10 +109,13 @@ index ac7f0f0..9730e9c 100644
replicaCount: 1
image:
- repository: ghcr.io/project-zot/zot-linux-amd64
+ repository: ghcr.io/project-zot/zot-linux-amd64-bla
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "v2.0.0"
- pullPolicy: IfNotPresent
- # Overrides the image tag whose default is the chart appVersion.
- tag: "v2.0.0"
+ registry: gsoci.azurecr.io
+ image: dummy/zot-linux
+ pullPolicy: Always
+ tag: ""
serviceAccount:
# Specifies whether a service account should be created
create: true

View File

@ -18,6 +18,12 @@ pub(crate) enum SupportedIncludes {
Charts,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)]
pub(crate) struct Hooks{
pre_hooks: Option<Vec<String>>,
post_hooks: Option<Vec<String>>
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)]
pub(crate) struct ChartExtended {
#[serde(flatten)]
@ -52,6 +58,7 @@ pub(crate) struct Config {
pub(crate) patches: Option<Vec<Patch>>,
#[serde(default = "empty_vec")]
pub(crate) mirrors: Vec<Mirror>,
pub(crate) hooks: Hooks,
}
fn empty_vec<T>() -> Vec<T> {

View File

@ -47,7 +47,7 @@ struct Args {
}
fn exec(args: Args) -> Result<(), Box<dyn Error>> {
let prerequisites = vec![args.helm_bin, args.git_bin.clone(), args.yq_bin];
let prerequisites = vec![args.helm_bin, args.git_bin, args.yq_bin];
check_prerequisites(prerequisites)?;
let workdir_path = helmzoo_lib::workdir::setup_workdir(args.workdir)?;
let mut config: Config = read_config(args.config.clone())?;
@ -61,6 +61,7 @@ fn exec(args: Args) -> Result<(), Box<dyn Error>> {
// First step is to pull the chart to the working dir
let current_repo = chart.chart.find_repo(config.repositories.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() {
extensions
.into_iter()
@ -72,7 +73,7 @@ fn exec(args: Args) -> Result<(), Box<dyn Error>> {
patches
.into_iter()
.try_for_each(|patch| -> Result<(), Box<dyn Error>> {
patch.apply(chart_path.clone(), config.patches.clone(), workdir_path.clone(), args.git_bin.clone())
patch.apply(chart_path.clone(), config.patches.clone())
})?
}
config
@ -89,7 +90,7 @@ fn exec(args: Args) -> Result<(), Box<dyn Error>> {
message_empty(&format!("{}", chart.chart.name));
Ok(())
})?;
todo!()
Ok(())
}
fn main() {

View File

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

View File

@ -46,7 +46,6 @@ impl Target for GitMirror {
Some(dir) => template::render(dir.clone(), &chart_local)?,
None => general_purpose::STANDARD_NO_PAD.encode(self.url.clone()),
};
let git_instance = Git {
url: template::render(self.url.clone(), &chart_local)?,
repo_path: repo_path.clone(),

View File

@ -1,11 +1,12 @@
use std::{
use std::{
fs::{self, read_dir, remove_dir_all, File, OpenOptions},
io::Write,
path::{Path, PathBuf}, process::exit,
path::{Path, PathBuf},
};
use helmzoo_lib::{
cli::{cli_exec, cli_exec_from_dir}, git::{CheckoutOptions, Git, GitOptions}, output::message_info, workdir
cli::{cli_exec, cli_exec_from_dir},
output::message_info,
};
use serde::{Deserialize, Serialize};
@ -25,12 +26,6 @@ pub(crate) struct RegexpPatch {
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub(crate) struct GitPatch {
path: String,
#[serde(alias = "ref")]
git_ref: Option<String>,
#[serde(skip)]
workdir: String,
#[serde(skip)]
git_bin: String
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
@ -67,20 +62,18 @@ impl Patch {
&self,
chart_local_path: String,
global_patches: Option<Vec<Patch>>,
workdir: String,
git_bin: String,
) -> Result<(), Box<dyn std::error::Error>> {
let patch_action: Box<dyn PatchInterface>;
if self.is_ref() {
let patch_ref = self.get_ref(global_patches)?;
patch_action = Box::from(patch_action_from_definition(patch_ref, workdir.clone(), git_bin.clone())?);
patch_action = Box::from(patch_action_from_definition(patch_ref)?);
} else {
patch_action = Box::from(patch_action_from_definition(self.clone(), workdir.clone(), git_bin.clone())?);
patch_action = Box::from(patch_action_from_definition(self.clone())?);
}
patch_action.apply(chart_local_path)
}
pub(crate) fn get_path(&self) -> String {
match patch_action_from_definition(self.clone(), String::new(), String::new()) {
match patch_action_from_definition(self.clone()) {
Ok(patch) => patch.get_path(),
Err(_) => "".to_string(),
}
@ -242,34 +235,12 @@ impl PatchInterface for RegexpPatch {
impl PatchInterface for GitPatch {
fn apply(&self, chart_local_path: String) -> Result<(), Box<dyn std::error::Error>> {
let git_instance = Git {
url: chart_local_path.clone(),
repo_path: chart_local_path.clone(),
};
let path = format!("{}", chart_local_path);
let is_git_repo = is_git_repo(path.clone());
if !is_git_repo {
if !is_git_repo(chart_local_path.clone()) {
init_git_repo(chart_local_path.clone())?;
};
let cmd = "git rev-parse --abbrev-ref HEAD".to_string();
let current_ref = cli_exec_from_dir(cmd, path)?;
let git_opts = GitOptions::new(self.git_bin.clone(), None);
if let Some(git_ref) = self.git_ref.clone() {
let checkout_options = CheckoutOptions {
create: false,
git_ref: git_ref.clone(),
};
git_instance.checkout(git_opts, checkout_options)?;
}
let cmd = format!("git -C {} apply {}", chart_local_path, self.path);
cli_exec(cmd)?;
if let Some(git_ref) = self.git_ref.clone() {
exit(1);
}
if !is_git_repo{
remove_dir_all(chart_local_path + "/.git")?;
}
Ok(())
}
@ -302,8 +273,6 @@ impl PatchInterface for CustomCommandPatch {
fn patch_action_from_definition(
patch: Patch,
workdir: String,
git_bin: String,
) -> Result<Box<dyn PatchInterface>, Box<dyn std::error::Error>> {
if let Some(regexp) = patch.regexp {
Ok(Box::new(RegexpPatch { path: regexp.path }))
@ -316,9 +285,6 @@ fn patch_action_from_definition(
None => git.path.clone(),
}
},
git_ref: git.git_ref.clone(),
workdir: workdir.clone(),
git_bin: git_bin.clone(),
}));
} else if let Some(custom_command) = patch.custom_command {
return Ok(Box::new(CustomCommandPatch {
@ -335,7 +301,7 @@ fn patch_action_from_definition(
}
fn is_git_repo(path: String) -> bool {
let dot_git_path = path + "/.git";
let dot_git_path = path + ".git";
Path::new(dot_git_path.as_str()).exists()
}

View File

@ -1,8 +1,8 @@
use std::{error::Error, fmt::format};
use std::error::Error;
use serde::{Deserialize, Serialize};
use crate::cli::{cli_exec, cli_exec_from_dir, is_path_relative};
use crate::cli::{cli_exec, cli_exec_from_dir};
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct GitOptions {
@ -46,10 +46,6 @@ pub struct Git {
impl Git {
pub fn new(url: String, repo_path: String) -> Self {
let repo_path = match is_path_relative(repo_path.clone()) {
true => format!("./{}", repo_path),
false => todo!(),
};
Self { url, repo_path }
}
@ -94,9 +90,8 @@ impl Git {
let _ = self.exec(cmd, git_opts.workdir.clone())?;
}
let cmd = format!(
"{} -C {} diff --staged --quiet || {} -C {} commit -m \"{}\"",
git_opts.bin, self.repo_path,
git_opts.bin, self.repo_path, opts.message
"{} diff --staged --quiet || {} -C {} commit -m \"{}\"",
git_opts.bin, git_opts.bin, self.repo_path, opts.message
);
match self.exec(cmd, git_opts.workdir.clone()) {
Ok(_) => Ok(()),

View File

@ -4,7 +4,6 @@ use crate::git::GitOptions;
use crate::{cli::cli_exec, helm::repository::Version};
use std::error::Error;
use std::fs::{self, rename};
use std::process::exit;
use base64::{engine::general_purpose, Engine};
use serde::Deserialize;
@ -20,7 +19,6 @@ pub struct GitRepo {
#[serde(alias = "ref")]
pub git_ref: String,
pub path: String,
pub subtree: bool,
#[serde(default = "default_git_bin")]
pub(crate) git_bin: String,
}
@ -42,7 +40,7 @@ impl RepositoryImpl for GitRepo {
git_ref: self.git_ref.clone(),
};
git_instance.checkout(git_opts.clone(), checkout_opts)?;
git_instance.checkout(git_opts, checkout_opts)?;
let old_dir_name = format!(
"{}/{}/{}/{}",
@ -58,29 +56,13 @@ impl RepositoryImpl for GitRepo {
match serde_yaml::from_str::<Version>(&helm_stdout) {
Ok(res) => {
new_dir_name = format!("{}/{}-{}", workdir_path, chart.name.clone(), res.version);
match self.subtree {
true => {
let cmd = format!("git subtree split --prefix {}/{} -b helmule-subtree-split", self.path, chart.name.clone());
cli_exec_from_dir(cmd, format!("{}/{}", workdir_path.clone(), repo_name))?;
let checkout_opts = CheckoutOptions{
create: false,
git_ref: "helmule-subtree-split".to_string(),
};
git_instance.checkout(git_opts.clone(), checkout_opts)?;
let old_dir_name = format!("{}/{}", workdir_path.clone(), repo_name);
rename(old_dir_name, new_dir_name.clone())?;
},
false => {
rename(old_dir_name, new_dir_name.clone())?;
// Cleaning up
fs::remove_dir_all(format!("{}/{}", workdir_path, repo_name))?;
}
};
}
Err(err) => return Err(Box::from(err)),
};
// Cleaning up
fs::remove_dir_all(format!("{}/{}", workdir_path, repo_name))?;
// Get the version
let cmd = "helm show chart . | yq '.version'".to_string();
@ -91,4 +73,10 @@ impl RepositoryImpl for GitRepo {
fn get_url(&self) -> String {
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 {
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 {
@ -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() {
LATEST_VERSION => "".to_string(),
_ => format!("--version {}", chart.version.clone()),
@ -85,13 +91,11 @@ impl HelmRepo {
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)
}
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
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());
@ -125,9 +129,6 @@ impl HelmRepo {
let cmd = format!("helm repo remove {}", repo_local_name);
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)
}
}

View File

@ -27,6 +27,7 @@ pub(crate) enum RepositoryKind {
pub trait RepositoryImpl {
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;
}

3
renovate.json Normal file
View File

@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}