mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
Merge pull request #406 from dgrisonnet/fix-build
Makefile: consolidate docker-build
This commit is contained in:
commit
89b6c7e31c
5 changed files with 40 additions and 29 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
*.swp
|
*.swp
|
||||||
*~
|
*~
|
||||||
/_output
|
|
||||||
/vendor
|
/vendor
|
||||||
|
/adapter
|
||||||
|
|
|
||||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
ARG BASEIMAGE
|
||||||
|
ARG GOIMAGE
|
||||||
|
|
||||||
|
FROM ${GOIMAGE} as build
|
||||||
|
|
||||||
|
WORKDIR /go/src/sigs.k8s.io/prometheus-adapter
|
||||||
|
COPY go.mod .
|
||||||
|
COPY go.sum .
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY pkg pkg
|
||||||
|
COPY cmd cmd
|
||||||
|
COPY Makefile Makefile
|
||||||
|
|
||||||
|
ARG ARCH
|
||||||
|
RUN make prometheus-adapter
|
||||||
|
|
||||||
|
FROM ${BASEIMAGE}
|
||||||
|
|
||||||
|
COPY --from=build /go/src/sigs.k8s.io/prometheus-adapter/adapter /
|
||||||
|
USER 65534
|
||||||
|
ENTRYPOINT ["/adapter"]
|
||||||
36
Makefile
36
Makefile
|
|
@ -3,12 +3,9 @@ IMAGE?=k8s-prometheus-adapter
|
||||||
ARCH?=$(shell go env GOARCH)
|
ARCH?=$(shell go env GOARCH)
|
||||||
ALL_ARCH=amd64 arm arm64 ppc64le s390x
|
ALL_ARCH=amd64 arm arm64 ppc64le s390x
|
||||||
ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x
|
ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x
|
||||||
OUT_DIR?=$(PWD)/_output
|
|
||||||
|
|
||||||
VERSION?=latest
|
VERSION?=latest
|
||||||
GOIMAGE=golang:1.15
|
GOIMAGE=golang:1.16
|
||||||
GO111MODULE=on
|
|
||||||
export GO111MODULE
|
|
||||||
|
|
||||||
ifeq ($(ARCH),amd64)
|
ifeq ($(ARCH),amd64)
|
||||||
BASEIMAGE?=busybox
|
BASEIMAGE?=busybox
|
||||||
|
|
@ -26,31 +23,26 @@ ifeq ($(ARCH),s390x)
|
||||||
BASEIMAGE?=s390x/busybox
|
BASEIMAGE?=s390x/busybox
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all docker-build push-% push test verify-gofmt gofmt verify build-local-image
|
.PHONY: all
|
||||||
|
all: prometheus-adapter
|
||||||
|
|
||||||
all: $(OUT_DIR)/$(ARCH)/adapter
|
# Build
|
||||||
|
# -----
|
||||||
|
|
||||||
src_deps=$(shell find pkg cmd -type f -name "*.go")
|
src_deps=$(shell find pkg cmd -type f -name "*.go")
|
||||||
$(OUT_DIR)/%/adapter: $(src_deps)
|
prometheus-adapter: $(src_deps)
|
||||||
CGO_ENABLED=0 GOARCH=$* go build -tags netgo -o $(OUT_DIR)/$*/adapter sigs.k8s.io/prometheus-adapter/cmd/adapter
|
CGO_ENABLED=0 GOARCH=$(ARCH) go build sigs.k8s.io/prometheus-adapter/cmd/adapter
|
||||||
|
|
||||||
docker-build: $(OUT_DIR)/Dockerfile
|
.PHONY: docker-build
|
||||||
docker run -it -v $(OUT_DIR):/build -v $(PWD):/go/src/sigs.k8s.io/prometheus-adapter -e GOARCH=$(ARCH) $(GOIMAGE) /bin/bash -c "\
|
docker-build:
|
||||||
CGO_ENABLED=0 go build -tags netgo -o /build/$(ARCH)/adapter sigs.k8s.io/prometheus-adapter/cmd/adapter"
|
docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg GOIMAGE=$(GOIMAGE) .
|
||||||
|
|
||||||
docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) $(OUT_DIR)
|
|
||||||
|
|
||||||
$(OUT_DIR)/Dockerfile: deploy/Dockerfile
|
|
||||||
mkdir -p $(OUT_DIR)
|
|
||||||
cp deploy/Dockerfile $(OUT_DIR)/Dockerfile
|
|
||||||
|
|
||||||
build-local-image: $(OUT_DIR)/Dockerfile $(OUT_DIR)/$(ARCH)/adapter
|
|
||||||
docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=scratch $(OUT_DIR)
|
|
||||||
|
|
||||||
|
.PHONY: push-%
|
||||||
push-%:
|
push-%:
|
||||||
$(MAKE) ARCH=$* docker-build
|
$(MAKE) ARCH=$* docker-build
|
||||||
docker push $(REGISTRY)/$(IMAGE)-$*:$(VERSION)
|
docker push $(REGISTRY)/$(IMAGE)-$*:$(VERSION)
|
||||||
|
|
||||||
|
.PHONY: push
|
||||||
push: ./manifest-tool $(addprefix push-,$(ALL_ARCH))
|
push: ./manifest-tool $(addprefix push-,$(ALL_ARCH))
|
||||||
./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(REGISTRY)/$(IMAGE)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMAGE):$(VERSION)
|
./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(REGISTRY)/$(IMAGE)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMAGE):$(VERSION)
|
||||||
|
|
||||||
|
|
@ -58,15 +50,19 @@ push: ./manifest-tool $(addprefix push-,$(ALL_ARCH))
|
||||||
curl -sSL https://github.com/estesp/manifest-tool/releases/download/v0.5.0/manifest-tool-linux-amd64 > manifest-tool
|
curl -sSL https://github.com/estesp/manifest-tool/releases/download/v0.5.0/manifest-tool-linux-amd64 > manifest-tool
|
||||||
chmod +x manifest-tool
|
chmod +x manifest-tool
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
CGO_ENABLED=0 go test ./cmd/... ./pkg/...
|
CGO_ENABLED=0 go test ./cmd/... ./pkg/...
|
||||||
|
|
||||||
|
.PHONY: verify-gofmt
|
||||||
verify-gofmt:
|
verify-gofmt:
|
||||||
./hack/gofmt-all.sh -v
|
./hack/gofmt-all.sh -v
|
||||||
|
|
||||||
|
.PHONY: gofmt
|
||||||
gofmt:
|
gofmt:
|
||||||
./hack/gofmt-all.sh
|
./hack/gofmt-all.sh
|
||||||
|
|
||||||
|
.PHONY: verify
|
||||||
verify: verify-gofmt verify-deps verify-generated test
|
verify: verify-gofmt verify-deps verify-generated test
|
||||||
|
|
||||||
.PHONY: update
|
.PHONY: update
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
ARG BASEIMAGE
|
|
||||||
FROM ${BASEIMAGE}
|
|
||||||
ARG ARCH
|
|
||||||
COPY ${ARCH}/adapter /
|
|
||||||
USER 1001:1001
|
|
||||||
ENTRYPOINT ["/adapter"]
|
|
||||||
|
|
@ -46,8 +46,7 @@ an x86_64 machine, use the `directxman12/k8s-prometheus-adapter-amd64`
|
||||||
image.
|
image.
|
||||||
|
|
||||||
If you're feeling adventurous, you can build the latest version of the
|
If you're feeling adventurous, you can build the latest version of the
|
||||||
custom metrics adapter by running `make docker-build` or `make
|
custom metrics adapter by running `make docker-build`.
|
||||||
build-local-image`.
|
|
||||||
|
|
||||||
Special thanks to [@luxas](https://github.com/luxas) for providing the
|
Special thanks to [@luxas](https://github.com/luxas) for providing the
|
||||||
demo application for this walkthrough.
|
demo application for this walkthrough.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue