Skip to content

fix image list in private registry helper utils #50

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

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ output

# only ignore the values.yaml file at the root of the repo
/values.yaml
.devcontainer
4 changes: 2 additions & 2 deletions charts/gitops-runtime/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
appVersion: 0.1.29
description: A Helm chart for Codefresh gitops runtime
name: gitops-runtime
version: 0.2.8-alpha
version: 0.2.8-alpha.1
home: https://github.com/codefresh-io/gitops-runtime-helm
icon: https://avatars1.githubusercontent.com/u/11412079?v=3
keywords:
Expand All @@ -16,7 +16,7 @@ annotations:
artifacthub.io/prerelease: "true"
artifacthub.io/changes: |
- kind: fixed
description: rollout-reporter and workflow-reporter trigger values were wrong (resulting in event not reaching the platform)
description: Fix image list generation in private registry helper utility
dependencies:
- name: argo-cd
repository: https://codefresh-io.github.io/argo-helm
Expand Down
4 changes: 2 additions & 2 deletions charts/gitops-runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Codefresh gitops runtime
![Version: 0.2.8-alpha](https://img.shields.io/badge/Version-0.2.8--alpha-informational?style=flat-square) ![AppVersion: 0.1.29](https://img.shields.io/badge/AppVersion-0.1.29-informational?style=flat-square)
![Version: 0.2.8-alpha.1](https://img.shields.io/badge/Version-0.2.8--alpha.1-informational?style=flat-square) ![AppVersion: 0.1.29](https://img.shields.io/badge/AppVersion-0.1.29-informational?style=flat-square)

## Codefresh official documentation:
Prior to running the installation please see the official documentation at: https://codefresh.io/docs/docs/installation/gitops/hybrid-gitops-helm-installation/
Expand All @@ -15,7 +15,7 @@ We have created a helper utility to resolve this issue:
The utility is packaged in a container image. Below are instructions on executing the utility using Docker:

```
docker run -v <output_dir>:/output quay.io/codefresh/gitops-runtime-private-registry-utils:0.2.7-alpha <local_registry>
docker run -v <output_dir>:/output quay.io/codefresh/gitops-runtime-private-registry-utils:0.2.8-alpha.1 <local_registry>
```
`output_dir` - is a local directory where the utility will output files. <br>
`local_registry` - is your local registry where you want to mirror the images to
Expand Down
2 changes: 1 addition & 1 deletion charts/gitops-runtime/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We have created a helper utility to resolve this issue:
The utility is packaged in a container image. Below are instructions on executing the utility using Docker:

```
docker run -v <output_dir>:/output quay.io/codefresh/gitops-runtime-private-registry-utils:0.2.7-alpha <local_registry>
docker run -v <output_dir>:/output quay.io/codefresh/gitops-runtime-private-registry-utils:{{ template "chart.version" . }} <local_registry>
```
`output_dir` - is a local directory where the utility will output files. <br>
`local_registry` - is your local registry where you want to mirror the images to
Expand Down
30 changes: 19 additions & 11 deletions scripts/private-registry-utils/private-registry-utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ def recurse_replace_registry(currValue,new_registry):
currValue[key] = replace_registry_in_image(currValue[key],new_registry)
else:
recurse_replace_registry(currValue[key],new_registry)

elif type(currValue) is list:
for item in currValue:
recurse_replace_registry(item,new_registry)
for index,item in enumerate(currValue):
if type(item) is dict or type(item) is list:
recurse_replace_registry(item,new_registry)
elif type(item) is str:
if is_docker_image(item):
currValue[index] = replace_registry_in_image(item,new_registry)


def recurse_remove_tags(currValue):
if type(currValue) is dict:
Expand All @@ -70,20 +76,17 @@ def recurse_get_source_target(currValue,new_registry,lstSourceTarget):
sourceImage += currValue[key]
if key == "tag":
sourceImage += ":" + currValue[key]

elif type(currValue[key]) is str:
if is_docker_image(currValue[key]):
sourceImage = currValue[key]

recurse_get_source_target(currValue[key],new_registry,lstSourceTarget)

else:
recurse_get_source_target(currValue[key],new_registry,lstSourceTarget)
if len(sourceImage) > 0:
lstSourceTarget.append({"source_image": sourceImage, "target_image": replace_registry_in_image(sourceImage,new_registry)})


elif type(currValue) is list:
for item in currValue:
recurse_get_source_target(item,new_registry,lstSourceTarget)
elif type(currValue) is str:
if is_docker_image(currValue):
lstSourceTarget.append({"source_image": currValue, "target_image": replace_registry_in_image(sourceImage,new_registry)})

def generate_file_from_field(list_of_dicts, field_name, output_file):
with open(output_file, 'w+') as file:
Expand All @@ -107,7 +110,6 @@ def generate_image_list():
print("Generating image list")

def generate_mirror_csv(lstSourceTarget, outputDir):

fields = ['source_image', 'target_image']

with open(f"{outputDir}/image-mirror.csv", 'w+') as csvfile:
Expand Down Expand Up @@ -138,13 +140,19 @@ def main():


if args.action == "generate-mirror-csv" or args.action is None:
print("Creating image-mirror.csv..")
generate_mirror_csv(lstSourceTarget,args.output_dir)
print("Done!")

if args.action == "generate-image-list" or args.action is None:
print("Creating image-list.txt...")
generate_file_from_field(lstSourceTarget,"source_image", f"{args.output_dir}/image-list.txt")
print("Done!")

if args.action == "generate-image-values" or args.action is None:
print("Creating values files...")
generate_image_values(dictImageValues,args.output_dir)
print("Done!")

if __name__ == "__main__":
main()