chore: add build target to Makefile & builder to Dockerfile (#215)

This commit is contained in:
Stephen Cuppett 2022-03-30 05:39:59 -04:00 committed by GitHub
parent 877a9ffa0a
commit de88bc221a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -1,10 +1,29 @@
FROM alpine:3.15.0
# Build the binary
FROM docker.io/library/golang:1.18 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY cmd/ cmd/
COPY phpfpm/ phpfpm/
# Build
RUN CGO_ENABLED=0 go build -a -o php-fpm_exporter main.go
FROM docker.io/library/alpine:3.15.0
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
COPY php-fpm_exporter /
COPY --from=builder /workspace/php-fpm_exporter .
EXPOSE 9253
ENTRYPOINT [ "/php-fpm_exporter", "server" ]

View file

@ -7,6 +7,9 @@ help: ## List targets & descriptions
deps: ## Get dependencies
go get -d -v ./...
build: deps ## Build the binary
go build -a -o php-fpm_exporter main.go
test: ## Run tests
go test -short ./...
@ -26,4 +29,4 @@ lint: ## Run linters
golangci-lint run
fmt: ## Fix formatting issues
goimports -w .
goimports -w .