Skip to content

Commit

Permalink
fix(docker) makefile, docker file multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyu committed Aug 7, 2024
1 parent ae1811b commit 7edb7b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM golang:1.22-alpine AS builder
ARG TARGETOS
ARG TARGETARCH

FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o prometheus-fake-remote-read ./cmd/prometheus-fake-remote-read
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o prometheus-fake-remote-read ./cmd/prometheus-fake-remote-read

FROM alpine:latest
WORKDIR /root/

COPY --from=builder /app/prometheus-fake-remote-read .
COPY --from=builder /app/configs/example.config.json .

ENTRYPOINT [ "./prometheus-fake-remote-read" ]
CMD [ "--config", "./example.config.json" ]
ENTRYPOINT ["./prometheus-fake-remote-read"]
CMD ["--config", "./example.config.json"]
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ export
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Helpers
##@ Prepare

.PHONY: tidy
tidy: ## Pull up dependecies
go mod tidy -v

.PHONY: test
test: ## Run tests
go test -race -cover -v ./...

.PHONY: lint
lint: ## Run linting
golangci-lint run --tests=false
golangci-lint run --disable-all -E golint,goimports,misspell

##@ Prepare

.PHONY: test
test: ## Run tests
go test -race -cover -v ./...

.PHONY: run
run: ## Run for current platform
CGO_ENABLED=0 go run ./cmd/prometheus-fake-remote-read --config configs/example.config.json

##@ Build

Expand All @@ -29,6 +34,9 @@ build: ## Build for current platform
mkdir ./bin/ || true
CGO_ENABLED=0 go build -o ./bin/ ./cmd/prometheus-fake-remote-read

.PHONY: run
run: ## Run for current platform
CGO_ENABLED=0 go run ./cmd/prometheus-fake-remote-read --config configs/example.config.json
.PHONY: docker-build
docker-build: ## Test building dockerfile for multiplatforms. Using buildx
docker buildx create --use
docker buildx build --platform linux/amd64 -t prometheus-fake-remote-read:amd64 .
docker buildx build --platform linux/arm64 -t prometheus-fake-remote-read:arm64 .

0 comments on commit 7edb7b3

Please # to comment.