Skip to content

Commit

Permalink
add makefile; multi-arch images (#1307) (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysngupta authored Jan 13, 2022
1 parent 5326bec commit 24b21dc
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 180 deletions.
180 changes: 54 additions & 126 deletions .pipelines/build.yml
Original file line number Diff line number Diff line change
@@ -1,129 +1,57 @@
# This contains common build steps

steps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'

- script: |
go get -u golang.org/x/lint/golint
golint $(go list ./... | grep -v /vendor/) | tee /tmp/lint.out
if [ -s /tmp/lint.out ]; then
echo -e "\e[101;97m golint FAILED \e[0m"``
exit 1
else
echo -e "\e[42;97m golint SUCCEEDED \e[0m"
fi
workingDirectory: '$(modulePath)'
displayName: 'Go lint'

- script: |
if go vet ./...; then
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
else
echo -e "\e[101;97m govet FAILED \e[0m"``
exit 1
fi
if go vet -tags=unittest ./...; then
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
else
echo -e "\e[101;97m govet FAILED \e[0m"``
exit 1
fi
cd ./scripts/e2e
if go vet -tags=e2e ./...; then
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
else
echo -e "\e[101;97m govet FAILED \e[0m"``
exit 1
fi
cd ../..
workingDirectory: '$(modulePath)'
displayName: 'Go vet'

- script: |
set -u
go version
echo -e "\e[44;97m Compiling ... \e[0m"
# set version
ORG_PATH="github.com/Azure"
PROJECT_NAME="application-gateway-kubernetes-ingress"
REPO_PATH="${ORG_PATH}/${PROJECT_NAME}"
VERSION_VAR="${REPO_PATH}/pkg/version.Version"
VERSION=$(git describe --abbrev=0 --tags)
DATE_VAR="${REPO_PATH}/pkg/version.BuildDate"
BUILD_DATE=$(date +%Y-%m-%d-%H:%MT%z)
COMMIT_VAR="${REPO_PATH}/pkg/version.GitCommit"
GIT_HASH=$(git rev-parse --short HEAD)
echo "VERSION $VERSION_VAR:$VERSION, BUILD_DATE $DATE_VAR:$BUILD_DATE, GIT_HASH $COMMIT_VAR:$GIT_HASH"
if go install -ldflags "-s -X ${VERSION_VAR}=${VERSION} -X ${DATE_VAR}=${BUILD_DATE} -X ${COMMIT_VAR}=${GIT_HASH}" -v ./cmd/appgw-ingress; then
chmod -R 777 $(GOBIN)
$(GOBIN)/appgw-ingress --version
echo -e "\e[42;97m Build SUCCEEDED \e[0m"
else
echo -e "\e[101;97m Build FAILED \e[0m"
exit 1
fi
workingDirectory: '$(modulePath)'
displayName: 'Get dependencies and build'

- script: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get github.com/matm/gocov-html
go test -timeout 80s -v -coverprofile=coverage.txt -covermode count -tags unittest ./... > testoutput.txt || { echo "go test returned non-zero"; cat testoutput.txt; exit 1; }
cat testoutput.txt | go-junit-report > report.xml
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
mkdir coverage
gocov-html < coverage.json > coverage/index.html
workingDirectory: '$(modulePath)'
displayName: 'Run unit tests with code coverage'

- script: |
helm lint ./helm/ingress-azure
workingDirectory: '$(modulePath)'
displayName: 'Helm lint'

- task: PublishTestResults@2
continueOnError: true
condition: succeededOrFailed()
inputs:
failTaskOnFailedTests: true
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml


- task: PublishCodeCoverageResults@1
continueOnError: true
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(modulePath)/coverage.xml
reportDirectory: $(modulePath)/coverage

- task: CopyFiles@2
inputs:
contents: |
$(GOBIN)/appgw-ingress
$(modulePath)/dockerfiles/deploy.Dockerfile
$(modulePath)/scripts/**
$(modulePath)/helm/**
targetFolder: $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: "Set up the Go workspace"
- script: make lint-all
workingDirectory: "$(modulePath)"
displayName: "Go and Helm lint check"

- script: make vet-all
workingDirectory: "$(modulePath)"
displayName: "Go vet"

- script: make build
workingDirectory: "$(modulePath)"
displayName: "Get dependencies and build"

- script: make unittest
workingDirectory: "$(modulePath)"
displayName: "Run unit tests with code coverage"

- task: PublishTestResults@2
continueOnError: true
condition: succeededOrFailed()
inputs:
failTaskOnFailedTests: true
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml

- task: PublishCodeCoverageResults@1
continueOnError: true
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(modulePath)/coverage.xml
reportDirectory: $(modulePath)/coverage

- task: CopyFiles@2
inputs:
contents: |
$(modulePath)/scripts/**
$(modulePath)/helm/**
targetFolder: $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop
35 changes: 34 additions & 1 deletion .pipelines/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,37 @@ variables:
GO_PROJ: 'github.com/Azure/$(build.repository.name)'

steps:
- template: build.yml
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: "Set up the Go workspace"
- task: Docker@2
displayName: Login to ACR
inputs:
command: login
containerRegistry: "AGIC Registry"

- script: |
docker buildx create --use
make build-image-multi-arch BUILD_TAG=$(build.buildid) PUSH_IMAGE=true
workingDirectory: "$(modulePath)"
displayName: "Build nightly image"
- task: CopyFiles@2
inputs:
contents: |
$(modulePath)/scripts/**
$(modulePath)/helm/**
targetFolder: $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop
49 changes: 41 additions & 8 deletions .pipelines/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,48 @@ trigger:
pr: none

pool:
vmImage: 'ubuntu-latest'
vmImage: "ubuntu-latest"

variables:
GOPATH: '$(system.defaultWorkingDirectory)/gopath'
GOBIN: '$(GOPATH)/bin'
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)'
GOOS: 'linux'
GO111MODULE: 'on'
GO_PROJ: 'github.com/Azure/$(build.repository.name)'
GOPATH: "$(system.defaultWorkingDirectory)/gopath"
GOBIN: "$(GOPATH)/bin"
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)"
GOOS: "linux"
GO111MODULE: "on"
GO_PROJ: "github.com/Azure/$(build.repository.name)"

steps:
- template: build.yml
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: "Set up the Go workspace"
- task: Docker@2
displayName: Login to ACR
inputs:
command: login
containerRegistry: "AGIC Registry"

- script: |
docker buildx create --use
make build-image-multi-arch RELEASE_IMAGE=true PUSH_IMAGE=true
workingDirectory: "$(modulePath)"
displayName: "Build release image"
- task: CopyFiles@2
inputs:
contents: |
$(modulePath)/scripts/**
$(modulePath)/helm/**
targetFolder: $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG BUILDPLATFORM=linux/amd64
ARG BUILD_BASE_IMAGE

FROM --platform=$BUILDPLATFORM $BUILD_BASE_IMAGE AS build
WORKDIR /azure

COPY go.mod go.sum /azure/
RUN go mod download

RUN apt-get update
RUN apt-get install -y ca-certificates openssl

ARG TARGETOS
ARG TARGETARCH
ARG BUILD_TAG
ARG BUILD_DATE
ARG GIT_HASH

COPY cmd cmd
COPY pkg pkg
COPY Makefile Makefile

RUN make build \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
BUILD_TAG=${BUILD_TAG} \
BUILD_DATE=${BUILD_DATE} \
GIT_HASH=${GIT_HASH}

#RUN ldd ./bin/appgw-ingress 2>&1 | grep 'not a dynamic executable'

FROM ubuntu:20.04 AS final
COPY --from=build /azure/bin/appgw-ingress /appgw-ingress
RUN apt-get update
RUN apt-get install -y ca-certificates openssl
RUN useradd appgw-ingress-user
RUN chown appgw-ingress-user /appgw-ingress
USER appgw-ingress-user
RUN chmod +x /appgw-ingress
CMD ["/appgw-ingress"]
Loading

0 comments on commit 24b21dc

Please sign in to comment.