From 61468d710bae89c8c97779234172204457f7f79c Mon Sep 17 00:00:00 2001 From: Fabio Date: Fri, 4 Apr 2025 17:35:00 -0300 Subject: [PATCH] Use Harbor to host charts instead --- .drone.yml | 70 ++++++++++-------------------------------------------- 1 file changed, 13 insertions(+), 57 deletions(-) diff --git a/.drone.yml b/.drone.yml index 62c5563..7d27e59 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,69 +21,25 @@ steps: depends_on: - lint-charts - - # Step 3: Fetch the existing index.yaml from Gitea (if it exists) - - name: fetch-existing-index - image: alpine:latest - commands: - - apk add --no-cache curl jq - - "LATEST_TAG=$(curl -s -H \"Authorization: token $GITEATOKEN\" https://git.interlegis.leg.br/api/v1/repos/SEIT/rancher-charts/releases?limit=1 | jq -r '.[0].tag_name')" - - "if [ -n \"$LATEST_TAG\" ]; then curl -L -o charts/dist/index.yaml https://git.interlegis.leg.br/SEIT/rancher-charts/releases/download/$LATEST_TAG/index.yaml || true; fi" - environment: - GITEATOKEN: - from_secret: giteatoken - depends_on: - - package-changed-charts - - # Step 4: Update index.yaml with changed charts (skip if no changes) - - name: update-index + # Step 3: Push charts to Harbor + - name: push-to-harbor image: alpine/helm:latest commands: - - if [ -n "$(ls charts/dist/*.tgz 2>/dev/null)" ]; then helm repo index charts/dist --url https://git.interlegis.leg.br/SEIT/rancher-charts/raw/branch/gh-pages/ --merge charts/dist/index.yaml; else echo "No new charts to index"; fi - depends_on: - - fetch-existing-index - - # Step 5: Push charts and index to gh-pages branch without credentials file - - name: push-to-branch - image: alpine/git - commands: - # Fail explicitly if GITEA_API_KEY is unset or empty - - "if [ -z \"$GITEATOKEN\" ]; then echo \"Error: GITEATOKEN is not set or empty\"; exit 1; fi" - # Check if gh-pages exists remotely, fetch it if it does, otherwise create it - - git ls-remote --heads origin gh-pages | grep -q gh-pages && git fetch origin gh-pages && git checkout gh-pages || git checkout -b gh-pages - # Stage the charts/dist directory (already in the working directory) - - git add charts/dist/* - # Commit changes - - git commit -m "Update Helm charts from commit ${DRONE_COMMIT}" || echo "No changes to commit" - # Push with API key, ensuring proper variable expansion - - "PUSH_URL=\"https://x:60dd20a2497096bd2354b2b259e5b574b490f942@git.interlegis.leg.br/SEIT/rancher-charts.git\"" - - "git push \"$PUSH_URL\" HEAD:gh-pages --force || { echo \"Git push failed\"; exit 1; }" + # Fail if credentials are missing + - "if [ -z \"$HARBOR_USERNAME\" ] || [ -z \"$HARBOR_PASSWORD\" ]; then echo \"Error: HARBOR_USERNAME or HARBOR_PASSWORD not set\"; exit 1; fi" + # Login to Harbor registry + - "helm registry login -u \"$HARBOR_USERNAME\" -p \"$HARBOR_PASSWORD\" https://porto.interlegis.leg.br" + # Push each chart to Harbor (OCI format, Helm 3.8+) + - for CHART in charts/dist/*.tgz; do helm push "$CHART" oci://porto.interlegis.leg.br/seit; done environment: - GITEATOKEN: - from_secret: giteatoken - when: - condition: ls charts/dist/*.tgz 2>/dev/null # Only run if there are new .tgz files - depends_on: - - update-index - - # Step 6: Create or update Gitea release with changed artifacts - - name: release-to-gitea - image: plugins/gitea-release - settings: - api_key: - from_secret: giteatoken - base_url: https://git.interlegis.leg.br - files: - - charts/dist/*.tar.gz - - charts/dist/index.yaml - title: "Helm Charts Update - ${DRONE_COMMIT}" - note: "Updated Helm repository from commit ${DRONE_COMMIT}" - draft: false - prerelease: true + HARBOR_USERNAME: + from_secret: harbor_username + HARBOR_PASSWORD: + from_secret: harbor_password when: condition: ls charts/dist/*.tgz 2>/dev/null # Only run if there are new .tgz files depends_on: - - push-to-branch + - package-changed-charts trigger: branch: