Skip to content

Commit

Permalink
Provide boilerplate for Resource Discovery Helm chart (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkerkhove authored Sep 28, 2020
1 parent 8e351dc commit 69db7b9
Show file tree
Hide file tree
Showing 21 changed files with 758 additions and 54 deletions.
13 changes: 12 additions & 1 deletion build/azure-devops/agents-ci-discovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ variables:
value: 'promitor-discovery-agent'
- name: App.Version
value: '0.0.0-$(Image.Tag)'
- name: Helm.Chart.Version
value: '0.0.0-$(App.Version)'
- name: Helm.Chart.CI.Name
value: 'promitor-agent-resource-discovery'
stages:
- stage: Init
displayName: Prepare Build
Expand Down Expand Up @@ -209,4 +213,11 @@ stages:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: templates/docker/push-image.yml
parameters:
imageName: '$(Image.TaggedName)'
imageName: '$(Image.TaggedName)'
- template: templates/stages/helm-chart-verification.yml
parameters:
chartName: '$(Helm.Chart.CI.Name)'
chartVersion: '$(Helm.Chart.Version)'
appVersion: '$(App.Version)'
imageName: '$(Image.Name)'
dependsOn: 'Docker'
49 changes: 9 additions & 40 deletions build/azure-devops/agents-ci-scraper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ variables:
value: '0.0.0-$(Image.Tag)'
- name: Helm.Chart.Version
value: '0.0.0-$(App.Version)'
- name: Helm.Chart.CI.Name
value: 'promitor-agent-scraper-ci'
- name: Helm.Chart.Name
value: 'promitor-agent-scraper'
stages:
- stage: Init
displayName: Prepare Build
Expand Down Expand Up @@ -286,41 +286,10 @@ stages:
parameters:
helmVersion: '$(Helm.Version)'
chartName: '$(Chart.Scraper.Name)'
- stage: Helm3
displayName: Helm Chart (3.x)
dependsOn: Docker
variables:
Helm.Version: '3.0.0'
jobs:
- job: Helm3_x
displayName: Helm 3.x - Lint, Package & Push Chart
condition: succeeded()
pool:
vmImage: ubuntu-16.04
steps:
- download: current
artifact: variables
- template: templates/utils/read-variable-on-linux.yml
parameters:
variableName: 'Image.Tag'
- template: templates/helm/lint-chart.yml
parameters:
helmVersion: '$(Helm.Version)'
chartName: '$(Chart.Scraper.Name)'
- template: templates/helm/package-preview-chart.yml
parameters:
chartName: '$(Helm.Chart.CI.Name)'
chartVersion: '$(Helm.Chart.Version)'
appVersion: '$(App.Version)'
imageName: '$(Image.Name)'
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: templates/helm/push-chart.yml
parameters:
chartName: '$(Helm.Chart.CI.Name)'
chartVersion: '$(Helm.Chart.Version)'
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- task: PublishBuildArtifacts@1
displayName: 'Publish Helm Chart'
inputs:
PathtoPublish: charts/output/$(Helm.Chart.CI.Name)-$(Helm.Chart.Version).tgz
ArtifactName: helm
- template: templates/stages/helm-chart-verification.yml
parameters:
chartName: '$(Helm.Chart.Name)'
chartVersion: '$(Helm.Chart.Version)'
appVersion: '$(App.Version)'
imageName: '$(Image.Name)'
dependsOn: 'Docker'
2 changes: 1 addition & 1 deletion build/azure-devops/templates/helm/lint-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parameters:

steps:
- task: HelmInstaller@1
displayName: 'Install Helm (${{ parameters.helmVersion }}'
displayName: 'Install Helm (${{ parameters.helmVersion }})'
inputs:
helmVersionToInstall: '${{ parameters.helmVersion }}'
- powershell: |
Expand Down
4 changes: 3 additions & 1 deletion build/azure-devops/templates/helm/package-preview-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ parameters:
default: '$(Helm.Version)'
- name: chartName
type: string
- name: transformedChartName
type: string
- name: chartVersion
type: string
- name: appVersion
Expand All @@ -21,7 +23,7 @@ steps:
inputs:
targetType: filePath
filePath: ./build/helm/Transform-Chart.ps1
arguments: '-chartName "${{ parameters.chartName }}" -imageName "${{ parameters.imageName }}" -imageTag "${{ parameters.appVersion }}"'
arguments: '-chartName "${{ parameters.chartName }}" -transformedChartName "${{ parameters.transformedChartName }}" -imageName "${{ parameters.imageName }}" -imageTag "${{ parameters.appVersion }}"'
workingDirectory: 'charts'
- template: package-official-chart.yml
parameters:
Expand Down
48 changes: 48 additions & 0 deletions build/azure-devops/templates/stages/helm-chart-verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
parameters:
chartName: ''
chartVersion: ''
appVersion: ''
imageName: ''
dependsOn: ''

stages:
- stage: Helm3
displayName: Helm Chart (3.x)
dependsOn: ${{ parameters.dependsOn }}
variables:
Helm.Version: '3.0.0'
jobs:
- job: Helm3_x
displayName: Helm 3.x - Lint, Package & Push Chart
condition: succeeded()
pool:
vmImage: ubuntu-16.04
steps:
- download: current
artifact: variables
# TODO: Move this to step to pass as "pre-run step"
- template: ./../../utils/read-variable-on-linux.yml
parameters:
variableName: 'Image.Tag'
- template: ./../../helm/lint-chart.yml
parameters:
helmVersion: '$(Helm.Version)'
chartName: '${{ parameters.chartName }}'
- template: ./../../helm/package-preview-chart.yml
parameters:
chartName: '${{ parameters.chartName }}'
chartVersion: '${{ parameters.chartVersion }}'
appVersion: '${{ parameters.appVersion }}'
imageName: '${{ parameters.imageName }}'
transformedChartName: '${{ parameters.chartName }}-ci'
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: ./../../helm/push-chart.yml
parameters:
chartName: '${{ parameters.chartName }}'
chartVersion: '${{ parameters.chartVersion }}'
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- task: PublishBuildArtifacts@1
displayName: 'Publish Helm Chart'
inputs:
PathtoPublish: charts/output/${{ parameters.chartName }}-${{ parameters.chartVersion }}.tgz
ArtifactName: helm
24 changes: 13 additions & 11 deletions build/helm/Transform-Chart.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ Param(
[String]
[Parameter(Mandatory = $true)] $chartName = $(throw "Chart name is required"),
[String]
[Parameter(Mandatory = $true)] $transformedChartName = $(throw "Chart name of the transformed output is required"),
[String]
[Parameter(Mandatory = $true)] $imageName = $(throw "Image name is required"),
[String]
[Parameter(Mandatory = $true)] $imageTag = $(throw "Image tag is required")
)

echo "Copying Chart folder"
cp promitor-agent-scraper/ $chartName/ -r
cp $chartName/ $transformedChartName/ -r

echo "Determining image version"
$imageVersion = "$imageTag".ToLower()
echo "Image version is $imageVersion"

echo "Changing name of chart to $chartName"
((Get-Content -path $chartName/Chart.yaml -Raw) -replace 'promitor-agent-scraper', $chartName) | Set-Content -Path $chartName/Chart.yaml
echo "Changing name of chart to $transformedChartName"
((Get-Content -path $transformedChartName/Chart.yaml -Raw) -replace 'promitor-agent-scraper', $transformedChartName) | Set-Content -Path $transformedChartName/Chart.yaml

echo "Changing image tag to $imageVersion"
((Get-Content -path $chartName/values.yaml -Raw) -replace 'latest', $imageVersion) | Set-Content -Path $chartName/values.yaml
((Get-Content -path $transformedChartName/values.yaml -Raw) -replace 'latest', $imageVersion) | Set-Content -Path $transformedChartName/values.yaml

echo "Changing repo name to $imageName"
((Get-Content -path $chartName/values.yaml -Raw) -replace 'tomkerkhove/promitor-agent-scraper', $imageName) | Set-Content -Path $chartName/values.yaml
((Get-Content -path $transformedChartName/values.yaml -Raw) -replace 'tomkerkhove/promitor-agent-scraper', $imageName) | Set-Content -Path $transformedChartName/values.yaml

echo "Change name of chart in README to $chartName"
((Get-Content -path $chartName/README.md -Raw) -replace 'promitor-agent-scraper', $chartName) | Set-Content -Path $chartName/README.md
echo "Change name of chart in README to $transformedChartName"
((Get-Content -path $transformedChartName/README.md -Raw) -replace 'promitor-agent-scraper', $transformedChartName) | Set-Content -Path $transformedChartName/README.md

echo "Change version of image in README to $imageVersion"
((Get-Content -path $chartName/README.md -Raw) -replace 'latest', $imageVersion) | Set-Content -Path $chartName/README.md
((Get-Content -path $transformedChartName/README.md -Raw) -replace 'latest', $imageVersion) | Set-Content -Path $transformedChartName/README.md

echo "Outputting transformed content"
Get-Content -path $chartName/Chart.yaml -Raw
Get-Content -path $chartName/values.yaml -Raw
Get-Content -path $chartName/README.md -Raw
Get-Content -path $transformedChartName/Chart.yaml -Raw
Get-Content -path $transformedChartName/values.yaml -Raw
Get-Content -path $transformedChartName/README.md -Raw
21 changes: 21 additions & 0 deletions charts/promitor-agent-resource-discovery/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
13 changes: 13 additions & 0 deletions charts/promitor-agent-resource-discovery/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
version: 0.2.0
appVersion: 1.0.0
type: application
name: promitor-agent-resource-discovery
description: Promitor, bringing Azure Monitor metrics where you need them.
home: https://promitor.io
sources:
- https://github.com/tomkerkhove/promitor
maintainers:
- name: Tom Kerkhove
url: https://github.com/tomkerkhove
icon: https://raw.githubusercontent.com/tomkerkhove/promitor/master/docs/media/logos/promitor.png
21 changes: 21 additions & 0 deletions charts/promitor-agent-resource-discovery/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Tom Kerkhove

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 69db7b9

Please sign in to comment.