diff --git a/.pipelines/pipeline.yaml b/.pipelines/pipeline.yaml index 8d62048627..c541b568fa 100644 --- a/.pipelines/pipeline.yaml +++ b/.pipelines/pipeline.yaml @@ -11,10 +11,10 @@ trigger: - honeycomb-dev stages: - - stage: build_and_test + - stage: setup displayName: ACN jobs: - - job: setup + - job: env displayName: Setup pool: name: "$(BUILD_POOL_NAME_DEFAULT)" @@ -32,13 +32,19 @@ stages: displayName: "Set environmental variables" condition: always() + + - template: windows-image.yaml + + - stage: build_and_test + displayName: ACN + dependsOn: + - "setup" + jobs: - job: build displayName: Build Binaries - dependsOn: - - "setup" variables: - TAG: $[ dependencies.setup.outputs['EnvironmentalVariables.Tag'] ] - STORAGE_ID: $[ dependencies.setup.outputs['EnvironmentalVariables.StorageID'] ] + TAG: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] + STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ] pool: name: "$(BUILD_POOL_NAME_DEFAULT)" steps: @@ -85,10 +91,8 @@ stages: - job: build_images displayName: Build Images - dependsOn: - - "setup" variables: - TAG: $[ dependencies.setup.outputs['EnvironmentalVariables.Tag'] ] + TAG: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] pool: name: "$(BUILD_POOL_NAME_DEFAULT)" steps: @@ -158,10 +162,8 @@ stages: - job: test displayName: Run Tests - dependsOn: - - "setup" variables: - STORAGE_ID: $[ dependencies.setup.outputs['EnvironmentalVariables.StorageID'] ] + STORAGE_ID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ] pool: name: "$(BUILD_POOL_NAME_DEFAULT)" steps: diff --git a/.pipelines/singletenancy/aks-engine/e2e-job-template.yaml b/.pipelines/singletenancy/aks-engine/e2e-job-template.yaml index ab0c62dbf7..f12e743e47 100644 --- a/.pipelines/singletenancy/aks-engine/e2e-job-template.yaml +++ b/.pipelines/singletenancy/aks-engine/e2e-job-template.yaml @@ -10,7 +10,9 @@ parameters: stages: - stage: ${{ parameters.name }} displayName: E2E - ${{ parameters.displayName }} - dependsOn: build_and_test + dependsOn: + - setup + - build_and_test jobs: - job: ${{ parameters.name }} displayName: Singletenancy AKS Engine Suite - (${{ parameters.name }}) @@ -27,9 +29,9 @@ stages: GOBIN: "$(GOPATH)/bin" # Go binaries path modulePath: "$(GOPATH)/src/github.com/Azure/aks-engine" acnPath: "$(GOPATH)/src/github.com/Azure/azure-container-networking" - Tag: $[ stagedependencies.build_and_test.setup.outputs['EnvironmentalVariables.Tag'] ] - CommitHash: $[ stagedependencies.build_and_test.setup.outputs['EnvironmentalVariables.CommitHash'] ] - StorageID: $[ stagedependencies.build_and_test.setup.outputs['EnvironmentalVariables.StorageID'] ] + Tag: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] + CommitHash: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.CommitHash'] ] + StorageID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.StorageID'] ] steps: - template: e2e-step-template.yaml parameters: diff --git a/.pipelines/singletenancy/aks-swift/e2e-job-template.yaml b/.pipelines/singletenancy/aks-swift/e2e-job-template.yaml index 3332471b1c..83319e10ae 100644 --- a/.pipelines/singletenancy/aks-swift/e2e-job-template.yaml +++ b/.pipelines/singletenancy/aks-swift/e2e-job-template.yaml @@ -6,7 +6,9 @@ parameters: stages: - stage: ${{ parameters.name }} displayName: E2E - ${{ parameters.displayName }} - dependsOn: build_and_test + dependsOn: + - setup + - build_and_test jobs: - job: ${{ parameters.name }} displayName: Singletenancy AKS Swift Suite - (${{ parameters.name }}) @@ -19,7 +21,7 @@ stages: variables: GOPATH: "$(Agent.TempDirectory)/go" # Go workspace path GOBIN: "$(GOPATH)/bin" # Go binaries path - Tag: $[ stagedependencies.build_and_test.setup.outputs['EnvironmentalVariables.Tag'] ] + Tag: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.Tag'] ] modulePath: "$(GOPATH)/src/github.com/Azure/azure-container-networking" steps: - template: e2e-step-template.yaml diff --git a/.pipelines/windows-image.yaml b/.pipelines/windows-image.yaml new file mode 100644 index 0000000000..6bf293dcf3 --- /dev/null +++ b/.pipelines/windows-image.yaml @@ -0,0 +1,55 @@ +stages: +- stage: build_windows_images + displayName: Build Windows Images + dependsOn: + - "setup" + 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; azure-npm-image $(tag)-windows-amd64 }" + 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:$(tag)-windows-amd64 acnpublic.azurecr.io/azure-npm:$(tag)-windows-amd64-test + docker push acnpublic.azurecr.io/azure-npm:$(tag)-windows-amd64-test + name: "push_npm" + displayName: "Push" + + - powershell: | + mkdir .\output\images\windows\ + docker save acnpublic.azurecr.io/azure-npm:$(tag)-windows-amd64-test -o .\output\images\windows\azure-npm-$(tag)-windows-amd64.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 6dffae9929..a55619e40b 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ ifeq ($(GOOS),linux) all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-npm all-images: azure-npm-image azure-cns-image else -all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns +all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-npm all-images: @echo "Nothing to build. Skip." endif diff --git a/log/logger_windows.go b/log/logger_windows.go index 85a48b318b..352f801d79 100644 --- a/log/logger_windows.go +++ b/log/logger_windows.go @@ -19,6 +19,9 @@ func (logger *Logger) SetTarget(target int) error { var err error switch target { + case TargetStdout: + logger.out = os.Stdout + case TargetStderr: logger.out = os.Stderr diff --git a/npm/Dockerfile.windows b/npm/Dockerfile.windows new file mode 100644 index 0000000000..910954d2c0 --- /dev/null +++ b/npm/Dockerfile.windows @@ -0,0 +1,20 @@ +FROM golang:windowsservercore-ltsc2022 AS builder +# Build args +ARG VERSION +ARG NPM_AI_PATH +ARG NPM_AI_ID + +WORKDIR /usr/src/npm +RUN mkdir /usr/bin/ +# Copy the source +COPY . . + +RUN $Env:CGO_ENABLED=0; go build -v -o /usr/bin/npm.exe -ldflags """-X main.version=${env:VERSION} -X ${env:NPM_AI_PATH}=${env:NPM_AI_ID}""" -gcflags="-dwarflocationlists=true" ./npm/cmd/ + +# Copy into final image +FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 +COPY --from=builder /Windows/System32/netapi32.dll /Windows/System32/netapi32.dll +COPY --from=builder /usr/bin/npm.exe \ + /usr/bin/npm.exe + +ENTRYPOINT ["/usr/bin/npm.exe", "start"] diff --git a/windows.ps1 b/windows.ps1 new file mode 100644 index 0000000000..32cd475d65 --- /dev/null +++ b/windows.ps1 @@ -0,0 +1,15 @@ + +function azure-npm-image { + $env:ACN_PACKAGE_PATH = "github.com/Azure/azure-container-networking" + $env:NPM_AI_ID = "014c22bd-4107-459e-8475-67909e96edcb" + $env:NPM_AI_PATH="$env:ACN_PACKAGE_PATH/npm.aiMetadata" + + if ($null -eq $env:VERSION) { $env:VERSION = $args[0] } + docker build ` + -f npm/Dockerfile.windows ` + -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 ` + . +}