-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pushing helm charts to artifactory (#736)
* Pushing helm charts to artifactory * error modified
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Release Charts | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
ARTIFACTORY_REGISTRY: ${{ secrets.TRUEFOUNDRY_ARTIFACTORY_REGISTRY_URL }} | ||
ARTIFACTORY_USERNAME: ${{ secrets.TRUEFOUNDRY_ARTIFACTORY_PUBLIC_USERNAME }} | ||
ARTIFACTORY_PASSWORD: ${{ secrets.TRUEFOUNDRY_ARTIFACTORY_PUBLIC_PASSWORD }} | ||
ARTIFACTORY_REPOSITORY_URL: ${{ secrets.TRUEFOUNDRY_ARTIFACTORY_PUBLIC_HELM_REGISTRY }} | ||
|
||
jobs: | ||
release: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Helm | ||
uses: azure/[email protected] | ||
with: | ||
version: v3.14.0 | ||
|
||
- name: Add helm dependencies and update | ||
run: | | ||
helm repo add grafana https://grafana.github.io/helm-charts | ||
helm repo add clickhouse-operator https://docs.altinity.com/clickhouse-operator | ||
helm repo add nvidia https://helm.ngc.nvidia.com/nvidia | ||
helm repo add dcgm-exporter https://nvidia.github.io/dcgm-exporter/helm-charts | ||
helm repo add truefoundry https://truefoundry.github.io/infra-charts | ||
helm repo add nats https://nats-io.github.io/k8s/helm/charts/ | ||
helm repo add bitnami https://charts.bitnami.com/bitnami | ||
helm repo update | ||
- name: Helm registry login | ||
run: | | ||
helm registry login ${{ env.ARTIFACTORY_REGISTRY }} -u ${{ env.ARTIFACTORY_USERNAME }} -p ${{ env.ARTIFACTORY_PASSWORD }} | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install python dependencies | ||
run: | | ||
pip install -r scripts/artifactory-chart-releaser/requirements.txt | ||
- name: Publish helm charts | ||
run: | | ||
python scripts/artifactory-chart-releaser/main.py | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
import subprocess | ||
import yaml | ||
|
||
ARTIFACTORY_REPOSITORY_URL = os.getenv("ARTIFACTORY_REPOSITORY_URL") | ||
|
||
def get_chart_info(chart_dir): | ||
"""Extract chart name and version from Chart.yaml""" | ||
with open(os.path.join(chart_dir, "Chart.yaml"), "r") as file: | ||
chart_yaml = yaml.safe_load(file) | ||
chart_name = chart_yaml.get("name") | ||
chart_version = chart_yaml.get("version") | ||
return chart_name, chart_version | ||
|
||
def helm_chart_exists(chart_name, chart_version): | ||
"""Check if a Helm chart exists in the repository""" | ||
try: | ||
subprocess.run( | ||
["helm", "pull", f"oci://{ARTIFACTORY_REPOSITORY_URL}/{chart_name}", "--version", chart_version], | ||
check=True, | ||
capture_output=True, | ||
text=True | ||
) | ||
return True | ||
except subprocess.CalledProcessError: | ||
return False | ||
|
||
def upload_chart(chart_dir): | ||
"""Upload Helm chart to OCI repository""" | ||
chart_name, chart_version = get_chart_info(chart_dir) | ||
print(f"Uploading chart {chart_name} with version {chart_version}") | ||
|
||
if helm_chart_exists(chart_name, chart_version): | ||
print(f"Helm chart {chart_name} with version {chart_version} already exists in {ARTIFACTORY_REPOSITORY_URL}. Skipping...") | ||
return | ||
|
||
# Update dependencies, package the chart, and push to the repository | ||
subprocess.run(["helm", "dependency", "update"], check=True, cwd=chart_dir) | ||
subprocess.run(["helm", "package", "."], check=True, cwd=chart_dir) | ||
|
||
package_file = f"{chart_name}-{chart_version}.tgz" | ||
try: | ||
subprocess.run( | ||
["helm", "push", package_file, f"oci://{ARTIFACTORY_REPOSITORY_URL}"], | ||
check=True, | ||
cwd=chart_dir | ||
) | ||
print(f"Pushed helm chart {package_file} to the OCI repository oci://{ARTIFACTORY_REPOSITORY_URL}") | ||
except subprocess.CalledProcessError as e: | ||
print(f"Failed to push helm chart {chart_name}: {e}") | ||
exit(1) | ||
|
||
def main(): | ||
"""Main script to iterate over chart directories and upload charts""" | ||
current_dir = os.getcwd() | ||
charts_dir = os.path.join(current_dir, "charts") | ||
chart_dirs = [os.path.join(charts_dir, d) for d in os.listdir(charts_dir) if os.path.isdir(os.path.join(charts_dir, d))] | ||
|
||
for chart_dir in chart_dirs: | ||
print(f"Current directory is {chart_dir}") | ||
upload_chart(chart_dir) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyYAML==6.0.2 |