Skip to content

Commit 24b21dc

Browse files
add makefile; multi-arch images (#1307) (#1324)
1 parent 5326bec commit 24b21dc

File tree

8 files changed

+296
-180
lines changed

8 files changed

+296
-180
lines changed

.pipelines/build.yml

Lines changed: 54 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,57 @@
11
# This contains common build steps
22

33
steps:
4-
- script: |
5-
mkdir -p '$(GOBIN)'
6-
mkdir -p '$(GOPATH)/pkg'
7-
mkdir -p '$(modulePath)'
8-
shopt -s extglob
9-
shopt -s dotglob
10-
mv !(gopath) '$(modulePath)'
11-
echo '##vso[task.prependpath]$(GOBIN)'
12-
echo '##vso[task.prependpath]$(GOROOT)/bin'
13-
displayName: 'Set up the Go workspace'
14-
15-
- script: |
16-
go get -u golang.org/x/lint/golint
17-
golint $(go list ./... | grep -v /vendor/) | tee /tmp/lint.out
18-
if [ -s /tmp/lint.out ]; then
19-
echo -e "\e[101;97m golint FAILED \e[0m"``
20-
exit 1
21-
else
22-
echo -e "\e[42;97m golint SUCCEEDED \e[0m"
23-
fi
24-
workingDirectory: '$(modulePath)'
25-
displayName: 'Go lint'
26-
27-
- script: |
28-
if go vet ./...; then
29-
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
30-
else
31-
echo -e "\e[101;97m govet FAILED \e[0m"``
32-
exit 1
33-
fi
34-
35-
if go vet -tags=unittest ./...; then
36-
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
37-
else
38-
echo -e "\e[101;97m govet FAILED \e[0m"``
39-
exit 1
40-
fi
41-
42-
cd ./scripts/e2e
43-
if go vet -tags=e2e ./...; then
44-
echo -e "\e[42;97m govet SUCCEEDED \e[0m"
45-
else
46-
echo -e "\e[101;97m govet FAILED \e[0m"``
47-
exit 1
48-
fi
49-
cd ../..
50-
workingDirectory: '$(modulePath)'
51-
displayName: 'Go vet'
52-
53-
- script: |
54-
set -u
55-
go version
56-
echo -e "\e[44;97m Compiling ... \e[0m"
57-
58-
# set version
59-
ORG_PATH="github.com/Azure"
60-
PROJECT_NAME="application-gateway-kubernetes-ingress"
61-
REPO_PATH="${ORG_PATH}/${PROJECT_NAME}"
62-
VERSION_VAR="${REPO_PATH}/pkg/version.Version"
63-
VERSION=$(git describe --abbrev=0 --tags)
64-
DATE_VAR="${REPO_PATH}/pkg/version.BuildDate"
65-
BUILD_DATE=$(date +%Y-%m-%d-%H:%MT%z)
66-
COMMIT_VAR="${REPO_PATH}/pkg/version.GitCommit"
67-
GIT_HASH=$(git rev-parse --short HEAD)
68-
69-
echo "VERSION $VERSION_VAR:$VERSION, BUILD_DATE $DATE_VAR:$BUILD_DATE, GIT_HASH $COMMIT_VAR:$GIT_HASH"
70-
if go install -ldflags "-s -X ${VERSION_VAR}=${VERSION} -X ${DATE_VAR}=${BUILD_DATE} -X ${COMMIT_VAR}=${GIT_HASH}" -v ./cmd/appgw-ingress; then
71-
chmod -R 777 $(GOBIN)
72-
$(GOBIN)/appgw-ingress --version
73-
echo -e "\e[42;97m Build SUCCEEDED \e[0m"
74-
else
75-
echo -e "\e[101;97m Build FAILED \e[0m"
76-
exit 1
77-
fi
78-
workingDirectory: '$(modulePath)'
79-
displayName: 'Get dependencies and build'
80-
81-
- script: |
82-
go get github.com/jstemmer/go-junit-report
83-
go get github.com/axw/gocov/gocov
84-
go get github.com/AlekSi/gocov-xml
85-
go get github.com/matm/gocov-html
86-
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; }
87-
cat testoutput.txt | go-junit-report > report.xml
88-
gocov convert coverage.txt > coverage.json
89-
gocov-xml < coverage.json > coverage.xml
90-
mkdir coverage
91-
gocov-html < coverage.json > coverage/index.html
92-
workingDirectory: '$(modulePath)'
93-
displayName: 'Run unit tests with code coverage'
94-
95-
- script: |
96-
helm lint ./helm/ingress-azure
97-
workingDirectory: '$(modulePath)'
98-
displayName: 'Helm lint'
99-
100-
- task: PublishTestResults@2
101-
continueOnError: true
102-
condition: succeededOrFailed()
103-
inputs:
104-
failTaskOnFailedTests: true
105-
testRunner: JUnit
106-
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
107-
108-
109-
- task: PublishCodeCoverageResults@1
110-
continueOnError: true
111-
condition: succeededOrFailed()
112-
inputs:
113-
codeCoverageTool: Cobertura
114-
summaryFileLocation: $(modulePath)/coverage.xml
115-
reportDirectory: $(modulePath)/coverage
116-
117-
- task: CopyFiles@2
118-
inputs:
119-
contents: |
120-
$(GOBIN)/appgw-ingress
121-
$(modulePath)/dockerfiles/deploy.Dockerfile
122-
$(modulePath)/scripts/**
123-
$(modulePath)/helm/**
124-
targetFolder: $(Build.ArtifactStagingDirectory)
125-
126-
- task: PublishBuildArtifacts@1
127-
inputs:
128-
pathtoPublish: $(Build.ArtifactStagingDirectory)
129-
artifactName: drop
4+
- script: |
5+
mkdir -p '$(GOBIN)'
6+
mkdir -p '$(GOPATH)/pkg'
7+
mkdir -p '$(modulePath)'
8+
shopt -s extglob
9+
shopt -s dotglob
10+
mv !(gopath) '$(modulePath)'
11+
echo '##vso[task.prependpath]$(GOBIN)'
12+
echo '##vso[task.prependpath]$(GOROOT)/bin'
13+
displayName: "Set up the Go workspace"
14+
15+
- script: make lint-all
16+
workingDirectory: "$(modulePath)"
17+
displayName: "Go and Helm lint check"
18+
19+
- script: make vet-all
20+
workingDirectory: "$(modulePath)"
21+
displayName: "Go vet"
22+
23+
- script: make build
24+
workingDirectory: "$(modulePath)"
25+
displayName: "Get dependencies and build"
26+
27+
- script: make unittest
28+
workingDirectory: "$(modulePath)"
29+
displayName: "Run unit tests with code coverage"
30+
31+
- task: PublishTestResults@2
32+
continueOnError: true
33+
condition: succeededOrFailed()
34+
inputs:
35+
failTaskOnFailedTests: true
36+
testRunner: JUnit
37+
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
38+
39+
- task: PublishCodeCoverageResults@1
40+
continueOnError: true
41+
condition: succeededOrFailed()
42+
inputs:
43+
codeCoverageTool: Cobertura
44+
summaryFileLocation: $(modulePath)/coverage.xml
45+
reportDirectory: $(modulePath)/coverage
46+
47+
- task: CopyFiles@2
48+
inputs:
49+
contents: |
50+
$(modulePath)/scripts/**
51+
$(modulePath)/helm/**
52+
targetFolder: $(Build.ArtifactStagingDirectory)
53+
54+
- task: PublishBuildArtifacts@1
55+
inputs:
56+
pathtoPublish: $(Build.ArtifactStagingDirectory)
57+
artifactName: drop

.pipelines/nightly-build.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,37 @@ variables:
2222
GO_PROJ: 'github.com/Azure/$(build.repository.name)'
2323

2424
steps:
25-
- template: build.yml
25+
- script: |
26+
mkdir -p '$(GOBIN)'
27+
mkdir -p '$(GOPATH)/pkg'
28+
mkdir -p '$(modulePath)'
29+
shopt -s extglob
30+
shopt -s dotglob
31+
mv !(gopath) '$(modulePath)'
32+
echo '##vso[task.prependpath]$(GOBIN)'
33+
echo '##vso[task.prependpath]$(GOROOT)/bin'
34+
displayName: "Set up the Go workspace"
35+
36+
- task: Docker@2
37+
displayName: Login to ACR
38+
inputs:
39+
command: login
40+
containerRegistry: "AGIC Registry"
41+
42+
- script: |
43+
docker buildx create --use
44+
make build-image-multi-arch BUILD_TAG=$(build.buildid) PUSH_IMAGE=true
45+
workingDirectory: "$(modulePath)"
46+
displayName: "Build nightly image"
47+
48+
- task: CopyFiles@2
49+
inputs:
50+
contents: |
51+
$(modulePath)/scripts/**
52+
$(modulePath)/helm/**
53+
targetFolder: $(Build.ArtifactStagingDirectory)
54+
55+
- task: PublishBuildArtifacts@1
56+
inputs:
57+
pathtoPublish: $(Build.ArtifactStagingDirectory)
58+
artifactName: drop

.pipelines/release-build.yml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,48 @@ trigger:
66
pr: none
77

88
pool:
9-
vmImage: 'ubuntu-latest'
9+
vmImage: "ubuntu-latest"
1010

1111
variables:
12-
GOPATH: '$(system.defaultWorkingDirectory)/gopath'
13-
GOBIN: '$(GOPATH)/bin'
14-
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)'
15-
GOOS: 'linux'
16-
GO111MODULE: 'on'
17-
GO_PROJ: 'github.com/Azure/$(build.repository.name)'
12+
GOPATH: "$(system.defaultWorkingDirectory)/gopath"
13+
GOBIN: "$(GOPATH)/bin"
14+
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)"
15+
GOOS: "linux"
16+
GO111MODULE: "on"
17+
GO_PROJ: "github.com/Azure/$(build.repository.name)"
1818

1919
steps:
20-
- template: build.yml
20+
- script: |
21+
mkdir -p '$(GOBIN)'
22+
mkdir -p '$(GOPATH)/pkg'
23+
mkdir -p '$(modulePath)'
24+
shopt -s extglob
25+
shopt -s dotglob
26+
mv !(gopath) '$(modulePath)'
27+
echo '##vso[task.prependpath]$(GOBIN)'
28+
echo '##vso[task.prependpath]$(GOROOT)/bin'
29+
displayName: "Set up the Go workspace"
30+
31+
- task: Docker@2
32+
displayName: Login to ACR
33+
inputs:
34+
command: login
35+
containerRegistry: "AGIC Registry"
36+
37+
- script: |
38+
docker buildx create --use
39+
make build-image-multi-arch RELEASE_IMAGE=true PUSH_IMAGE=true
40+
workingDirectory: "$(modulePath)"
41+
displayName: "Build release image"
42+
43+
- task: CopyFiles@2
44+
inputs:
45+
contents: |
46+
$(modulePath)/scripts/**
47+
$(modulePath)/helm/**
48+
targetFolder: $(Build.ArtifactStagingDirectory)
49+
50+
- task: PublishBuildArtifacts@1
51+
inputs:
52+
pathtoPublish: $(Build.ArtifactStagingDirectory)
53+
artifactName: drop

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ARG BUILDPLATFORM=linux/amd64
2+
ARG BUILD_BASE_IMAGE
3+
4+
FROM --platform=$BUILDPLATFORM $BUILD_BASE_IMAGE AS build
5+
WORKDIR /azure
6+
7+
COPY go.mod go.sum /azure/
8+
RUN go mod download
9+
10+
RUN apt-get update
11+
RUN apt-get install -y ca-certificates openssl
12+
13+
ARG TARGETOS
14+
ARG TARGETARCH
15+
ARG BUILD_TAG
16+
ARG BUILD_DATE
17+
ARG GIT_HASH
18+
19+
COPY cmd cmd
20+
COPY pkg pkg
21+
COPY Makefile Makefile
22+
23+
RUN make build \
24+
GOOS=${TARGETOS} \
25+
GOARCH=${TARGETARCH} \
26+
BUILD_TAG=${BUILD_TAG} \
27+
BUILD_DATE=${BUILD_DATE} \
28+
GIT_HASH=${GIT_HASH}
29+
30+
#RUN ldd ./bin/appgw-ingress 2>&1 | grep 'not a dynamic executable'
31+
32+
FROM ubuntu:20.04 AS final
33+
COPY --from=build /azure/bin/appgw-ingress /appgw-ingress
34+
RUN apt-get update
35+
RUN apt-get install -y ca-certificates openssl
36+
RUN useradd appgw-ingress-user
37+
RUN chown appgw-ingress-user /appgw-ingress
38+
USER appgw-ingress-user
39+
RUN chmod +x /appgw-ingress
40+
CMD ["/appgw-ingress"]

0 commit comments

Comments
 (0)