diff --git a/.devops/pipelines/jobs.ci.build.docker.yaml b/.devops/pipelines/jobs.ci.build.docker.yaml index 9fcba63..a6594a9 100644 --- a/.devops/pipelines/jobs.ci.build.docker.yaml +++ b/.devops/pipelines/jobs.ci.build.docker.yaml @@ -1,75 +1,51 @@ parameters: -- name: pool - type: string - default: "" -- name: arch - default: "" + - name: pool + type: string + default: "" + - name: arch + default: "" jobs: -- job: build_docker_${{ parameters.arch }} - displayName: "Docker ${{ parameters.arch }} image" - pool: - ${{ if eq(parameters.pool, '') }}: - vmImage: "ubuntu-latest" - ${{ if ne(parameters.pool, '') }}: - name: "${{ parameters.pool }}" - ${{ if ne(parameters.arch, '') }}: - demands: - - ${{ if eq(parameters.arch, 'amd64') }}: - - Agent.OSArchitecture -equals X64 - - ${{ if eq(parameters.arch, 'arm') }}: - - Agent.OSArchitecture -equals ARM - - ${{ if eq(parameters.arch, 'arm64') }}: - - Agent.OSArchitecture -equals ARM64 - variables: - - ${{ if eq(parameters.arch, 'amd64') }}: - - name: Docker.CLI.Architecture - value: amd64 - - ${{ if eq(parameters.arch, 'arm64') }}: - - name: Docker.CLI.Architecture - value: arm64 - - ${{ if eq(parameters.arch, 'arm') }}: - - name: Docker.CLI.Architecture - value: armhf - - name: Docker.Image.Architecture - value: ${{ parameters.arch }} + - job: build_docker_${{ parameters.arch }} + displayName: "Docker ${{ parameters.arch }} image" + pool: + ${{ if eq(parameters.pool, '') }}: + vmImage: "ubuntu-latest" + ${{ if ne(parameters.pool, '') }}: + name: "${{ parameters.pool }}" + ${{ if ne(parameters.arch, '') }}: + demands: + - ${{ if eq(parameters.arch, 'amd64') }}: + - Agent.OSArchitecture -equals X64 + - ${{ if eq(parameters.arch, 'arm') }}: + - Agent.OSArchitecture -equals ARM + - ${{ if eq(parameters.arch, 'arm64') }}: + - Agent.OSArchitecture -equals ARM64 + variables: + - name: Docker.Image.Architecture + value: ${{ parameters.arch }} - steps: - - script: | - docker version - if [ "$?" -ne "0" ]; then - apt-get update - apt-get install \ - apt-transport-https \ - ca-certificates \ - curl \ - gnupg2 \ - software-properties-common - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - - add-apt-repository \ - "deb [arch=$(Docker.CLI.Architecture)] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) \ - stable" - apt-get update - apt-get install docker-ce docker-ce-cli containerd.io - fi - displayName: "Docker install" + steps: + - task: DockerInstaller@0 + displayName: "Docker install" + inputs: + dockerVersion: "19.03.9" - - task: Docker@2 - displayName: 'Build image' - inputs: - containerRegistry: 'Emberstack Docker Hub' - repository: $(imageRepository) - Dockerfile: src/ES.Kubernetes.Reflector.Host/Dockerfile - command: build - buildContext: src - tags: 'build-$(Build.BuildNumber)-$(Docker.Image.Architecture)' + - task: Docker@2 + displayName: "Build image" + inputs: + containerRegistry: "Emberstack Docker Hub" + repository: $(imageRepository) + Dockerfile: src/ES.Kubernetes.Reflector.Host/Dockerfile + command: build + buildContext: src + tags: "build-$(Build.BuildNumber)-$(Docker.Image.Architecture)" - - task: Docker@2 - displayName: "Push image" - inputs: - containerRegistry: "Emberstack Docker Hub" - repository: $(imageRepository) - command: push - tags: | - build-$(Build.BuildNumber)-$(Docker.Image.Architecture) + - task: Docker@2 + displayName: "Push image" + inputs: + containerRegistry: "Emberstack Docker Hub" + repository: $(imageRepository) + command: push + tags: | + build-$(Build.BuildNumber)-$(Docker.Image.Architecture) diff --git a/.devops/pipelines/stage.cd.yaml b/.devops/pipelines/stage.cd.yaml index f64e78a..25d382f 100644 --- a/.devops/pipelines/stage.cd.yaml +++ b/.devops/pipelines/stage.cd.yaml @@ -1,83 +1,82 @@ parameters: architectures: [] - stages: -- stage: cd - displayName: "CD" - dependsOn: 'ci' - condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'Manual'), in(variables['Build.SourceBranchName'], 'master')) - jobs: - - job: release - displayName: "Release" - pool: - vmImage: ubuntu-latest - variables: - - group: "OpenSource.GitHub" - - name: "manifest.images" - value: "" - steps: - - checkout: none - - download: current - artifact: 'helm' - displayName: "Download helm artifact" - - download: current - artifact: 'kubectl' - displayName: "Download kubectl artifact" - - task: DockerInstaller@0 - displayName: 'Docker install' - inputs: - dockerVersion: '19.03.5' - - task: Docker@2 - displayName: "Docker login" - inputs: - containerRegistry: "Emberstack Docker Hub" - command: login - - task: HelmInstaller@1 - inputs: - helmVersionToInstall: '3.1.1' - displayName: "Helm install" - - ${{ each architecture in parameters.architectures }}: - - script: | - docker pull $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} - echo '##vso[task.setvariable variable=manifest.images]$(manifest.images) $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }}' - docker tag $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} $(imageRepository):$(Build.BuildNumber)-${{ architecture.arch }} - docker push $(imageRepository):$(Build.BuildNumber)-${{ architecture.arch }} - displayName: "Retag ${{ architecture.arch }} image" - - script: | - docker manifest create $(imageRepository):$(Build.BuildNumber) $(manifest.images) - docker manifest push $(imageRepository):$(Build.BuildNumber) - docker manifest create $(imageRepository):latest $(manifest.images) - docker manifest push $(imageRepository):latest - displayName: 'Create and push multi-arch manifest' - - script: | - git config --global user.email "$(emberstack-agent-email)" - git config --global user.name "$(emberstack-agent-name)" - git clone https://$(emberstack-agent-username):$(emberstack-agent-pat)@github.com/emberstack/helm-charts.git - - mkdir -p helm-charts/charts - cp $(Pipeline.Workspace)/helm/reflector-$(Build.BuildNumber).tgz helm-charts/charts - - cd helm-charts - rm index.yaml - helm repo index ./ - git add . - git status - git commit -m "Added reflector-$(Build.BuildNumber).tgz" - git push - displayName: 'GitHub - Commit chart' - - script: | - mkdir -p github - cp $(Pipeline.Workspace)/kubectl/reflector-$(Build.BuildNumber).yaml github/reflector.yaml - displayName: 'GitHub - Prepare artifacts' - - task: GitHubRelease@1 - displayName: 'GitHub - Create release' - inputs: - gitHubConnection: GitHub - repositoryName: 'emberstack/kubernetes-reflector' - tagSource: userSpecifiedTag - tag: 'v$(Build.BuildNumber)' - title: 'Release v$(Build.BuildNumber)' - releaseNotesSource: inline - releaseNotes: 'The release process is automated.' - assets: '$(System.DefaultWorkingDirectory)/github/*.*' \ No newline at end of file + - stage: cd + displayName: "CD" + dependsOn: "ci" + condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'Manual'), in(variables['Build.SourceBranchName'], 'master')) + jobs: + - job: release + displayName: "Release" + pool: + vmImage: ubuntu-latest + variables: + - group: "OpenSource.GitHub" + - name: "manifest.images" + value: "" + steps: + - checkout: none + - download: current + artifact: "helm" + displayName: "Download helm artifact" + - download: current + artifact: "kubectl" + displayName: "Download kubectl artifact" + - task: DockerInstaller@0 + displayName: "Docker install" + inputs: + dockerVersion: "19.03.5" + - task: Docker@2 + displayName: "Docker login" + inputs: + containerRegistry: "Emberstack Docker Hub" + command: login + - task: HelmInstaller@1 + inputs: + helmVersionToInstall: "3.1.1" + displayName: "Helm install" + - ${{ each architecture in parameters.architectures }}: + - script: | + docker pull $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} + echo '##vso[task.setvariable variable=manifest.images]$(manifest.images) $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }}' + docker tag $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} $(imageRepository):$(Build.BuildNumber)-${{ architecture.arch }} + docker push $(imageRepository):$(Build.BuildNumber)-${{ architecture.arch }} + displayName: "Retag ${{ architecture.arch }} image" + - script: | + docker manifest create $(imageRepository):$(Build.BuildNumber) $(manifest.images) + docker manifest push $(imageRepository):$(Build.BuildNumber) + docker manifest create $(imageRepository):latest $(manifest.images) + docker manifest push $(imageRepository):latest + displayName: "Create and push multi-arch manifest" + - script: | + git config --global user.email "$(emberstack-agent-email)" + git config --global user.name "$(emberstack-agent-name)" + git clone https://$(emberstack-agent-username):$(emberstack-agent-pat)@github.com/emberstack/helm-charts.git + + mkdir -p helm-charts/charts + cp $(Pipeline.Workspace)/helm/reflector-$(Build.BuildNumber).tgz helm-charts/charts + + cd helm-charts + rm index.yaml + helm repo index ./ + git add . + git status + git commit -m "Added reflector-$(Build.BuildNumber).tgz" + git push + displayName: "GitHub - Commit chart" + - script: | + mkdir -p github + cp $(Pipeline.Workspace)/kubectl/reflector-$(Build.BuildNumber).yaml github/reflector.yaml + displayName: "GitHub - Prepare artifacts" + - task: GitHubRelease@1 + displayName: "GitHub - Create release" + inputs: + gitHubConnection: GitHub + repositoryName: "emberstack/kubernetes-reflector" + tagSource: userSpecifiedTag + tag: "v$(Build.BuildNumber)" + title: "Release v$(Build.BuildNumber)" + releaseNotesSource: inline + releaseNotes: "The release process is automated." + assets: "$(System.DefaultWorkingDirectory)/github/*.*" diff --git a/.devops/pipelines/stage.ci.yaml b/.devops/pipelines/stage.ci.yaml index 30bf91c..339e31f 100644 --- a/.devops/pipelines/stage.ci.yaml +++ b/.devops/pipelines/stage.ci.yaml @@ -1,76 +1,73 @@ parameters: architectures: [] - stages: -- stage: ci - displayName: "CI" - jobs: - - job: build_helm - displayName: "Helm" - pool: - vmImage: ubuntu-latest - steps: - - script: | - mkdir -p artifacts/helm - mkdir -p artifacts/kubectl - workingDirectory: '$(Build.ArtifactStagingDirectory)' - displayName: 'Create Artifacts directories' - - task: HelmInstaller@1 - inputs: - helmVersionToInstall: '3.1.1' - displayName: "Helm install" - - script: | - cp README.md src/helm/reflector/README.md - displayName: 'import README' - - script: | - helm package --destination $(Build.ArtifactStagingDirectory)/artifacts/helm --version $(Build.BuildNumber) --app-version $(Build.BuildNumber) src/helm/reflector - displayName: 'Helm package chart' - - script: 'helm template --namespace kube-system reflector $(Build.ArtifactStagingDirectory)/artifacts/helm/reflector-$(Build.BuildNumber).tgz > $(Build.ArtifactStagingDirectory)/artifacts/kubectl/reflector-$(Build.BuildNumber).yaml' - workingDirectory: src/helm - displayName: 'Helm template chart' - - publish: '$(Build.ArtifactStagingDirectory)/artifacts/helm' - artifact: 'helm' - displayName: "Publish helm artifact" - - publish: '$(Build.ArtifactStagingDirectory)/artifacts/kubectl' - artifact: 'kubectl' - displayName: "Publish kubectl artifact" - - - - ${{ each architecture in parameters.architectures }}: - - template: jobs.ci.build.docker.yaml - parameters: - arch: ${{ architecture.arch }} - pool: ${{ architecture.pool }} + - stage: ci + displayName: "CI" + jobs: + - job: build_helm + displayName: "Helm" + pool: + vmImage: ubuntu-latest + steps: + - script: | + mkdir -p artifacts/helm + mkdir -p artifacts/kubectl + workingDirectory: "$(Build.ArtifactStagingDirectory)" + displayName: "Create Artifacts directories" + - task: HelmInstaller@1 + inputs: + helmVersionToInstall: "3.1.1" + displayName: "Helm install" + - script: | + cp README.md src/helm/reflector/README.md + displayName: "import README" + - script: | + helm package --destination $(Build.ArtifactStagingDirectory)/artifacts/helm --version $(Build.BuildNumber) --app-version $(Build.BuildNumber) src/helm/reflector + displayName: "Helm package chart" + - script: "helm template --namespace kube-system reflector $(Build.ArtifactStagingDirectory)/artifacts/helm/reflector-$(Build.BuildNumber).tgz > $(Build.ArtifactStagingDirectory)/artifacts/kubectl/reflector-$(Build.BuildNumber).yaml" + workingDirectory: src/helm + displayName: "Helm template chart" + - publish: "$(Build.ArtifactStagingDirectory)/artifacts/helm" + artifact: "helm" + displayName: "Publish helm artifact" + - publish: "$(Build.ArtifactStagingDirectory)/artifacts/kubectl" + artifact: "kubectl" + displayName: "Publish kubectl artifact" - - - job: build_docker_multiarch - displayName: "Docker multiarch image" - pool: - vmImage: ubuntu-latest - dependsOn: - - ${{ each architecture in parameters.architectures }}: - - build_docker_${{ architecture.arch}} - variables: - - name: "manifest.images" - value: "" - steps: - - task: DockerInstaller@0 - displayName: 'Docker install' - inputs: - dockerVersion: '19.03.5' - - task: Docker@2 - displayName: "Docker login" - inputs: - containerRegistry: "Emberstack Docker Hub" - command: login - ${{ each architecture in parameters.architectures }}: - - script: | - docker pull $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} - echo '##vso[task.setvariable variable=manifest.images]$(manifest.images) $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }}' - displayName: "Pull ${{ architecture.arch }} image" - - script: | - docker manifest create $(imageRepository):build-$(Build.BuildNumber) $(manifest.images) - docker manifest inspect $(imageRepository):build-$(Build.BuildNumber) - docker manifest push $(imageRepository):build-$(Build.BuildNumber) - displayName: "Create and push multi-arch manifest" \ No newline at end of file + - template: jobs.ci.build.docker.yaml + parameters: + arch: ${{ architecture.arch }} + pool: ${{ architecture.pool }} + + - job: build_docker_multiarch + displayName: "Docker multiarch image" + pool: + vmImage: ubuntu-latest + dependsOn: + - ${{ each architecture in parameters.architectures }}: + - build_docker_${{ architecture.arch}} + variables: + - name: "manifest.images" + value: "" + steps: + - task: DockerInstaller@0 + displayName: "Docker install" + inputs: + dockerVersion: "19.03.5" + - task: Docker@2 + displayName: "Docker login" + inputs: + containerRegistry: "Emberstack Docker Hub" + command: login + - ${{ each architecture in parameters.architectures }}: + - script: | + docker pull $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }} + echo '##vso[task.setvariable variable=manifest.images]$(manifest.images) $(imageRepository):build-$(Build.BuildNumber)-${{ architecture.arch }}' + displayName: "Pull ${{ architecture.arch }} image" + - script: | + docker manifest create $(imageRepository):build-$(Build.BuildNumber) $(manifest.images) + docker manifest inspect $(imageRepository):build-$(Build.BuildNumber) + docker manifest push $(imageRepository):build-$(Build.BuildNumber) + displayName: "Create and push multi-arch manifest" diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index 7ea1c6a..f1bc585 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -4,7 +4,7 @@ variables: version: 5.1 buildConfiguration: "Release" imageRepository: "emberstack/kubernetes-reflector" - DOCKER_CLI_EXPERIMENTAL: 'enabled' + DOCKER_CLI_EXPERIMENTAL: "enabled" trigger: branches: @@ -12,25 +12,24 @@ trigger: - "*" paths: include: - - src/* - - .devops/* - - azure-pipelines.yaml + - src/* + - .devops/* + - azure-pipelines.yaml stages: -- template: .devops/pipelines/stage.ci.yaml - parameters: - architectures: - - arch: amd64 - pool: winromulus-devops - - arch: arm - pool: winromulus-devops - - arch: arm64 - pool: winromulus-devops + - template: .devops/pipelines/stage.ci.yaml + parameters: + architectures: + - arch: amd64 + pool: winromulus-devops + - arch: arm + pool: winromulus-devops + - arch: arm64 + pool: winromulus-devops - -- template: .devops/pipelines/stage.cd.yaml - parameters: - architectures: - - arch: amd64 - - arch: arm - - arch: arm64 \ No newline at end of file + - template: .devops/pipelines/stage.cd.yaml + parameters: + architectures: + - arch: amd64 + - arch: arm + - arch: arm64