From 771fa82b7dbc9e321628e313f501dd03ee7a6f99 Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Tue, 25 May 2021 12:15:03 -0700 Subject: [PATCH] Fix issue with release scripts (#1509) --- azure-pipelines.yml | 41 +++---- devops/azure-pipelines.yaml | 212 ------------------------------------ 2 files changed, 21 insertions(+), 232 deletions(-) delete mode 100644 devops/azure-pipelines.yaml diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 07d245bc355..63732e4ba47 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -67,20 +67,20 @@ steps: - script: | make validate-copyright-headers make validate-cainjection-files - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) displayName: 'Validate Source' continueOnError: 'false' - task: GoTool@0 displayName: Get Go 1.13.7 - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: version: '1.13.7' - task: Go@0 displayName: Get Go dependencies - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: command: 'get' arguments: '-d' @@ -88,7 +88,7 @@ steps: - task: Bash@3 displayName: Install kubebuilder, kustomize and test dependencies - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: 'false' inputs: targetType: 'inline' @@ -109,7 +109,7 @@ steps: export PATH=$PATH:$(go env GOPATH)/bin make test-unit displayName: Run unit tests - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: 'false' env: GO111MODULE: on @@ -124,7 +124,7 @@ steps: export TEST_APIM_NAME=$(TEST_APIM_NAME) make test-integration-controllers displayName: Run envtest tests - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: 'false' env: GO111MODULE: on @@ -144,7 +144,7 @@ steps: export KUBEBUILDER_ASSETS=$(go env GOPATH)/kubebuilder/bin make test-v1-secret-naming displayName: Run legacy v1 secret naming tests - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: 'false' env: GO111MODULE: on @@ -163,7 +163,7 @@ steps: kubectl cluster-info make install displayName: Install CRDs into kind cluster - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: 'false' env: GO111MODULE: on @@ -175,20 +175,20 @@ steps: export PATH=$PATH:$(go env GOPATH)/bin make test-process-coverage displayName: Render Coverage Reports - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) continueOnError: true workingDirectory: '$(System.DefaultWorkingDirectory)' - task: PublishCodeCoverageResults@1 displayName: Publish Codecoverage results - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: codeCoverageTool: Cobertura summaryFileLocation: $(System.DefaultWorkingDirectory)/reports/merged-coverage.xml - task: PublishBuildArtifacts@1 displayName: Publish test reports - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: pathtoPublish: '$(System.DefaultWorkingDirectory)/reports' artifactName: reports @@ -204,19 +204,19 @@ steps: - script: docker build -t $(IMAGE_NAME) . displayName: Docker build - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Docker@2 displayName: Login to temporary pipeline ACR - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: containerRegistry: $(PIPELINE_CONTAINER_REGISTRY) command: 'login' - task: Docker@2 displayName: Build and Push Docker Image to temporary ACR for validation - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: containerRegistry: $(PIPELINE_CONTAINER_REGISTRY) repository: '$(IMAGE_NAME)' @@ -246,18 +246,18 @@ steps: workingDirectory: '$(System.DefaultWorkingDirectory)' failOnStandardError: true displayName: Deploy to AKS - Find available AKS cluster and connect to it - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - script: | kubectl create namespace cert-manager kubectl label namespace cert-manager cert-manager.io/disable-validation=true kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml displayName: Deploy to AKS - Install Cert Manager - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: HelmInstaller@1 displayName: Deploy to AKS - Install latest Helm - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: helmVersionToInstall: 'latest' - script: | @@ -266,11 +266,10 @@ steps: echo $img sed -i -e 's@azureserviceoperator:latest@azureserviceoperator:'${img}'@' charts/azure-service-operator/values.yaml displayName: Deploy to AKS - Replace image in values.yaml - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') - task: Bash@3 displayName: Deploy to AKS - Helm Deploy - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: targetType: 'inline' script: | @@ -317,7 +316,7 @@ steps: workingDirectory: '$(System.DefaultWorkingDirectory)' failOnStandardError: true displayName: Deploy to AKS - Clean up deployment and release cluster back to free pool - condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true') + condition: or(eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: Docker@2 condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) @@ -340,6 +339,7 @@ steps: $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) - script: | + set -e export HELM_EXPERIMENTAL_OCI=1 cd charts/azure-service-operator versiontag="$(CONTAINER_REGISTRY_NAME)/$(ASO_HELM_CHART_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)" @@ -357,6 +357,7 @@ steps: condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - script: | + set -e echo "updating kustomize image patch file for manager resource" echo $IMAGE_NAME img="$IMAGE_NAME:$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION" diff --git a/devops/azure-pipelines.yaml b/devops/azure-pipelines.yaml deleted file mode 100644 index 3c8e6144afb..00000000000 --- a/devops/azure-pipelines.yaml +++ /dev/null @@ -1,212 +0,0 @@ -trigger: - branches: - include: - - master - -pool: - vmImage: 'Ubuntu 16.04' - -variables: - MAJOR_VERSION: 0 - MINOR_VERSION: 0 - PATCH_VERSION: $(Build.BuildId) - GOROOT: '/usr/local/go1.13.12' # Go installation path - GOPATH: '$(System.DefaultWorkingDirectory)/gopath' # Go workspace path - GOBIN: '$(GOPATH)/bin' # Go binaries path - MODULE_PATH: '$(GOPATH)/src/$(Build.Repository.Name)' # Path to the module's code - IMAGE_NAME: 'candidate/k8s/azure-service-operator' - KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin - # CONTAINER_REGISTRY: - set this value in Azure Devops variables - Name of Service Connection - # AZURE_SUBSCRIPTION_ID - set this value in Azure Devops variables - # AZURE_TENANT_ID: - set this value in Azure Devops variables - # AZURE_CLIENT_ID: - set this value in Azure Devops variables - # AZURE_CLIENT_SECRET: - set this value in Azure Devops variables - # REQUEUE_AFTER: - set this value in Azure Devops variables - -steps: - -- checkout: self # self represents the repo where the initial Pipelines YAML file was found - lfs: "true" - -- script: | - make validate-copyright-headers - make validate-cainjection-files - displayName: 'Validate Source' - continueOnError: 'false' - -- script: | - set -x - ls -l /usr/local/go* - mkdir -p '$(GOBIN)' - mkdir -p '$(GOPATH)/pkg' - mkdir -p '$(MODULE_PATH)' - shopt -s extglob - mv !(GOPATH) '$(MODULE_PATH)' - echo '##vso[task.prependpath]$(GOBIN)' - echo '##vso[task.prependpath]$(GOROOT)/bin' - go version - go env - displayName: 'Set up the Go workspace' - env: - GO111MODULE: on - -- script: | - set -x - mkdir -p $(MODULE_PATH)/bin - os=$(go env GOOS) - arch=$(go env GOARCH) - # download kubebuilder - curl -sL https://go.kubebuilder.io/dl/2.0.0-alpha.4/${os}/${arch} | tar -xz -C $(MODULE_PATH)/bin - mv $(MODULE_PATH)/bin/kubebuilder_2.0.0-alpha.4_${os}_${arch}/bin/* $(MODULE_PATH)/bin - # download kustomize - curl -o $(MODULE_PATH)/bin/kustomize -sL https://go.kubebuilder.io/kustomize/${os}/${arch} - # set permission - chmod a+x $(MODULE_PATH)/bin/* - # export PATH - export PATH=$PATH:$(MODULE_PATH)/bin - echo '##vso[task.prependpath]$(MODULE_PATH)/bin' - #which kustomize - which kustomize - #kustomize version - kustomize version - go mod download - go get -u github.com/jstemmer/go-junit-report - go get github.com/axw/gocov/gocov - go get github.com/AlekSi/gocov-xml - go get -u gopkg.in/matm/v1/gocov-html - go get golang.org/x/tools/cmd/cover - displayName: 'Install kubebuilder, kustomize and set environment' - env: - GO111MODULE: on - KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin - workingDirectory: '$(MODULE_PATH)' - -# - script: | -# go mod download -# go get -u github.com/jstemmer/go-junit-report -# go get github.com/axw/gocov/gocov -# go get github.com/AlekSi/gocov-xml -# go get -u gopkg.in/matm/v1/gocov-html -# go get golang.org/x/tools/cmd/cover -# go get github.com/onsi/ginkgo/ginkgo -# make test -# gocov convert coverage.txt > coverage.json -# gocov-xml < coverage.json > coverage.xml -# mkdir coverage -# continueOnError: 'false' -# displayName: 'Run unit/mocked tests' -# env: -# GO111MODULE: on -# KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin -# AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) -# AZURE_TENANT_ID: $(AZURE_TENANT_ID) -# AZURE_CLIENT_ID: $(AZURE_CLIENT_ID) -# AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET) -# REQUEUE_AFTER: $(REQUEUE_AFTER) -# workingDirectory: '$(MODULE_PATH)' - -- script: | - set -e - GO111MODULE="on" go get sigs.k8s.io/kind@v0.7.0 - kind create cluster - export KUBECONFIG=$(kind get kubeconfig-path --name="kind") - kubectl cluster-info - make install - kubectl get namespaces - #make test-existing-controllers - make test-integration-controllers - continueOnError: 'false' - displayName: 'Set kind cluster and Run int tests' - env: - GO111MODULE: on - AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID) - AZURE_TENANT_ID: $(AZURE_TENANT_ID) - AZURE_CLIENT_ID: $(AZURE_CLIENT_ID) - AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET) - REQUEUE_AFTER: $(REQUEUE_AFTER) - KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin - BUILD_ID: $(Build.BuildId) - workingDirectory: '$(MODULE_PATH)' - -- task: AzureCLI@2 - displayName: 'Clean up Azure Resources' - condition: always() - env: - BUILD_ID: $(Build.BuildId) - inputs: - azureSubscription: 'CSE AmWest Sub - ASO' - scriptType: bash - scriptLocation: inlineScript - workingDirectory: '$(MODULE_PATH)' - inlineScript: | - make test-cleanup-azure-resources - -# - task: PublishTestResults@2 -# displayName: 'test cluster' -# inputs: -# testRunner: JUnit -# testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml -# failTaskOnFailedTests: 'true' -# failOnStandardError: 'true' - -# - task: PublishTestResults@2 -# displayName: 'existing cluster' -# inputs: -# testRunner: JUnit -# testResultsFiles: $(System.DefaultWorkingDirectory)/**/report-existing.xml -# failTaskOnFailedTests: 'true' -# failOnStandardError: 'true' - -# - task: PublishCodeCoverageResults@1 -# inputs: -# codeCoverageTool: Cobertura -# summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml -# reportDirectory: $(System.DefaultWorkingDirectory)/**/coverage -# failIfCoverageEmpty: 'true' -# failOnStandardError: 'true' - -- script: docker build -t $(IMAGE_NAME) . # add options to this command to meet your needs - condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master')) - displayName: 'Docker build' - workingDirectory: '$(MODULE_PATH)' - -- task: Docker@2 - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - displayName: Login to ACR - inputs: - command: login - containerRegistry: $(CONTAINER_REGISTRY) - -- task: Docker@2 - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - displayName: Build and Push Docker Image $(IMAGE_NAME) - inputs: - command: buildAndPush - containerRegistry: $(CONTAINER_REGISTRY) - repository: $(IMAGE_NAME) - Dockerfile: "$(MODULE_PATH)/Dockerfile" - buildContext: $(MODULE_PATH) - tags: | - latest - $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) - - -- script: | - echo "updating kustomize image patch file for manager resource" - echo $(IMAGE_NAME) - IMG="$(IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)" - echo $(IMG) - sed -i -e 's@IMAGE_URL@'${IMG}'@g' ./config/default/manager_image_patch.yaml - kustomize build config/default > $(Build.ArtifactStagingDirectory)/setup.yaml - set -x - echo $IMG > $(Build.ArtifactStagingDirectory)/azure-service-operator.txt - continueOnError: 'false' - displayName: 'Prepare manifests for publish' - workingDirectory: '$(MODULE_PATH)' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - -- task: PublishBuildArtifacts@1 - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - inputs: - pathtoPublish: $(Build.ArtifactStagingDirectory) - artifactName: drop