diff --git a/.pipelines/pipeline.yaml b/.pipelines/pipeline.yaml index 42a5868f08..ad924decdf 100644 --- a/.pipelines/pipeline.yaml +++ b/.pipelines/pipeline.yaml @@ -151,10 +151,16 @@ stages: displayName: "Push NPM Image and Wait for Repository" - script: | - cd ./output + mkdir -p ./output/bins + cd ./output/linux_amd64 sudo find . -mindepth 2 -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete - sudo find . -mindepth 2 -type f -print -exec mv {} . \; + sudo find . -mindepth 2 -type f -print -exec mv {} ../bins \; sudo rm -R -- */ && cd .. + cd ./windows_amd64 + sudo find . -mindepth 2 -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete + sudo find . -mindepth 2 -type f -print -exec mv {} ../bins \; + sudo rm -R -- */ && cd .. + rmdir ./linux_amd64 && rmdir ./windows_amd64 workingDirectory: "$(modulePath)" name: "PrepareArtifacts" displayName: "Prepare Artifacts" @@ -195,7 +201,7 @@ stages: inlineScript: | echo Creating storage container with name acn-$(EnvironmentalVariables.StorageID) and account name $(STORAGE_ACCOUNT_NAME) az storage container create -n acn-$(EnvironmentalVariables.StorageID) --account-name $(STORAGE_ACCOUNT_NAME) --public-access container - az storage blob upload-batch -d acn-$(EnvironmentalVariables.StorageID) -s ./output/ --account-name $(STORAGE_ACCOUNT_NAME) + az storage blob upload-batch -d acn-$(EnvironmentalVariables.StorageID) -s ./output/bins/ --account-name $(STORAGE_ACCOUNT_NAME) workingDirectory: "$(modulePath)" displayName: Create artifact storage container condition: succeeded() diff --git a/Makefile b/Makefile index 5842854659..46e581cbae 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,7 @@ CNMS_DIR = cnms/service NPM_DIR = npm/plugin OUTPUT_DIR = output BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH) +IMAGE_DIR = $(OUTPUT_DIR)/images CNM_BUILD_DIR = $(BUILD_DIR)/cnm CNI_BUILD_DIR = $(BUILD_DIR)/cni ACNCLI_BUILD_DIR = $(BUILD_DIR)/acncli @@ -181,7 +182,7 @@ all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns endif ifeq ($(GOOS),linux) -all-images: azure-npm-image azure-cns-aks-swift-image +all-images: azure-npm-image azure-cns-image else all-images: @echo "Nothing to build. Skip." @@ -306,13 +307,14 @@ publish-azure-vnet-plugin-image: .PHONY: azure-npm-image azure-npm-image: azure-npm ifeq ($(GOOS),linux) + mkdir -p $(IMAGE_DIR) docker build \ --no-cache \ -f npm/Dockerfile \ -t $(AZURE_NPM_IMAGE):$(VERSION) \ --build-arg NPM_BUILD_DIR=$(NPM_BUILD_DIR) \ . - docker save $(AZURE_NPM_IMAGE):$(VERSION) | gzip -c > $(NPM_BUILD_DIR)/$(NPM_IMAGE_ARCHIVE_NAME) + docker save $(AZURE_NPM_IMAGE):$(VERSION) | gzip -c > $(IMAGE_DIR)/$(NPM_IMAGE_ARCHIVE_NAME) endif # Publish the Azure NPM image to a Docker registry @@ -330,7 +332,7 @@ ifeq ($(GOOS),linux) -t $(AZURE_CNMS_IMAGE):$(VERSION) \ --build-arg CNMS_BUILD_DIR=$(CNMS_BUILD_DIR) \ . - docker save $(AZURE_CNMS_IMAGE):$(VERSION) | gzip -c > $(CNMS_BUILD_DIR)/$(CNMS_IMAGE_ARCHIVE_NAME) + docker save $(AZURE_CNMS_IMAGE):$(VERSION) | gzip -c > $(IMAGE_DIR)/$(CNMS_IMAGE_ARCHIVE_NAME) endif # Build the Azure vnet telemetry image @@ -349,29 +351,20 @@ azure-vnet-telemetry-image: azure-vnet-telemetry publish-azure-vnet-telemetry-image: docker push $(AZURE_VNET_TELEMETRY_IMAGE):$(VERSION) -# Build the Azure CNS image. +# Build the Azure CNS image .PHONY: azure-cns-image -azure-cns-image: azure-cns +azure-cns-image: ifeq ($(GOOS),linux) + mkdir -p $(IMAGE_DIR) docker build \ + --no-cache \ -f cns/Dockerfile \ -t $(AZURE_CNS_IMAGE):$(VERSION) \ - --build-arg CNS_BUILD_ARCHIVE=$(CNS_BUILD_DIR)/$(CNS_IMAGE_ARCHIVE_NAME) \ - . - docker save $(AZURE_CNS_IMAGE):$(VERSION) | gzip -c > $(CNS_BUILD_DIR)/$(CNS_IMAGE_ARCHIVE_NAME) -endif - -# Build the Azure CNS image for AKS Swift. -.PHONY: azure-cns-aks-swift-image -azure-cns-aks-swift-image: -ifeq ($(GOOS),linux) - docker build \ - -f cns/aks.Dockerfile \ - -t $(AZURE_CNS_IMAGE):$(VERSION) \ --build-arg VERSION=$(VERSION) \ --build-arg CNS_AI_PATH=$(cnsaipath) \ --build-arg CNS_AI_ID=$(CNS_AI_ID) \ . + docker save $(AZURE_CNS_IMAGE):$(VERSION) | gzip -c > $(IMAGE_DIR)/$(CNS_IMAGE_ARCHIVE_NAME) endif # Publish the Azure NPM image to a Docker registry @@ -451,6 +444,10 @@ ifeq ($(GOOS),linux) chown $(BUILD_USER):$(BUILD_USER) $(NPM_BUILD_DIR)/$(NPM_ARCHIVE_NAME) endif +.PHONY: release +release: + ./scripts/semver-release.sh + PRETTYGOTEST := $(shell command -v gotest 2> /dev/null) diff --git a/cns/Dockerfile b/cns/Dockerfile index 1acc3fe300..5810079b7a 100644 --- a/cns/Dockerfile +++ b/cns/Dockerfile @@ -1,18 +1,34 @@ -# Use a minimal image as a parent image -FROM ubuntu:20.04 -ARG CNS_BUILD_ARCHIVE +# Get a trusted CA cert bundle +FROM alpine:latest as certs +RUN apk --update add ca-certificates -# Install plugin -COPY $CNS_BUILD_ARCHIVE azure-cns.tgz +# Build cns +FROM golang:1.16-alpine AS builder +# Build ars +ARG VERSION +ARG CNS_AI_PATH +ARG CNS_AI_ID -# Update and unzip cns archive -RUN apt-get update && \ - apt-get install -y ca-certificates && \ - tar -xvzf azure-cns.tgz && \ - rm azure-cns.tgz -RUN apt-get upgrade -y +WORKDIR /usr/local/src/cns -EXPOSE 10090 +# Copy the source +COPY . . -# Run the cns command by default when the container starts. -ENTRYPOINT ["sh", "-c", "/azure-cns -c tcp://$CNSIpAddress:10090"] \ No newline at end of file +# Build cns +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /usr/local/bin/azure-cns -ldflags "-X main.version="$VERSION" -X "$CNS_AI_PATH"="$CNS_AI_ID" -s -w " cns/service/*.go + +# Build aitelemetry +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /usr/local/bin/azure-vnet-telemetry -ldflags "-X main.version="$VERSION" -s -w" cni/telemetry/service/*.go + +# Copy into final image +FROM scratch +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group +COPY --from=builder /usr/local/bin/azure-cns \ + /usr/local/bin/azure-cns +COPY --from=builder /usr/local/bin/azure-vnet-telemetry \ + /usr/local/bin/azure-vnet-telemetry +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +ENTRYPOINT [ "/usr/local/bin/azure-cns" ] +EXPOSE 10090 \ No newline at end of file diff --git a/cns/aks.Dockerfile b/cns/aks.Dockerfile deleted file mode 100644 index f064a2cea4..0000000000 --- a/cns/aks.Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -# Get a trusted CA cert bundle -FROM alpine:latest as certs -RUN apk --update add ca-certificates - -# Build cns -FROM golang:1.14-alpine AS builder -# Build ars -ARG VERSION -ARG CNS_AI_PATH -ARG CNS_AI_ID - -WORKDIR /usr/local/src/cns - -# Copy the source -COPY . . - -# Build cns -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /usr/local/bin/azure-cns -ldflags "-X main.version="$VERSION" -X "$CNS_AI_PATH"="$CNS_AI_ID" -s -w " cns/service/*.go - -# Build aitelemetry -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /usr/local/bin/azure-vnet-telemetry -ldflags "-X main.version="$VERSION" -s -w" cni/telemetry/service/*.go - -# Copy into final image -FROM scratch -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/group /etc/group -COPY --from=builder /usr/local/bin/azure-cns \ - /usr/local/bin/azure-cns -COPY --from=builder /usr/local/bin/azure-vnet-telemetry \ - /usr/local/bin/azure-vnet-telemetry -COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt - -ENTRYPOINT [ "/usr/local/bin/azure-cns" ] -EXPOSE 10090 \ No newline at end of file diff --git a/scripts/semver-release.sh b/scripts/semver-release.sh new file mode 100755 index 0000000000..bba5163a56 --- /dev/null +++ b/scripts/semver-release.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +export MAJOR=0 +export MINOR=0 +export PATCH=0 +export FULL_TAG="v0.0.0" + +function create_release () { + parse_git_tag + + if increment_git_tag + then + FULL_TAG="v${MAJOR}.${MINOR}.${PATCH}" + set_git_tag + else + echo "local git tag unchanged" + fi +} + +function get_git_tag () { + + return echo "v${MAJOR}${MINOR}${PATCH}" +} + +function set_git_tag () { + read -p "Set git tag to $FULL_TAG? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + git tag $FULL_TAG + echo "git tag set to $FULL_TAG" + + push_git_tag + fi + + return +} + +function push_git_tag { + remote=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} | cut -f1 -d"/") + + read -p "Push git tag to remote $remote? [y/N] " -n 1 + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + git push $remote $FULL_TAG + fi +} + +function increment_git_tag () { + read -p "Does this release contain incompatible API changes? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + MAJOR=$((MAJOR+1)) + MINOR=0 + PATCH=0 + return + fi + + read -p "Does this release contain added functionality that's backwards compatible? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + MINOR=$((MINOR+1)) + PATCH=0 + return + fi + + read -p "Does this release only contain backwards compatible bug fixes [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]] + then + PATCH=$((PATCH+1)) + return + fi + + false +} + +function parse_git_tag () { + FULL_TAG=$(git describe --tags --abbrev=0) + echo Current git tag: $FULL_TAG + echo "--------" + tagArr=(${FULL_TAG//./ }) + MAJOR=${tagArr[0]:1} + MINOR=${tagArr[1]} + PATCH=${tagArr[2]} +} + +create_release \ No newline at end of file