diff --git a/.pipelines/containers/container-template-windows.yaml b/.pipelines/containers/container-template-windows.yaml new file mode 100644 index 0000000000..344c2a714f --- /dev/null +++ b/.pipelines/containers/container-template-windows.yaml @@ -0,0 +1,31 @@ +parameters: + name: "" + arch: "" + tag: "" + +steps: +- task: Docker@2 + displayName: Login + inputs: + containerRegistry: $(ACR_SERVICE_CONNECTION) + command: 'login' + addPipelineData: false + +- powershell: | + powershell.exe -command "& { . .\windows.ps1; Retry({${{ parameters.name }}-image windows-${{ parameters.arch }}-${{ parameters.tag }}}) }" + name: image_build + displayName: Image Build + +- powershell: | + $registry = "acnpublic.azurecr.io" + docker push $registry/azure-${{ parameters.name }}:windows-${{ parameters.arch }}-${{ parameters.tag }} + name: image_push + displayName: Image Push + retryCountOnTaskFailure: 3 + +- task: Docker@2 + displayName: Logout + inputs: + containerRegistry: $(ACR_SERVICE_CONNECTION) + command: 'logout' + addPipelineData: false diff --git a/.pipelines/containers/manifest-template.yaml b/.pipelines/containers/manifest-template.yaml index aa3c44e2c9..c5772d1a70 100644 --- a/.pipelines/containers/manifest-template.yaml +++ b/.pipelines/containers/manifest-template.yaml @@ -1,7 +1,6 @@ parameters: name: "" - oses: "" - arches: "" + platforms: "" tag: "" steps: @@ -14,15 +13,15 @@ steps: - script: | set -e - make ${{ parameters.name }}-multiarch-manifest-create OSES="${{ parameters.oses }}" ARCHES="${{ parameters.arches }}" TAG=${{ parameters.tag }} + make ${{ parameters.name }}-multiarch-manifest-create PLATFORMS="${{ parameters.platforms }}" TAG=${{ parameters.tag }} make ${{ parameters.name }}-image-info TAG=${{ parameters.tag }} name: manifest_build displayName: Manifest Build - script: | set -e - make multiarch-manifest-push REGISTRY=$IMAGE_REGISTRY IMAGE=$(make ${{ parameters.name }}-image-name) TAG=${{ parameters.tag }} - make container-pull REGISTRY=$IMAGE_REGISTRY IMAGE=$(make ${{ parameters.name }}-image-name) TAG=${{ parameters.tag }} + make multiarch-manifest-push IMAGE=$(make ${{ parameters.name }}-image-name) TAG=${{ parameters.tag }} + make container-pull IMAGE=$(make ${{ parameters.name }}-image-name) TAG=${{ parameters.tag }} name: manifest_push displayName: Manifest Push diff --git a/.pipelines/pipeline.yaml b/.pipelines/pipeline.yaml index 50fc83b204..955d099706 100644 --- a/.pipelines/pipeline.yaml +++ b/.pipelines/pipeline.yaml @@ -35,7 +35,7 @@ stages: condition: always() - stage: test - displayName: Test + displayName: Test ACN dependsOn: - setup jobs: @@ -136,8 +136,6 @@ stages: - publish: ./test/apimodels/ artifact: clusterdefinitions - - template: windows-image.yaml - - stage: containerize displayName: Build Images dependsOn: @@ -183,6 +181,26 @@ stages: os: $(os) arch: $(arch) tag: $(TAG) + - job: containerize_windows + displayName: Build Images + variables: + TAG: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] + pool: + name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS)" + strategy: + matrix: + cns_windows_amd64: + arch: amd64 + name: cns + npm_windows_amd64: + arch: amd64 + name: npm + steps: + - template: containers/container-template-windows.yaml + parameters: + name: $(name) + arch: $(arch) + tag: $(TAG) - stage: publish displayName: Publish Multiarch Manifests @@ -200,16 +218,18 @@ stages: matrix: cni-manager: name: cni-manager + platforms: linux/amd64 linux/arm64 cns: name: cns + platforms: linux/amd64 linux/arm64 windows/amd64 npm: name: npm + platforms: linux/amd64 linux/arm64 windows/amd64 steps: - template: containers/manifest-template.yaml parameters: name: $(name) - oses: linux - arches: amd64 arm64 + platforms: $(platforms) tag: $(TAG) - template: singletenancy/aks-swift/e2e-job-template.yaml diff --git a/.pipelines/windows-image.yaml b/.pipelines/windows-image.yaml deleted file mode 100644 index 5fee9f04e8..0000000000 --- a/.pipelines/windows-image.yaml +++ /dev/null @@ -1,56 +0,0 @@ -stages: -- stage: build_windows_images - displayName: Build Windows Images - dependsOn: - - setup - - test - jobs: - - job: NPM - displayName: Build NPM - variables: - tag: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] - pool: - name: "$(BUILD_POOL_NAME_DEFAULT_WINDOWS)" - steps: - - powershell: | - powershell.exe -command "& { . .\windows.ps1; Retry({npm-image windows-amd64-$(tag)}) }" - name: "build_npm" - displayName: "Build" - - - task: Docker@2 - displayName: Docker Login - inputs: - containerRegistry: $(ACR_SERVICE_CONNECTION) - command: 'login' - addPipelineData: false - - - powershell: | - docker tag acnpublic.azurecr.io/azure-npm:windows-amd64-$(tag) acnpublic.azurecr.io/azure-npm:windows-amd64-$(tag)-test - docker push acnpublic.azurecr.io/azure-npm:windows-amd64-$(tag)-test - name: "push_npm" - displayName: "Push" - - - powershell: | - mkdir .\output\images\windows\ - docker save acnpublic.azurecr.io/azure-npm:windows-amd64-$(tag)-test -o .\output\images\windows\azure-npm-windows-amd64-$(tag).tar - name: "save_npm" - displayName: "Save" - - - task: Docker@2 - displayName: Docker Logout - inputs: - containerRegistry: $(ACR_SERVICE_CONNECTION) - command: 'logout' - addPipelineData: false - - - task: CopyFiles@2 - inputs: - sourceFolder: "output" - targetFolder: $(Build.ArtifactStagingDirectory) - condition: succeeded() - - - task: PublishBuildArtifacts@1 - inputs: - artifactName: "output" - pathtoPublish: "$(Build.ArtifactStagingDirectory)" - condition: succeeded() diff --git a/Makefile b/Makefile index 3a35adcea5..c3dad84015 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) GOOSES ?= "linux windows" # To override at the cli do: GOOSES="\"darwin bsd\"" GOARCHES ?= "amd64 arm64" # To override at the cli do: GOARCHES="\"ppc64 mips\"" +WINVER ?= "10.0.20348.643" # Windows specific extensions ifeq ($(GOOS),windows) @@ -180,7 +181,7 @@ containerize-buildah: # util target to build container images using buildah. do --platform $(PLATFORM) \ -f $(DOCKERFILE) \ --build-arg VERSION=$(VERSION) $(EXTRA_BUILD_ARGS) \ - -t $(REGISTRY)/$(IMAGE):$(TAG) \ + -t $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) \ . containerize-docker: # util target to build container images using docker buildx. do not invoke directly. @@ -188,21 +189,21 @@ containerize-docker: # util target to build container images using docker buildx --platform $(PLATFORM) \ -f $(DOCKERFILE) \ --build-arg VERSION=$(VERSION) $(EXTRA_BUILD_ARGS) \ - -t $(REGISTRY)/$(IMAGE):$(TAG) \ + -t $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) \ . container-tag-test: # util target to retag an image with -test suffix. do not invoke directly. $(CONTAINER_BUILDER) tag \ - $(REGISTRY)/$(IMAGE):$(TAG) \ - $(REGISTRY)/$(IMAGE):$(TAG)-test + $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) \ + $(IMAGE_REGISTRY)/$(IMAGE):$(TAG)-test container-push: # util target to publish container image. do not invoke directly. $(CONTAINER_BUILDER) push \ - $(REGISTRY)/$(IMAGE):$(TAG) + $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) container-pull: # util target to pull container image. do not invoke directly. $(CONTAINER_BUILDER) pull \ - $(REGISTRY)/$(IMAGE):$(TAG) + $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) container-info: # util target to write container info file. do not invoke directly. # these commands need to be root due to some ongoing perms issues in the pipeline. @@ -350,34 +351,31 @@ azure-cnm-plugin-image: azure-cnm-plugin ## build the azure-cnm plugin container ## This section is for building multi-arch/os container image manifests. multiarch-manifest-create: # util target to compose multiarch container manifests from os/arch images. - $(CONTAINER_BUILDER) manifest create \ - $(REGISTRY)/$(IMAGE):$(TAG) \ - $(foreach OS,$(OSES),$(foreach ARCH,$(ARCHES),$(REGISTRY)/$(IMAGE):$(OS)-$(ARCH)-$(TAG))) + $(CONTAINER_BUILDER) manifest create $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) + $(foreach PLATFORM,$(PLATFORMS), \ + $(if $(filter $(PLATFORM),windows/amd64), \ + $(CONTAINER_BUILDER) manifest add --os-version=$(WINVER) $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) docker://$(IMAGE_REGISTRY)/$(IMAGE):$(subst /,-,$(PLATFORM))-$(TAG); \ + , \ + $(CONTAINER_BUILDER) manifest add $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) docker://$(IMAGE_REGISTRY)/$(IMAGE):$(subst /,-,$(PLATFORM))-$(TAG);)) multiarch-manifest-push: # util target to push multiarch container manifest. - $(CONTAINER_BUILDER) manifest push $(REGISTRY)/$(IMAGE):$(TAG) docker://$(REGISTRY)/$(IMAGE):$(TAG) + $(CONTAINER_BUILDER) manifest push --all $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) docker://$(IMAGE_REGISTRY)/$(IMAGE):$(TAG) cni-manager-multiarch-manifest-create: ## build cni-manager multi-arch container manifest. $(MAKE) multiarch-manifest-create \ - OSES="$(OSES)" \ - ARCHES="$(ARCHES)" \ - REGISTRY=$(IMAGE_REGISTRY) \ + PLATFORMS="$(PLATFORMS)" \ IMAGE=$(CNI_IMAGE) \ TAG=$(TAG) cns-multiarch-manifest-create: ## build azure-cns multi-arch container manifest. $(MAKE) multiarch-manifest-create \ - OSES="$(OSES)" \ - ARCHES="$(ARCHES)" \ - REGISTRY=$(IMAGE_REGISTRY) \ + PLATFORMS="$(PLATFORMS)" \ IMAGE=$(CNS_IMAGE) \ TAG=$(TAG) npm-multiarch-manifest-create: ## build azure-npm multi-arch container manifest. $(MAKE) multiarch-manifest-create \ - OSES="$(OSES)" \ - ARCHES="$(ARCHES)" \ - REGISTRY=$(IMAGE_REGISTRY) \ + PLATFORMS="$(PLATFORMS)" \ IMAGE=$(NPM_IMAGE) \ TAG=$(TAG) diff --git a/cns/windows.Dockerfile b/cns/windows.Dockerfile index 47ae1c7ad9..e65f20cf4e 100644 --- a/cns/windows.Dockerfile +++ b/cns/windows.Dockerfile @@ -1,5 +1,5 @@ # Build cns -FROM mcr.microsoft.com/oss/go/microsoft/golang:1.18 AS builder +FROM mcr.microsoft.com/oss/go/microsoft/golang:1.18-windowsservercore-ltsc2022 AS builder # Build args ARG VERSION ARG CNS_AI_PATH @@ -14,7 +14,7 @@ COPY . . RUN $Env:CGO_ENABLED=0; go build -v -o /usr/local/bin/azure-cns.exe -ldflags """-X main.version=${env:VERSION} -X ${env:CNS_AI_PATH}=${env:CNS_AI_ID}""" -gcflags="-dwarflocationlists=true" ./cns/service # Copy into final image -FROM mcr.microsoft.com/windows/nanoserver:1809 +FROM mcr.microsoft.com/windows/servercore:ltsc2022 COPY --from=builder /usr/local/bin/azure-cns.exe \ /usr/local/bin/azure-cns.exe diff --git a/npm/Dockerfile.windows b/npm/windows.Dockerfile similarity index 100% rename from npm/Dockerfile.windows rename to npm/windows.Dockerfile diff --git a/windows.ps1 b/windows.ps1 index 54e242187f..af7f1b139d 100644 --- a/windows.ps1 +++ b/windows.ps1 @@ -27,10 +27,25 @@ function npm-image { if ($null -eq $env:VERSION) { $env:VERSION = $args[0] } docker build ` - -f npm/Dockerfile.windows ` + -f npm/windows.Dockerfile ` -t acnpublic.azurecr.io/azure-npm:$env:VERSION ` --build-arg VERSION=$env:VERSION ` --build-arg NPM_AI_PATH=$env:NPM_AI_PATH ` --build-arg NPM_AI_ID=$env:NPM_AI_ID ` . } + +function cns-image { + $env:ACN_PACKAGE_PATH = "github.com/Azure/azure-container-networking" + $env:CNS_AI_ID = "ce672799-8f08-4235-8c12-08563dc2acef" + $env:CNS_AI_PATH = "$env:ACN_PACKAGE_PATH/cns/logger.aiMetadata" + + if ($null -eq $env:VERSION) { $env:VERSION = $args[0] } + docker build ` + -f cns/windows.Dockerfile ` + -t acnpublic.azurecr.io/azure-cns:$env:VERSION ` + --build-arg VERSION=$env:VERSION ` + --build-arg CNS_AI_PATH=$env:CNS_AI_PATH ` + --build-arg CNS_AI_ID=$env:CNS_AI_ID ` + . +}