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