From c9ffc0e35151a2366baab0b5664f92eee4419004 Mon Sep 17 00:00:00 2001 From: Akshit Agrawal Date: Thu, 2 Nov 2023 10:35:39 +0530 Subject: [PATCH 1/3] initial commit --- Dockerfile | 18 +++++++++++++++ main.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Dockerfile create mode 100644 main.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0b92e10 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine:3.18 + +WORKDIR /app + +ENV HELM_EXPERIMENTAL_OCI=1 + +RUN apk --no-cache add ca-certificates curl && \ + curl -LO "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz" && \ + tar -zxvf helm-v3.7.0-linux-amd64.tar.gz && \ + mv linux-amd64/helm /usr/local/bin/helm && \ + rm -rf linux-amd64 helm-v3.7.0-linux-amd64.tar.gz && \ + chmod +x /usr/local/bin/helm + +RUN apk --no-cache add python3 + +COPY main.py /app/ + +CMD ["python3", "/app/main.py"] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..4f66393 --- /dev/null +++ b/main.py @@ -0,0 +1,64 @@ +# z Plugin Name: Push OCI Chart to Registry +# Description: Pushes an OCI Chart to a Docker Registry + +import os +import subprocess + +# Environment Variables + +# Helm Chart +CHART_NAME = os.getenv("PLUGIN_CHART_NAME") # ! required +CHART_VERSION = os.getenv("PLUGIN_CHART_VERSION", "1.0.0") + +# Docker Repository Details +DOCKER_REGISTRY = os.getenv( + "PLUGIN_DOCKER_REGISTRY", 'registry.hub.docker.com') # ? optional + +# Docker Hub Credentials +DOCKER_USERNAME = os.getenv( + "PLUGIN_DOCKER_USERNAME") # ! required +DOCKER_PASSWORD = os.getenv( + "PLUGIN_DOCKER_PASSWORD") # ! required + +# Path to Chart +CHART_PATH = os.getenv("PLUGIN_CHART_PATH") # ? optional + + +# ? validate environment variables + +if (CHART_NAME is None): + print("Please provide a chart name") + exit(1) + +if (DOCKER_USERNAME is None or DOCKER_PASSWORD is None): + print("Please provide a username and a password") + exit(1) + + +# cd into the chart directory +if (CHART_PATH is not None): + os.chdir(CHART_PATH) + +# Package the helm chart +subprocess.run(["helm", "package", "--dependency-update", "."]) + +# Construct the chart name +chart_filename = f"{CHART_NAME}-{CHART_VERSION}.tgz" + +# Login to Docker Registry +try: + login_command = ['helm', 'registry', 'login', DOCKER_REGISTRY, + '-u', DOCKER_USERNAME, '-p', DOCKER_PASSWORD] + subprocess.run(login_command) +except: + print("Failed to login!") + exit(1) + +# Push the chart to Docker Hub +try: + docker_push_command = ["helm", "push", chart_filename, + f"oci://{DOCKER_REGISTRY}/{DOCKER_USERNAME}"] + subprocess.run(docker_push_command) +except: + print("Failed to push chart!") + exit(1) From 50895cb69bb8204bd4ff9d2c81aa5fbb76ac42e5 Mon Sep 17 00:00:00 2001 From: "OP (oppenheimer)" <21008429+Ompragash@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:41:21 +0530 Subject: [PATCH 2/3] Update Dockerfile Fixed EOL issue --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0b92e10..cdce824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,4 @@ RUN apk --no-cache add python3 COPY main.py /app/ -CMD ["python3", "/app/main.py"] \ No newline at end of file +CMD ["python3", "/app/main.py"] From f733d18115eee66a6bbcfcf4cb329b8fd67593c0 Mon Sep 17 00:00:00 2001 From: "OP (oppenheimer)" <21008429+Ompragash@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:41:55 +0530 Subject: [PATCH 3/3] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 4f66393..b841a2c 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ -# z Plugin Name: Push OCI Chart to Registry -# Description: Pushes an OCI Chart to a Docker Registry +# Plugin Name: Push OCI Chart to Registry +# Description: Pushes an Helm Chart to a Docker Registry import os import subprocess