From cec6e814af5b8dad3c987f0033c40cc698e871e3 Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Fri, 25 Oct 2024 09:02:28 -0500 Subject: [PATCH] build: stop requiring updates to version.go --- Dockerfile | 6 ++++-- Dockerfile-openshift | 3 ++- makefile | 29 +++++++++++++++++++++-------- version.go | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index cc6a3212..0484a8dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ FROM golang:alpine as backend +ARG VERSION WORKDIR /src COPY . /src RUN go mod download -RUN CGO_ENABLED=0 go build -o ./bin/server /src/cmd/server +RUN CGO_ENABLED=0 go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/server /src/cmd/server FROM node:21-alpine as frontend +ARG VERSION COPY webui/ /watchman/ WORKDIR /watchman/ RUN npm install --legacy-peer-deps @@ -16,8 +18,8 @@ COPY --from=backend /src/bin/server /bin/server COPY --from=frontend /watchman/build/ /watchman/ ENV WEB_ROOT=/watchman/ -# USER moov # TODO(adam): non-root users EXPOSE 8084 EXPOSE 9094 + ENTRYPOINT ["/bin/server"] diff --git a/Dockerfile-openshift b/Dockerfile-openshift index e1db3ff0..b48cf01c 100644 --- a/Dockerfile-openshift +++ b/Dockerfile-openshift @@ -1,9 +1,10 @@ FROM quay.io/fedora/fedora:40-x86_64 as builder +ARG VERSION RUN yum install -y git golang make npm wget glibc WORKDIR /opt/app-root/src/ COPY . . RUN go mod download -RUN make build-server +RUN VERSION=${VERSION} make build-server FROM node:21-bookworm as frontend COPY webui/ /watchman/ diff --git a/makefile b/makefile index 4cf88896..7e28eb4a 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,18 @@ PLATFORM=$(shell uname -s | tr '[:upper:]' '[:lower:]') -VERSION := $(shell grep -Eo '(v[0-9]+[\.][0-9]+[\.][0-9]+(-[a-zA-Z0-9]*)?)' version.go) + +ifndef VERSION + ifndef RELEASE + # If we're not publishing a release, set the dev commit hash + ifndef DEV_TAG_SHA + COMMIT_HASH :=$(shell git rev-parse --short=7 HEAD) + else + COMMIT_HASH :=$(shell echo ${DEV_TAG_SHA} | cut -c 1-7) + endif + VERSION := dev-${COMMIT_HASH} + else + VERSION := $(shell git describe --tags --abbrev=0) + endif +endif .PHONY: run build build-server docker release check test @@ -14,13 +27,13 @@ else endif build-server: - CGO_ENABLED=0 go build -o ./bin/server github.com/moov-io/watchman/cmd/server + CGO_ENABLED=0 go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/server github.com/moov-io/watchman/cmd/server build-batchsearch: - CGO_ENABLED=0 go build -o ./bin/batchsearch github.com/moov-io/watchman/cmd/batchsearch + CGO_ENABLED=0 go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/batchsearch github.com/moov-io/watchman/cmd/batchsearch build-watchmantest: - CGO_ENABLED=0 go build -o ./bin/watchmantest github.com/moov-io/watchman/cmd/watchmantest + CGO_ENABLED=0 go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/watchmantest github.com/moov-io/watchman/cmd/watchmantest .PHONY: check check: @@ -71,18 +84,18 @@ endif docker: clean docker-hub docker-openshift docker-static docker-watchmantest docker-hub: - docker build --pull -t moov/watchman:$(VERSION) -f Dockerfile . + docker build --pull --build-arg VERSION=${VERSION} -t moov/watchman:$(VERSION) -f Dockerfile . docker tag moov/watchman:$(VERSION) moov/watchman:latest docker-openshift: - docker build --pull -t quay.io/moov/watchman:$(VERSION) -f Dockerfile-openshift --build-arg VERSION=$(VERSION) . + docker build --pull --build-arg VERSION=${VERSION} -t quay.io/moov/watchman:$(VERSION) -f Dockerfile-openshift --build-arg VERSION=$(VERSION) . docker tag quay.io/moov/watchman:$(VERSION) quay.io/moov/watchman:latest docker-static: - docker build --pull -t moov/watchman:static -f Dockerfile-static . + docker build --pull --build-arg VERSION=${VERSION} -t moov/watchman:static -f Dockerfile-static . docker-watchmantest: - docker build --pull -t moov/watchmantest:$(VERSION) -f ./cmd/watchmantest/Dockerfile . + docker build --pull --build-arg VERSION=${VERSION} -t moov/watchmantest:$(VERSION) -f ./cmd/watchmantest/Dockerfile . docker tag moov/watchmantest:$(VERSION) moov/watchmantest:latest release: docker AUTHORS diff --git a/version.go b/version.go index 106b81d7..08c83c98 100644 --- a/version.go +++ b/version.go @@ -4,4 +4,4 @@ package watchman -const Version = "v0.30.0" +var Version string