Skip to content

Commit

Permalink
Merge pull request #72 from Ensono/fix/release
Browse files Browse the repository at this point in the history
fix: Fixes Github Releases
  • Loading branch information
russellseymour authored Mar 20, 2024
2 parents 1279360 + ea82efa commit 3c8969f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 78 deletions.
30 changes: 17 additions & 13 deletions build/azDevOps/azure/deploy-infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ parameters:
displayName: Force deploy regardless of branch
type: boolean
default: false
- name: pre_release
displayName: Create a pre-release from feature branch
type: boolean
default: false

- name: stages
type: object
Expand Down Expand Up @@ -247,11 +251,14 @@ stages:

- stage: Release
dependsOn:
- Build
- Prod
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['create_release'], 'true'), eq('${{ parameters.deploy }}', true))
- ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/master') }}:
- NonProd
- ${{ else }}:
- Prod
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(${{ parameters.pre_release }}, true)))
variables:
- group: ensono-sp-creds
# TODO: Credentials should come from another group. `amido-stacks-github-credentials` are the old creds
- group: amido-stacks-webapp
- name: version_number
value: "$(version_major).$(version_minor).$(version_revision)"
jobs:
Expand All @@ -263,18 +270,15 @@ stages:
parameters:
TaskctlVersion: ${{ variables.TaskctlVersion }}

# Tag the code with the version of the build
- task: Bash@3
displayName: Release
displayName: Publish Release
inputs:
targetType: inline
script: |
taskctl release
env:
BUILDNUMBER: $(Build.BuildNumber)
API_KEY: $(GITHUB_TOKEN)
NOTES:
COMMIT_ID: $(Build.SourceVersion)
ARTIFACTS_DIR: outputs/docs
OWNER: ${{ variables.RepoOwner }}
REPONAME: ${{ variables.RepoName }}
STAGE: "release"
PUBLISH_RELEASE: "true"
GITHUB_TOKEN: "$(GITHUB_TOKEN)"
${{ if ne(variables['Build.SourceBranch'], 'refs/heads/master') }}:
PRERELEASE: "true"
18 changes: 11 additions & 7 deletions build/azDevOps/azure/pipeline-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ variables:
# -------- Cluster information
# version of AKS to deploy
- name: aks_cluster_version
value: 1.26.3
value: 1.26.12

# Should a valid certificate be obtained, or use a self signed one
- name: create_valid_cert
Expand Down Expand Up @@ -87,12 +87,16 @@ variables:
value: false

# ------- GitHub
- name: create_release
value: true
- name: github_release_service_connection
value: GitHubReleases
- name: github_org
value: $(company)
- name: VERSION_NUMBER
value: $(Build.BuildNumber)
- name: COMMIT_ID
value: $(Build.SourceVersion)
- name: OWNER
value: ensono
- name: REPOSITORY
value: stacks-infrastructure-aks
- name: ARTIFACTS_DIR
value: artifacts/

# ------- Resource Tags
- name: team_owner
Expand Down
91 changes: 51 additions & 40 deletions build/scripts/Deploy-Charts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ param (

[string]
# Path to the configuration file stating which charts should be deployed
$path = $env:HELM_CHARTS,
$Path = $env:HELM_CHARTS,

[string[]]
# Names of charts that should be deployed.
# This does not override the enabled flag, but allows a subset of enabled chartts
# to be deployed
$names,
$Names,

[string]
# Path to temporary directory for writing out templates
$tempdir = "tmp/",
$Tempdir = "tmp/",

[string]
# Cloud provider being targetted
$provider = $env:CLOUD_PLATFORM,
# Cloud provider being targeted
$Provider = $env:CLOUD_PROVIDER,

[string]
[Alias("resourcegroup")]
[Alias("ResourceGroup")]
# Identifier for finding the cluster
# In the case of Azure this is the resource group name
$identifier,
$Identifier,

[string]
[Alias("aksname")]
# Name of the cluster
$clustername,
$Clustername,

[switch]
# Specify a dryrun, which will output the helm command to run
$dryrun
$Dryrun
)

# Set defaults on undefined parameters
Expand All @@ -48,20 +48,33 @@ if (!(Test-Path -Path $path)) {
}

