File tree Expand file tree Collapse file tree 2 files changed +29
-11
lines changed
Expand file tree Collapse file tree 2 files changed +29
-11
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/kube-bootstrap-token-manager
10+
11+ # Dependencies
12+ COPY go.mod go.sum .
13+ RUN go mod download
14+
715# Compile
8- COPY ./ /go/src/github.com/webdevops/kube-bootstrap-token-manager
9- RUN make dependencies
16+ COPY . .
1017RUN make test
11- RUN make build
12- RUN ./kube-bootstrap-token-manager --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/kube-bootstrap-token-manager/kube-bootstrap-token-manager .
28+ RUN ["./kube-bootstrap-token-manager" , "--help" ]
1329
1430# ############################################
15- # FINAL IMAGE
31+ # Final
1632# ############################################
1733FROM gcr.io/distroless/static
1834ENV LOG_JSON=1
19- COPY --from=build /go/src/github.com/webdevops/kube-bootstrap-token-manager/kube-bootstrap-token-manager /
35+ WORKDIR /
36+ COPY --from=test /app .
2037USER 1000:1000
2138ENTRYPOINT ["/kube-bootstrap-token-manager" ]
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 :
@@ -40,7 +41,7 @@ dependencies:
4041 go mod vendor
4142
4243.PHONY : check-release
43- check-release : vendor lint gosec
44+ check-release : vendor lint gosec test
4445
4546.PHONY : lint
4647lint : $(GOLANGCI_LINT_BIN )
You can’t perform that action at this time.
0 commit comments