Simplify build process (drop docker and cross-compilation)

This commit is contained in:
Timothée Floure 2024-04-24 16:41:36 +02:00
parent 97cd8b60f0
commit 9c58b4a7d5
Signed by: tfloure
GPG Key ID: 4502C902C00A1E12
2 changed files with 9 additions and 37 deletions

View File

@ -1,20 +0,0 @@
FROM golang:alpine as build
WORKDIR /root
COPY . /root
RUN go install golang.org/x/tools/cmd/stringer@latest && go generate ./... && go build .
FROM alpine:latest
ENV LISTEN_ADDRESS="0.0.0.0" LISTEN_PORT="9452"
RUN addgroup -S mystrom \
&& adduser -S mystrom -G mystrom \
&& mkdir /app \
&& chown -R mystrom:mystrom /app
WORKDIR /app
USER mystrom
COPY --from=build /root/mystrom-exporter /app
CMD /app/mystrom-exporter -web.listen-address $LISTEN_ADDRESS:$LISTEN_PORT

View File

@ -21,36 +21,28 @@ LDFLAGS := -w -s \
-X $(versionPkgPrefix).BuildUser=${builduser} \
-X $(versionPkgPrefix).BuildDate=${builddate}
GOFLAGS := -v
GOX_FLAGS := -mod=vendor
GO_BUILD_FLAGS := -v
export GO111MODULE := on
build: go-tools generate ## builds the all platform binaries of the exporter
$(GOPATH)/bin/gox \
-os="darwin linux" \
-arch="amd64 arm arm64" \
-osarch="!darwin/arm" \
-output "${BINDIR}/{{.Dir}}-{{.OS}}-{{.Arch}}" \
-gcflags "$(GO_BUILD_FLAGS)" \
-ldflags '$(LDFLAGS)' \
-tags '$(TAGS)' \
./...
build: go-tools generate ## build mystrom-exporter for your local system
$(GO) build \
-o ${BINDIR}/mystrom-exporter \
-gcflags "$(GO_BUILD_FLAGS)" \
-ldflags '$(LDFLAGS)' \
-tags '$(TAGS)' \
.
run:
${BINDIR}/mystrom-exporter-$(shell $(GO) env GOOS)-$(shell $(GO) env GOARCH)
${BINDIR}/mystrom-exporter
generate: go-tools
$(GO) generate ./...
go-tools: $(GOPATH)/bin/stringer $(GOPATH)/bin/gox
go-tools: $(GOPATH)/bin/stringer
# -- see more info on https://pkg.go.dev/golang.org/x/tools/cmd/stringer
$(GOPATH)/bin/stringer:
$(GO) install golang.org/x/tools/cmd/stringer@latest
$(GOPATH)/bin/gox:
$(GO) install github.com/mitchellh/gox@latest
# --
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'