diff --git a/build/azure-devops/agents-scraper-release-official.yml b/build/azure-devops/agents-scraper-release-official.yml new file mode 100644 index 000000000..161936365 --- /dev/null +++ b/build/azure-devops/agents-scraper-release-official.yml @@ -0,0 +1,134 @@ +name: $(Image.Version) +resources: +- repo: self +trigger: none +pr: none +variables: + DotNet.SDK.Version: '2.2.301' + Image.Name: 'tomkerkhove/promitor-agent-scraper' + Image.TaggedName: '$(Image.Name):$(Image.Version)' + Release.TagName: '$(Build.BuildNumber)' + Helm.App.Version: '$(Image.Version)' + # Release.Title is configured in the build definition as settable at queue time + # Image.Version is configured in the build definition as settable at queue time + # Helm.Chart.Version is configured in the build definition as settable at queue time +stages: +- stage: Build + displayName: Build and Push Docker image + jobs: + - job: Build + pool: + vmImage: ubuntu-16.04 + steps: + - task: DotNetCoreInstaller@0 + displayName: 'Install .NET SDK' + inputs: + version: '$(DotNet.SDK.Version)' + - powershell: | + Write-Host "Determining '{major}.{minor}' for '$(Image.Version)'" + $index = "$(Image.Version)".IndexOf(".", 2); + $majorMinorVersion = "$(Image.Version)".Substring(0, $index); + Write-Host "Found version '$majorMinorVersion'" + Write-Output ("##vso[task.setvariable variable=Image.MajorMinorVersion;]$majorMinorVersion") + displayName: 'Determine ''{major}.{minor}'' version' + - task: DotNetCoreCLI@2 + displayName: 'Run Unit Tests' + inputs: + command: test + projects: src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj + - task: Docker@1 + displayName: 'Build Docker image' + inputs: + dockerFile: ./src/Promitor.Scraper.Host/Dockerfile + arguments: '-t $(Image.Name):$(Image.MajorMinorVersion)' + imageName: '$(Image.TaggedName)' + includeLatestTag: true + useDefaultContext: false + buildContext: ./src/ + - task: Docker@1 + displayName: 'Push ''{major}.{minor}.{patch}'' to Docker Hub' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Push an image' + imageName: '$(Image.TaggedName)' + - task: Docker@1 + displayName: 'Push ''{major}.{minor}'' to Docker Hub' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Push an image' + imageName: '$(Image.Name):$(Image.MajorMinorVersion)' + - task: Docker@1 + displayName: 'Push ''latest'' to Docker Hub' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Push an image' + imageName: '$(Image.Name):latest' +- stage: ReleaseGitHub + displayName: Release on GitHub + dependsOn: Build + jobs: + - job: CreateRelease + displayName: Create Release + pool: + vmImage: ubuntu-16.04 + steps: + - task: GitHubRelease@0 + displayName: 'Create GitHub Release' + inputs: + gitHubConnection: 'Tom Kerkhove (GitHub - OAuth)' + repositoryName: tomkerkhove/promitor + action: Create + tagSource: manual + tag: '$(Release.TagName)' + title: '$(Release.Title)' + releaseNotesSource: input + isDraft: true + releaseNotes: | + ### Breaking Changes + Here are a list of breaking changes and how to mitigate them: + - TBW (#) - _Use new approach documented here_ + ### Getting started + Running Promitor Scraper is super easy: + ``` + docker run -d -p 8999:80 --name promitor-agent-scraper + --env PROMITOR_AUTH_APPID='' \ + --env-file C:/Promitor/az-mon-auth.creds \ + --volume C:/Promitor/metrics-declaration.yaml:/config/metrics-declaration.yaml \ + tomkerkhove/promitor-agent-scraper:$(Image.Version) + ``` + ### Docker Image information + New Docker image tags are available: + - `latest` + - `$(Image.Version)` + - `$(Image.MajorMinorVersion)` + + Docker image is available on [Docker Hub](https://hub.docker.com/r/tomkerkhove/promitor-agent-scraper/).
+ For more information about our tagging strategy, feel free to read our [documentation](https://promitor.io/deployment/#image-tagging-strategy). +- stage: ReleaseHelm + displayName: Release Helm Chart + dependsOn: Build + jobs: + - job: PushHelmChart + displayName: Push Helm Chart to ACR + pool: + vmImage: ubuntu-16.04 + steps: + - task: HelmInstaller@0 + inputs: + helmVersion: '2.9.1' + - powershell: | + mkdir output/ + helm package promitor-agent-scraper/ --app-version $(Helm.App.Version) --version $(Helm.Chart.Version) --destination output/ + workingDirectory: charts + displayName: 'Package Helm Chart' + - task: AzureCLI@1 + displayName: 'Push Helm Chart to Azure Container Registry' + inputs: + azureSubscription: 'Visual Studio Enterprise (0f9d7fea-99e8-4768-8672-06a28514f77e)' + scriptLocation: inlineScript + inlineScript: | + az configure --defaults acr=promitor + az acr helm push --name promitor charts/output/promitor-agent-scraper-$(Helm.Chart.Version).tgz --force \ No newline at end of file diff --git a/build/azure-devops/agents-scraper-release-preview.yml b/build/azure-devops/agents-scraper-release-preview.yml new file mode 100644 index 000000000..d4a084dac --- /dev/null +++ b/build/azure-devops/agents-scraper-release-preview.yml @@ -0,0 +1,83 @@ +name: $(Image.Version) +resources: +- repo: self +trigger: none +pr: none +variables: + DotNet.SDK.Version: '2.2.301' + Image.Name: 'tomkerkhove/promitor-agent-scraper' + Image.TaggedName: '$(Image.Name):$(Image.Version)' + Release.TagName: '$(Build.BuildNumber)' + # Release.Title is configured in the build definition as settable at queue time + # Image.Version is configured in the build definition as settable at queue time +stages: +- stage: Build + displayName: Build and Push Docker image + jobs: + - job: Build + pool: + vmImage: ubuntu-16.04 + steps: + - task: DotNetCoreInstaller@0 + displayName: 'Install .NET SDK' + inputs: + version: '$(DotNet.SDK.Version)' + - task: DotNetCoreCLI@2 + displayName: 'Run Unit Tests' + inputs: + command: test + projects: src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj + - task: Docker@1 + displayName: 'Build Docker image' + inputs: + dockerFile: ./src/Promitor.Scraper.Host/Dockerfile + imageName: '$(Image.TaggedName)' + includeLatestTag: true + useDefaultContext: false + buildContext: ./src/ + - task: Docker@1 + displayName: 'Push preview to Docker Hub' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Push an image' + imageName: '$(Image.TaggedName)' +- stage: ReleaseGitHub + displayName: Release on GitHub + dependsOn: Build + jobs: + - job: CreateRelease + displayName: Create Preview Release + pool: + vmImage: ubuntu-16.04 + steps: + - task: GitHubRelease@0 + displayName: 'Create GitHub Release' + inputs: + gitHubConnection: 'Tom Kerkhove (GitHub - OAuth)' + repositoryName: tomkerkhove/promitor + action: Create + tagSource: manual + tag: '$(Release.TagName)' + title: '$(Release.Title)' + releaseNotesSource: input + isDraft: true + isPreRelease: true + releaseNotes: | + ### Breaking Changes + Here are a list of breaking changes and how to mitigate them: + - TBW (#) - _Use new approach documented here_ + ### Getting started + Running Promitor Scraper Agent is super easy: + ``` + docker run -d -p 8999:80 --name promitor-agent-scraper + --env PROMITOR_AUTH_APPID='' \ + --env-file C:/Promitor/az-mon-auth.creds \ + --volume C:/Promitor/metrics-declaration.yaml:/config/metrics-declaration.yaml \ + tomkerkhove/promitor-agent-scraper:$(Image.Version) + ``` + ### Docker Image information + New Docker image tag is available: `$(Image.Version)` on [Docker Hub](https://hub.docker.com/r/tomkerkhove/promitor-agent-scraper).
+ For more information about our tagging strategy, feel free to read our [documentation](https://promitor.io/deployment/#image-tagging-strategy). + ## Features + - TBW (#) diff --git a/build/azure-devops/docker-hub-bot-for-prs-ci.yml b/build/azure-devops/docker-hub-bot-for-prs-ci.yml new file mode 100644 index 000000000..089cb0bee --- /dev/null +++ b/build/azure-devops/docker-hub-bot-for-prs-ci.yml @@ -0,0 +1,38 @@ +name: $(Date:yyyyMMdd)$(Rev:.r) +trigger: none +pr: + branches: + include: + - master + paths: + include: + - deploy/automation/docker-hub/ci/* + - .azure-devops/docker-hub-bot-for-prs-ci.yml +stages: +- stage: Build + displayName: Verify Tooling + jobs: + - job: Tooling + displayName: Verify ARM Template + pool: + vmImage: ubuntu-16.04 + steps: + - powershell: | + $prNumber = '$(System.PullRequest.PullRequestNumber)' + $buildNumber = '$(Build.BuildNumber)' + Write-Host "Initial build number: '$buildNumber'" + Write-Host "PR Number '$prNumber'" + $buildNumber = 'PR$(System.PullRequest.PullRequestNumber)' + Write-Host "##vso[build.updatebuildnumber]$buildNumber" + Write-Host "Build number is '$buildNumber'" + displayName: 'Change Build Number to PR format' + condition: eq(variables['Build.Reason'], 'PullRequest') + - task: AzureResourceGroupDeployment@2 + displayName: 'Validate Docker Hub Bot ARM Template' + inputs: + azureSubscription: 'Visual Studio Enterprise (0f9d7fea-99e8-4768-8672-06a28514f77e)' + resourceGroupName: 'promitor' + location: 'West Europe' + csmFile: 'deploy/automation/docker-hub/ci/azuredeploy.json' + csmParametersFile: 'deploy/automation/docker-hub/ci/azuredeploy.parameters.json' + deploymentMode: Validation \ No newline at end of file diff --git a/build/azure-devops/docker-hub-bot-for-prs-deploy.yml b/build/azure-devops/docker-hub-bot-for-prs-deploy.yml new file mode 100644 index 000000000..c756620c0 --- /dev/null +++ b/build/azure-devops/docker-hub-bot-for-prs-deploy.yml @@ -0,0 +1,40 @@ +name: $(Date:yyyyMMdd)$(Rev:.r) +resources: +- repo: self +trigger: + batch: true + branches: + include: + - master + paths: + include: + - deploy/automation/docker-hub/ci/* +pr: none +variables: + LogicApp.Name: 'promitor-automation-github-ci-scraper' + GitHub.Repo.Owner: 'tomkerkhove' + GitHub.Repo.Name: 'promitor' + GitHub.Bot.Name: 'promitor-bot' +stages: +- stage: Deploy + jobs: + - job: DeployToAzure + displayName: Deploy to Azure (ARM) + pool: + vmImage: ubuntu-16.04 + steps: + - task: qetza.replacetokens.replacetokens-task.replacetokens@3 + displayName: 'Replace tokens in tooling' + inputs: + rootDirectory: 'deploy/automation/docker-hub/ci/' + targetFiles: azuredeploy.parameters.json + verbosity: detailed + actionOnMissing: fail + - task: AzureResourceGroupDeployment@2 + displayName: 'Deploy CI bot for Docker Hub updates' + inputs: + azureSubscription: 'Visual Studio Enterprise (0f9d7fea-99e8-4768-8672-06a28514f77e)' + resourceGroupName: promitor + location: 'West Europe' + csmFile: 'deploy/automation/docker-hub/ci/azuredeploy.json' + csmParametersFile: 'deploy/automation/docker-hub/ci/azuredeploy.parameters.json' \ No newline at end of file diff --git a/build/azure-devops/scraper-ci.yml b/build/azure-devops/scraper-ci.yml new file mode 100644 index 000000000..20aaaad51 --- /dev/null +++ b/build/azure-devops/scraper-ci.yml @@ -0,0 +1,209 @@ +name: $(Date:yyyyMMdd)$(Rev:.r) +resources: +- repo: self +trigger: +- master +pr: + branches: + include: + - master + paths: + include: + - src/* + - .azure-devops/scraper-ci.yml + - charts/promitor-agent-scraper/* +variables: + DotNet.SDK.Version: '2.2.301' + Image.Name: 'tomkerkhove/promitor-agent-scraper-ci' + Image.TaggedName: '$(Image.Name):$(Build.BuildNumber)' +stages: +- stage: Build + dependsOn: [] + jobs: + - job: Build + displayName: Build Codebase + condition: succeeded() + pool: + vmImage: ubuntu-16.04 + steps: + - task: DotNetCoreInstaller@0 + displayName: 'Install .NET SDK' + inputs: + version: '$(DotNet.SDK.Version)' + - task: DotNetCoreCLI@2 + displayName: 'dotnet build' + inputs: + projects: src/Promitor.sln + arguments: '--configuration release' + - task: CopyFiles@2 + displayName: 'Copy Build Files' + inputs: + contents: 'src/**' + targetFolder: '$(Pipeline.Workspace)/build' + - task: PublishPipelineArtifact@0 + displayName: 'Publish Build Pipeline Artifact' + inputs: + targetPath: '$(Pipeline.Workspace)/build' + artifactName: Build +- stage: CodeQuality + displayName: Code Quality + dependsOn: [Build] + jobs: + - job: RunCodeQuality + displayName: Run Code Quality + condition: succeeded() + pool: + vmImage: windows-2019 + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download Build Artifact' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - task: DotNetCoreInstaller@0 + displayName: 'Import .Net Core Sdk ($(DotNet.Sdk.Version))' + inputs: + version: '$(DotNet.Sdk.Version)' + - task: DotNetCoreCLI@2 + displayName: 'Restore NuGet Packages' + inputs: + command: restore + projects: 'src/Promitor.sln' + - task: alanwales.resharper-code-analysis.custom-build-task.ResharperCli@1 + inputs: + SolutionOrProjectPath: 'src/Promitor.sln' + AdditionalArguments: '/disable-settings-layers:SolutionPersonal --properties:Configuration=$(Build.Configuration)' + env: + MSBuildSDKsPath: '$(Agent.ToolsDirectory)/dncs/$(DotNet.Sdk.Version)/x64/sdk/$(DotNet.Sdk.Version)/Sdks' +- stage: Test + displayName: Run Tests + dependsOn: [Build] + jobs: + - job: RunUnitTests + displayName: Run Unit Tests + condition: succeeded() + pool: + vmImage: ubuntu-16.04 + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download Build Artifact' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + - task: DotNetCoreCLI@2 + displayName: 'dotnet test' + inputs: + command: test + projects: src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj + arguments: '--configuration release --no-build' +- stage: Docker + displayName: Docker Image + dependsOn: [] + jobs: + - job: DockerBuild + displayName: Build Docker Image Tests + condition: succeeded() + pool: + vmImage: ubuntu-16.04 + steps: + - powershell: | + $prNumber = '$(System.PullRequest.PullRequestNumber)' + $buildNumber = '$(Build.BuildNumber)' + Write-Host "Initial build number: '$buildNumber'" + Write-Host "PR Number '$prNumber'" + $buildNumber = 'PR$(System.PullRequest.PullRequestNumber)' + Write-Host "##vso[build.updatebuildnumber]$buildNumber" + Write-Host "Build number is '$buildNumber'" + displayName: 'Change Build Number to PR format' + condition: eq(variables['Build.Reason'], 'PullRequest') + - task: Docker@1 + displayName: 'Build an image' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + dockerFile: ./src/Promitor.Scraper.Host/Dockerfile + arguments: '--tag promitor-agent-scraper-ci --no-cache' + useDefaultContext: false + buildContext: ./src/ + imageName: '$(Image.TaggedName)' + addDefaultLabels: false + - task: Docker@1 + displayName: 'Run an image' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Run an image' + imageName: '$(Image.TaggedName)' + containerName: 'promitor-ci' + ports: '8999:80' + volumes: '/src/metric-config.yaml:/config/metrics-declaration.yaml promitor-agent-scraper-ci' + envVars: | + PROMITOR_AUTH_APPID='$(Container.Env.AzureMonitor.Id)' + PROMITOR_AUTH_APPKEY='$(Container.Env.AzureMonitor.Key)' + - task: Docker@1 + displayName: 'Push ''$(Image.Name)'' image to Docker Hub' + inputs: + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'Docker Hub' + command: 'Push an image' + imageName: '$(Image.TaggedName)' + condition: eq(variables['Build.Reason'], 'PullRequest') +- stage: Helm + displayName: Helm Chart + dependsOn: Docker + jobs: + - job: HelmChart + displayName: Lint, Package & Push Chart + condition: succeeded() + variables: + Helm.Chart.Version: '0.0.0-$(Build.BuildNumber)' + Helm.Chart.Name: 'promitor-agent-scraper-ci' + pool: + vmImage: ubuntu-16.04 + steps: + - task: HelmInstaller@0 + inputs: + helmVersion: '2.9.1' + - powershell: | + $prNumber = '$(System.PullRequest.PullRequestNumber)' + $buildNumber = '$(Build.BuildNumber)' + Write-Host "Initial build number: '$buildNumber'" + Write-Host "PR Number '$prNumber'" + $buildNumber = 'PR$(System.PullRequest.PullRequestNumber)' + Write-Host "##vso[build.updatebuildnumber]$buildNumber" + Write-Host "Build number is '$buildNumber'" + displayName: 'Change Build Number to PR format' + condition: eq(variables['Build.Reason'], 'PullRequest') + - powershell: | + helm lint promitor-agent-scraper/ --strict + workingDirectory: charts + displayName: 'Lint Helm Chart' + - task: PowerShell@2 + displayName: 'Transform Helm Chart in CI Chart' + inputs: + targetType: filePath + filePath: ./build/helm/CI/Transform-Chart.ps1 + arguments: '-chartName "$(Helm.Chart.Name)" -imageName "$(Image.Name)" -imageTag "$(Build.BuildNumber)"' + workingDirectory: 'charts' + - task: PowerShell@2 + displayName: 'Package Helm Chart' + inputs: + targetType: filePath + filePath: ./build/helm/CI/Package-Chart.ps1 + arguments: '-chartName "$(Helm.Chart.Name)" -chartVersion "$(Helm.Chart.Version)"' + workingDirectory: 'charts' + - task: AzureCLI@1 + displayName: 'Push Helm Chart to Azure Container Registry' + inputs: + azureSubscription: 'Visual Studio Enterprise (0f9d7fea-99e8-4768-8672-06a28514f77e)' + scriptLocation: inlineScript + inlineScript: | + az configure --defaults acr=promitor + az acr helm push --name promitor charts/output/$(Helm.Chart.Name)-$(Helm.Chart.Version).tgz --force + condition: eq(variables['Build.Reason'], 'PullRequest') + - task: PublishBuildArtifacts@1 + displayName: 'Publish Helm Chart' + inputs: + PathtoPublish: charts/output/$(Helm.Chart.Name)-$(Helm.Chart.Version).tgz + ArtifactName: helm + condition: eq(variables['Build.Reason'], 'PullRequest') \ No newline at end of file