From 60e80918aeacfd8da9c26e5d39670bb35a7e9659 Mon Sep 17 00:00:00 2001 From: Russell Seymour Date: Mon, 29 Nov 2021 09:21:38 +0000 Subject: [PATCH 1/3] Added support for the Stacks CLI Created release at end of build so CLI has a version to key from Signed-off-by: Russell Seymour --- .../azure-pipeline-infrastructure-aks.yml | 114 ++++++++++++------ .../azure/azuredevops-vars-template.yml | 53 ++++++++ build/azDevOps/azure/azuredevops-vars.yml | 45 +++++++ stackscli.yml | 14 +++ 4 files changed, 187 insertions(+), 39 deletions(-) create mode 100644 build/azDevOps/azure/azuredevops-vars-template.yml create mode 100644 build/azDevOps/azure/azuredevops-vars.yml create mode 100644 stackscli.yml diff --git a/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml b/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml index d839f8e..ce3010e 100644 --- a/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml +++ b/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml @@ -34,53 +34,50 @@ resources: image: amidostacks/ci-tf:0.0.8 variables: - company: amido - project: stacks - domain: core + - template: azuredevops-vars.yml + # Versioning - version_major: 0 - version_minor: 0 - version_revision: $[counter(join(variables['version_major'], join('-', variables['version_minor'])), 0)] - version_build_number: "$(version_major).$(version_minor).$(version_revision)-$(Build.SourceBranchName)" + - name: version_major + value: 0 + - name: version_minor + value: 0 + - name: version_revision + value: $[counter(join(variables['version_major'], join('-', variables['version_minor'])), 0)] + - name: version_build_number + value: "$(version_major).$(version_minor).$(version_revision)-$(Build.SourceBranchName)" + # SelfConfig - self_repo: stacks-infrastructure-aks - self_repo_dir: "$(Agent.BuildDirectory)/s/$(self_repo)" - self_repo_tf_src: deploy/azure/infra/stacks-aks - self_repo_tf_dir: "$(self_repo_dir)/$(self_repo_tf_src)" - self_pipeline_repo: "$(Agent.BuildDirectory)/s/stacks-pipeline-templates" - self_pipeline_scripts_dir: "$(self_pipeline_repo)/scripts" - # TF STATE CONFIG - tf_state_rg: "Stacks-Ancillary-Resources" - tf_state_storage: "amidostackstfstate" - tf_state_container: "tfstate" - # Stacks operates Terraform states based on workspaces **IT IS VERY IMPORTANT** that you ensure a unique name for each application definition - # Furthermore **IT IS VERY IMPORTANT** that you change the name of a workspace for each deployment stage - # there are some best practices around this if you are going for feature based environments - # - we suggest you create a runtime variable that is dynamically set based on a branch currently running - # **`terraform_state_workspace: `** all states will be saved under this key for this definition - # avoid running anything past dev that is not on master - # sample value: sharedservices - tf_state_key: "core-sharedservices" + - name: self_repo_dir + value: "$(Agent.BuildDirectory)/s/$(self_repo)" + - name: self_repo_tf_src + value: deploy/azure/infra/stacks-aks + - name: self_repo_tf_dir + value: "$(self_repo_dir)/$(self_repo_tf_src)" + - name: self_pipeline_repo + value: "$(Agent.BuildDirectory)/s/stacks-pipeline-templates" + - name: self_pipeline_scripts_dir + value: "$(self_pipeline_repo)/scripts" + # Scripts directory used by pipeline steps - scripts_dir: $(Agent.BuildDirectory)/s/stacks-pipeline-templates/azDevOps/azure/templates/v2/scripts + - name: scripts_dir + value: $(Agent.BuildDirectory)/s/stacks-pipeline-templates/azDevOps/azure/templates/v2/scripts + # AKS/AZURE # This will always be predictably named by setting your company - project - stage - location - compnonent names above # IT IS SET per stage as an output to be consumed by deploy stage - aks_cluster_version: "1.20.7" - region: "westeurope" + - name: aks_cluster_version + value: "1.20.7" + # DEFAULT IMAGE RUNNER - pool_vm_image: ubuntu-20.04 - # Ensure you find this definition in the K8s and Azure steps to prefix with desired subdomain assignment - base_domain_nonprod: nonprod.amidostacks.com - base_domain_internal_nonprod: nonprod.amidostacks.internal - base_domain_prod: prod.amidostacks.com - base_domain_internal_prod: prod.amidostacks.internal + - name: pool_vm_image + value: ubuntu-20.04 + # Yamllint - yamllint_config_file: "${{ variables.self_repo_dir }}/yamllint.conf" - yamllint_scan_directory: "." - # Resource grup that the DNS zones are in - create_dns_zone: false - dns_resource_group: Stacks-Ancillary-Resources + - name: yamllint_config_file + value: "${{ variables.self_repo_dir }}/yamllint.conf" + - name: yamllint_scan_directory + value: "." + stages: - stage: Build @@ -463,3 +460,42 @@ stages: external_dns: false external_dns_yml: $(self_repo_dir)/deploy/k8s_manifests/aks/external-dns.yml domain_filter: $(base_domain_prod) + + - stage: Release + dependsOn: + - Build + - Prod + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['create_release'], 'true')) + variables: + - group: amido-stacks-infra-credentials-nonprod + - name: version_number + value: "$(version_major).$(version_minor).$(version_revision)" + jobs: + - job: CreateGitHubRelease + pool: + vmImage: $(pool_vm_image) + steps: + # Check out the repo so that it can be tagged + - checkout: self + persistCredentials: true + + # Create a tag in the code for this release + - task: Bash@3 + displayName: Tag Code + inputs: + targetType: "inline" + script: | + git config user.name "BuildService" + git config user.email "builder@${COMPANY}.com" + git tag -a v${VERSION_NUMBER} -m "Release created by Azure DevOps" + git push origin v${VERSION_NUMBER} + env: + COMPANY: $(company) + + # Create a GitHub release with these packages + - task: GitHubRelease@0 + displayName: Create GitHub Release + inputs: + gitHubConnection: $(github_release_service_connection) + repositoryName: $(github_org)/$(self_repo) + tag: $(Build.BuildNumber) \ No newline at end of file diff --git a/build/azDevOps/azure/azuredevops-vars-template.yml b/build/azDevOps/azure/azuredevops-vars-template.yml new file mode 100644 index 0000000..8fa3fab --- /dev/null +++ b/build/azDevOps/azure/azuredevops-vars-template.yml @@ -0,0 +1,53 @@ +variables: + - name: region + value: {{ .Input.Cloud.Region }} + - name: company + value: {{ .Input.Business.Company }} + - name: project + value: {{ .Project.Name }} + - name: domain + value: {{ .Input.Business.Domain }} + - name: self_repo + value: {{ .Project.Name }} + + # Terraform Configuration + + # State configuration + + # Stacks operates Terraform states based on workspaces **IT IS VERY IMPORTANT** that you ensure a unique name for each application definition + # Furthermore **IT IS VERY IMPORTANT** that you change the name of a workspace for each deployment stage + # there are some best practices around this if you are going for feature based environments + # avoid running anything past dev that is not on master + - name: tf_state_rg + value: {{ .Input.Terraform.Backend.Group }} + - name: tf_state_storage + value: {{ .Input.Terraform.Backend.Storage }} + - name: tf_state_container + value: {{ .Input.Terraform.Backend.Container }} + - name: tf_state_key + value: $(self-generic-name) + + # Domain names + - name: base_domain_nonprod + value: nonprod.{{ .Input.Network.Base.Domain.External }} + - name: base_domain_internal_nonprod + value: nonprod.{{ .Input.Network.Base.Domain.Internal }} + - name: base_domain_prod + value: prod.{{ .Input.Network.Base.Domain.External }} + - name: base_domain_internal_prod + value: prod.{{ .Input.Network.Base.Domain.Internal }} + + # DNS configuration + - name: dns_zone_resource_group + value: + - name: create_dns_zone + value: false + + # GitHub infomration + - name: create_release + value: false + - name: github_release_service_connection + value: + - name: github_org + value: $(company) + diff --git a/build/azDevOps/azure/azuredevops-vars.yml b/build/azDevOps/azure/azuredevops-vars.yml new file mode 100644 index 0000000..329496f --- /dev/null +++ b/build/azDevOps/azure/azuredevops-vars.yml @@ -0,0 +1,45 @@ +variables: + - name: region + value: westeurope + - name: company + value: amido + - name: project + value: stacks + - name: domain + value: core + - name: self_repo + value: stacks-infrastructure-aks + + # Terraform configuration + - name: tf_state_rg + value: Stacks-Ancillary-Resources + - name: tf_state_storage + value: amidostackstfstate + - name: tf_state_container + value: tfstate + - name: tf_state_key + value: core-sharedservices + + # Domain names + - name: base_domain_nonprod + value: nonprod.amidostacks.com + - name: base_domain_internal_nonprod + value: nonprod.amidostacks.internal + - name: base_domain_prod + value: prod.amidostacks.com + - name: base_domain_internal_prod + value: prod.amidostacks.internal + + # DNS configuration + - name: create_dns_zone + value: false + - name: dns_resource_group + value: Stacks-Ancillary-Resources + + # GitHub infomration + - name: create_release + value: true + - name: github_release_service_connection + value: GitHubReleases + - name: github_org + value: $(company) \ No newline at end of file diff --git a/stackscli.yml b/stackscli.yml new file mode 100644 index 0000000..ebea49c --- /dev/null +++ b/stackscli.yml @@ -0,0 +1,14 @@ +pipeline: + - type: azdo + files: + - name: build + path: build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml + - name: variable + path: build/azDevOps/azure/azuredevops-vars.yml + template: + - name: variable + path: build/azDevOps/azure/azuredevops-vars-template.yml + +setup: + operations: + - action: copy \ No newline at end of file From 512f265c884f4a52ac3bfb3739a6cf297aee8479 Mon Sep 17 00:00:00 2001 From: Russell Seymour Date: Mon, 29 Nov 2021 09:36:11 +0000 Subject: [PATCH 2/3] Corrected key name and variable name Signed-off-by: Russell Seymour --- build/azDevOps/azure/azuredevops-vars-template.yml | 2 +- stackscli.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/azDevOps/azure/azuredevops-vars-template.yml b/build/azDevOps/azure/azuredevops-vars-template.yml index 8fa3fab..72d367a 100644 --- a/build/azDevOps/azure/azuredevops-vars-template.yml +++ b/build/azDevOps/azure/azuredevops-vars-template.yml @@ -1,6 +1,6 @@ variables: - name: region - value: {{ .Input.Cloud.Region }} + value: {{ .Project.Cloud.Region }} - name: company value: {{ .Input.Business.Company }} - name: project diff --git a/stackscli.yml b/stackscli.yml index ebea49c..9434e00 100644 --- a/stackscli.yml +++ b/stackscli.yml @@ -5,7 +5,7 @@ pipeline: path: build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml - name: variable path: build/azDevOps/azure/azuredevops-vars.yml - template: + templates: - name: variable path: build/azDevOps/azure/azuredevops-vars-template.yml From 5a6154a35d9a6e31476278861afc5cfb5be941f0 Mon Sep 17 00:00:00 2001 From: Russell Seymour Date: Tue, 30 Nov 2021 16:12:09 +0000 Subject: [PATCH 3/3] Corrected lint violations Signed-off-by: Russell Seymour --- .../azure-pipeline-infrastructure-aks.yml | 4 +-- .../azure/azuredevops-vars-template.yml | 27 +++++++++---------- build/azDevOps/azure/azuredevops-vars.yml | 4 +-- stackscli.yml | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml b/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml index ce3010e..f5c593e 100644 --- a/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml +++ b/build/azDevOps/azure/azure-pipeline-infrastructure-aks.yml @@ -45,7 +45,7 @@ variables: value: $[counter(join(variables['version_major'], join('-', variables['version_minor'])), 0)] - name: version_build_number value: "$(version_major).$(version_minor).$(version_revision)-$(Build.SourceBranchName)" - + # SelfConfig - name: self_repo_dir value: "$(Agent.BuildDirectory)/s/$(self_repo)" @@ -498,4 +498,4 @@ stages: inputs: gitHubConnection: $(github_release_service_connection) repositoryName: $(github_org)/$(self_repo) - tag: $(Build.BuildNumber) \ No newline at end of file + tag: $(Build.BuildNumber) diff --git a/build/azDevOps/azure/azuredevops-vars-template.yml b/build/azDevOps/azure/azuredevops-vars-template.yml index 72d367a..954f5e3 100644 --- a/build/azDevOps/azure/azuredevops-vars-template.yml +++ b/build/azDevOps/azure/azuredevops-vars-template.yml @@ -1,14 +1,14 @@ variables: - name: region - value: {{ .Project.Cloud.Region }} + value: {{.Project.Cloud.Region}} - name: company - value: {{ .Input.Business.Company }} + value: {{.Input.Business.Company}} - name: project - value: {{ .Project.Name }} + value: {{.Project.Name}} - name: domain - value: {{ .Input.Business.Domain }} + value: {{.Input.Business.Domain}} - name: self_repo - value: {{ .Project.Name }} + value: {{.Project.Name}} # Terraform Configuration @@ -19,23 +19,23 @@ variables: # there are some best practices around this if you are going for feature based environments # avoid running anything past dev that is not on master - name: tf_state_rg - value: {{ .Input.Terraform.Backend.Group }} + value: {{.Input.Terraform.Backend.Group}} - name: tf_state_storage - value: {{ .Input.Terraform.Backend.Storage }} + value: {{.Input.Terraform.Backend.Storage}} - name: tf_state_container - value: {{ .Input.Terraform.Backend.Container }} + value: {{.Input.Terraform.Backend.Container}} - name: tf_state_key value: $(self-generic-name) # Domain names - name: base_domain_nonprod - value: nonprod.{{ .Input.Network.Base.Domain.External }} + value: nonprod.{{.Input.Network.Base.Domain.External}} - name: base_domain_internal_nonprod - value: nonprod.{{ .Input.Network.Base.Domain.Internal }} + value: nonprod.{{.Input.Network.Base.Domain.Internal}} - name: base_domain_prod - value: prod.{{ .Input.Network.Base.Domain.External }} + value: prod.{{.Input.Network.Base.Domain.External}} - name: base_domain_internal_prod - value: prod.{{ .Input.Network.Base.Domain.Internal }} + value: prod.{{.Input.Network.Base.Domain.Internal}} # DNS configuration - name: dns_zone_resource_group @@ -47,7 +47,6 @@ variables: - name: create_release value: false - name: github_release_service_connection - value: + value: - name: github_org value: $(company) - diff --git a/build/azDevOps/azure/azuredevops-vars.yml b/build/azDevOps/azure/azuredevops-vars.yml index 329496f..702d5cf 100644 --- a/build/azDevOps/azure/azuredevops-vars.yml +++ b/build/azDevOps/azure/azuredevops-vars.yml @@ -8,7 +8,7 @@ variables: - name: domain value: core - name: self_repo - value: stacks-infrastructure-aks + value: stacks-infrastructure-aks # Terraform configuration - name: tf_state_rg @@ -42,4 +42,4 @@ variables: - name: github_release_service_connection value: GitHubReleases - name: github_org - value: $(company) \ No newline at end of file + value: $(company) diff --git a/stackscli.yml b/stackscli.yml index 9434e00..3a5a14f 100644 --- a/stackscli.yml +++ b/stackscli.yml @@ -11,4 +11,4 @@ pipeline: setup: operations: - - action: copy \ No newline at end of file + - action: copy