File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed
Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change 1- FROM golang:1.17-alpine as build
1+ # ############################################
2+ # Build
3+ # ############################################
4+ FROM --platform=$BUILDPLATFORM golang:1.18-alpine as build
25
36RUN apk upgrade --no-cache --force
47RUN apk add --update build-base make git
58
69WORKDIR /go/src/github.com/webdevops/azure-devops-exporter
710
11+ # Dependencies
12+ COPY go.mod go.sum .
13+ RUN go mod download
14+
815# Compile
9- COPY ./ /go/src/github.com/webdevops/azure-devops-exporter
10- RUN make dependencies
16+ COPY . .
1117RUN make test
12- RUN make build
13- RUN ./azure-devops-exporter --help
18+ ARG TARGETOS TARGETARCH
19+ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
20+
21+ # ############################################
22+ # Test
23+ # ############################################
24+ FROM gcr.io/distroless/static as test
25+ USER 0:0
26+ WORKDIR /app
27+ COPY --from=build /go/src/github.com/webdevops/azure-devops-exporter/azure-devops-exporter .
28+ RUN ["./azure-devops-exporter" , "--help" ]
1429
1530# ############################################
16- # FINAL IMAGE
31+ # Final
1732# ############################################
1833FROM gcr.io/distroless/static
1934ENV LOG_JSON=1
20- COPY --from=build /go/src/github.com/webdevops/azure-devops-exporter/azure-devops-exporter /
35+ WORKDIR /
36+ COPY --from=test /app .
2137USER 1000:1000
2238ENTRYPOINT ["/azure-devops-exporter" ]
Original file line number Diff line number Diff line change 11PROJECT_NAME := $(shell basename $(CURDIR ) )
22GIT_TAG := $(shell git describe --dirty --tags --always)
33GIT_COMMIT := $(shell git rev-parse --short HEAD)
4- LDFLAGS := -X "main.gitTag=$(GIT_TAG ) " -X "main.gitCommit=$(GIT_COMMIT ) " -linkmode external - extldflags "-static" -s -w
4+ LDFLAGS := -X "main.gitTag=$(GIT_TAG ) " -X "main.gitCommit=$(GIT_COMMIT ) " -extldflags "-static" -s -w
55
66FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH) ) )
77GOLANGCI_LINT_BIN := $(FIRST_GOPATH ) /bin/golangci-lint
1616
1717.PHONY : build
1818build :
19- CGO_ENABLED=0 go build -a -ldflags ' $(LDFLAGS)' -o $(PROJECT_NAME ) .
19+ GOOS= ${GOOS} GOARCH= ${GOARCH} CGO_ENABLED=0 go build -a -ldflags ' $(LDFLAGS)' -o $(PROJECT_NAME ) .
2020
2121.PHONY : vendor
2222vendor :
@@ -29,7 +29,8 @@ image: build
2929 docker build -t $(PROJECT_NAME ) :$(GIT_TAG ) .
3030
3131build-push-development :
32- docker build -t webdevops/$(PROJECT_NAME ) :development . && docker push webdevops/$(PROJECT_NAME ) :development
32+ docker buildx create --use
33+ docker buildx build -t webdevops/$(PROJECT_NAME ) :development --platform linux/amd64,linux/arm,linux/arm64 --push .
3334
3435.PHONY : test
3536test :
You can’t perform that action at this time.
0 commit comments