Skip to content

Commit

Permalink
Transition from Helm Repositories to OCI Artifacts for Storing Helm C…
Browse files Browse the repository at this point in the history
…harts - update to helm3 command (#1271)

* update to helm3 command

* update to helm3 command

* update to helm3 command

* re-add addrepo function

* re-add addrepo function

* re-add addrepo function

* Revert "add debug to function"

This reverts commit 8afc417.

* add verbose logging

* add verbose logging

* remove add repo function

* readd function

* fix indendation

* edit helm push command

* edit helm push command

* edit helm push command

* edit helm push command

* edit helm push command

* revert addrepo function helm push command

* add env variable

* add env variable

* edit add repo function

* edit add repo function

* edit add repo function

* edit add repo function

* add removerepo function

* add removerepo function

* add removerepo function

* fix typo on indendation

* fix typo on indendation

* fix typo on indendation

* git registry name

* git registry name

* fix white spaces

* fix addrepo function

* fix typo

* fix typo

* fix typo

* add az login before helm command

* fix duplicate

* hardcore clientid

* hardcore clientid

* revert configacr function

* revert configacr function

* run az acr login

* remove add function

* remove add function

* fix issue with add repo function

* edit helm push command

* re-add addrepo function

* re-add addrepo function

* remove az login --identity to test

* re-add az-login --identity

* comment out az login --identity

* add a exeption on az login

* test acr.az login

* test acr.az login

* test acr.az login

* test acr.az login

* remove duplicate bracket

* remove duplicate bracket

* remove duplicate bracket

* edit authenticateAcr function

* edit authenticateAcr function

* remove extra spacing

* add authenticateAcr to be called first before other operation
  • Loading branch information
NickAzureDevops authored Oct 15, 2024
1 parent d2a9af8 commit 1aa6b6e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/uk/gov/hmcts/contino/Helm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Helm {
}

def setup() {
authenticateAcr()
configureAcr()
removeRepo()
addRepo()
Expand All @@ -46,43 +47,50 @@ class Helm {

def removeRepo() {
this.steps.echo "Clear out helm repo before re-adding"
this.steps.sh(label: "helm repo rm ${registryName}", script: "helm repo rm ${registryName} || echo 'Helm repo may not exist on disk, skipping remove'")
this.steps.sh(label: "helm repo rm ${registryName}", script: 'helm repo rm $REGISTRY_NAME || echo "Helm repo may not exist on disk, skipping remove"', env: [REGISTRY_NAME: registryName])
}

def addRepo() {
this.acr.az "acr helm repo add --subscription ${registrySubscription} --name ${registryName}"
}

def authenticateAcr() {
this.acr.az "acr login --name ${registryName}"
}

def publishIfNotExists(List<String> values) {
configureAcr()
removeRepo()
addRepo()
authenticateAcr()
dependencyUpdate()
lint(values)

def version = this.steps.sh(script: "helm inspect chart ${this.chartLocation} | grep ^version | cut -d ':' -f 2", returnStdout: true).trim()
def version = this.steps.sh(script: "helm inspect chart ${this.chartLocation} | grep ^version | cut -d ':' -f 2", returnStdout: true).trim()
this.steps.echo "Version of chart locally is: ${version}"
def resultOfSearch
try {
resultOfSearch = this.acr.az "acr helm show --subscription ${registrySubscription} --name ${registryName} ${this.chartName} --version ${version} --query version -o tsv"
addRepo()
this.steps.sh(script: "helm pull ${registryName}/${this.chartName} --version ${version} -d .", returnStdout: true).trim()
resultOfSearch = version
} catch(ignored) {
resultOfSearch = notFoundMessage
resultOfSearch = notFoundMessage
}
this.steps.echo "Searched remote repo ${registryName}, result was ${resultOfSearch}"

if (resultOfSearch == notFoundMessage) {
this.steps.echo "Publishing new version of ${this.chartName}"

this.steps.sh "helm package ${this.chartLocation}"
this.acr.az "acr helm push --subscription ${registrySubscription} --name ${registryName} ${this.chartName}-${version}.tgz"
this.steps.sh(script: "helm push ${this.chartLocation}-${version}.tgz oci://${registryName}.azurecr.io/helm/${this.chartName}")

this.steps.echo "Published ${this.chartName}-${version} to ${registryName}"
} else {
this.steps.echo "Chart already published, skipping publish, bump the version in ${this.chartLocation}/Chart.yaml if you want it to be published"
this.steps.echo "Chart already published, skipping publish, bump the version in ${this.chartLocation}/Chart.yaml if you want it to be published"
}
}

def publishToGitIfNotExists(List<String> values) {
authenticateAcr()
addRepo()
lint(values)

Expand All @@ -103,7 +111,6 @@ class Helm {
}
}


def lint(List<String> values) {
this.execute("lint", this.chartLocation, values, null)
}
Expand Down Expand Up @@ -163,5 +170,4 @@ class Helm {
def valuesStr = (values == null ? "" : "${' -f ' + values.join(' -f ')}")
helm command, name, "${valuesStr} ${optionsStr}"
}

}
}

0 comments on commit 1aa6b6e

Please sign in to comment.