# Determine if the tempdir path exists, if not create it
if (!(Test-Path -Path $tempdir)) {
Write-Information ("Creating temporary dir: {0}" -f $tempdir)
New-Item -Type Directory -Path $tempdir | Out-Null
if (!(Test-Path -Path $Tempdir)) {
Write-Information ("Creating temporary dir: {0}" -f $Tempdir)
New-Item -Type Directory -Path $Tempdir | Out-Null
}

# Read in the configuration
$helm = Get-Content -Path $path -Raw | ConvertFrom-Yaml
# Read in the configuration, replacing parameters as necessary
$template_name = Split-Path -Path $path -Leaf
$target = [IO.Path]::Join($Tempdir, $template_name)

# Expand the template for the values
$template = Get-Content -Path $path -Raw
if ([String]::IsNullOrEmpty($template)) {
New-Item -Type File -Path $target -Force | Out-Null
} else {
Expand-Template -Template $template -Target $target
}

$helm = Get-Content -Path $target -Raw | ConvertFrom-Yaml

Write-Host $(Get-Content -Path $target -Raw)

# Iterate around all the charts in the object
foreach ($chart in $helm.charts) {

# if any names have been specified only run if the current chart is in that list
if ($names.length -gt 0 -and $names -notcontains $chart.name) {
Write-Warning -Message ("Skipping chart due to names list: {0} not in [{1}]" -f $chart.name, ($names -join ","))
if ($Names.length -gt 0 -and $Names -notcontains $chart.name) {
Write-Warning -Message ("Skipping chart due to names list: {0} not in [{1}]" -f $chart.name, ($Names -join ","))
}

# Skip the chart if not enabled
Expand All @@ -87,14 +100,25 @@ foreach ($chart in $helm.charts) {
$namespace = $chart.namespace
}

# If a repo has been set, run the command to add the repo to helm
if (![String]::IsNullOrEmpty($chart.repo)) {
$command = "Invoke-Helm -Repo -RepositoryName {0} -RepositoryUrl {1}" -f $chart.location, $chart.repo

if ($Dryrun) {
Write-Host $command
} else {
Invoke-Expression $command
}
}

# Configure an array to hold the pareameters for the helm cmdlet
$helm_args = @()
$helm_args += "-install"
$helm_args += "-chartpath `"{0}/{1}`"" -f $chart.location, $chart.name
$helm_args += "-identifier {0}" -f $identifier
$helm_args += "-target {0}" -f $clustername
$helm_args += "-identifier {0}" -f $Identifier
$helm_args += "-target {0}" -f $Clustername
$helm_args += "-namespace {0}" -f $namespace
$helm_args += "-provider {0}" -f $provider
$helm_args += "-provider {0}" -f $Provider

# Determine the release name
$release_name = $chart.release_name
Expand All @@ -108,7 +132,7 @@ foreach ($chart in $helm.charts) {
# Only if a values template has been specified
if (![String]::IsNullOrEmpty($chart.values_template)) {
$template_name = Split-Path -Path $chart.values_template -Leaf
$target = [IO.Path]::Join($tempdir, $template_name)
$target = [IO.Path]::Join($Tempdir, $template_name)

# Expand the template for the values
$template = Get-Content -Path $chart.values_template -Raw
Expand All @@ -121,29 +145,16 @@ foreach ($chart in $helm.charts) {
$helm_args += "-valuepath {0}" -f $target
}

# If a repo has been set, run the command to add the repo to helm
if (![String]::IsNullOrEmpty($chart.repo)) {
$command = @"
Invoke-Helm -custom -arguments "repo add {0} {1}" -target foobar -provider azure -identifier foobar -namespace foobar -releasename foobar
"@ -f $chart.name, $chart.repo

if ($dryrun) {
Write-Host $command
} else {
Invoke-Expression $command
}
}

# Build up the command to run
$command = "Invoke-Helm {0}" -f ($helm_args -join " ")

# $command = @"
#Invoke-Helm -custom -arguments "upgrade", "{0}", "{1}/{2}", "--install", "--namespace", "{3}", "--create-namespace", "--atomic", "--values", "{4}
#"@ -f $release_name, $chart.location, $chart.name, $chart.namespace, $target
Write-Host ("DEPLOYING: '{0}/{1}'" -f $chart.location, $chart.name)

if ($dryrun) {
if ($Dryrun) {
Write-Host $command
} else {
Invoke-Expression $command
Invoke-Expression $command
}
}

Write-Host ("DEPLOYING FINISHED: '{0}/{1}'" -f $chart.location, $chart.name)
}
18 changes: 10 additions & 8 deletions build/taskctl/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ tasks:
Invoke-Terraform -Init -Path $env:TF_FILE_LOCATION -Arguments $env:TF_BACKEND_INIT -debug
Invoke-Terraform -Workspace -Arguments $env:TF_VAR_name_environment -Path $env:TF_FILE_LOCATION
Invoke-Terraform -Output -Path $env:TF_FILE_LOCATION | /app/build/scripts/Set-EnvironmentVars.ps1 -prefix "TFOUT" -key "value"
/app/build/scripts/Deploy-Charts.ps1 /app/deploy/helm/k8s_apps.yml `
-resourcegroup ${env:TFOUT_resource_group_name} `
-aksname ${env:TFOUT_aks_cluster_name}
/app/build/scripts/Deploy-Charts.ps1 `
-Path /app/deploy/helm/k8s_apps.yml `
-ResourceGroup ${env:TFOUT_resource_group_name} `
-Clustername ${env:TFOUT_aks_cluster_name} `
-Provider ${env:CLOUD_PLATFORM}
_docs:
description: Build Docs for AKS
Expand All @@ -127,12 +129,12 @@ tasks:
Invoke-AsciiDoc -PDF -basepath /app -config /app/docs.json -debug
_release:
context: buildenv
context: powershell
command:
- |
/Publish-GitHubRelease -version $env:BUILDNUMBER `
- Publish-GitHubRelease `
-version $env:BUILD_BUILDNUMBER `
-commitId $env:COMMIT_ID `
-apikey $env:API_KEY `
-apikey $env:GITHUB_TOKEN `
-artifactsDir $env:ARTIFACTS_DIR `
-Owner $env:OWNER `
-repository $env:REPONAME
-repository $env:REPOSITORY
10 changes: 0 additions & 10 deletions taskctl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,4 @@ pipelines:
depends_on: build:number

release:
- task: build:number
- task: _release
depends_on:
- build:number
env:
VERSION_NUMBER: $BUILDNUMBER
API_KEY: $API_KEY
NOTES:
COMMIT_ID: $COMMIT_ID
ARTIFACTS_DIR: $ARTIFACTS_DIR
REPONAME: $REPONAME

0 comments on commit 3c8969f

Please sign in to comment.