From d112bf4be7f9c729cedc936fac66688cc70c58de Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Fri, 29 Mar 2019 10:18:23 +0100 Subject: [PATCH] proper version number for builds --- Makefile | 3 ++- server/Makefile | 17 +++++++++++------ server/app/app.go | 4 ---- server/app/version.go | 3 +++ server/web/config.go | 2 ++ 5 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 server/app/version.go diff --git a/Makefile b/Makefile index 185c524..9ad9a56 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ OUT_DIR=output MOD_ZIP=$(OUT_DIR)/mapserver-mod.zip +VERSION=git-$(shell git rev-parse HEAD) all: $(OUT_DIR) $(MOD_ZIP) # build the docker image with all dependencies @@ -11,7 +12,7 @@ all: $(OUT_DIR) $(MOD_ZIP) -v mapserver-volume:/root/go\ -w /app\ mapserver-builder\ - make test all + make test all VERSION=$(VERSION) # copy generated files to output dir cp server/output/* $(OUT_DIR)/ diff --git a/server/Makefile b/server/Makefile index d73e8ea..2160057 100644 --- a/server/Makefile +++ b/server/Makefile @@ -1,8 +1,13 @@ STATIC_VFS=vfs/static.go OUT_DIR=output ENV=GO111MODULE=on +VERSION=git-$(shell git rev-parse HEAD) -GO_LDFLAGS=-ldflags "-linkmode external -extldflags -static" + +# -ldflags="-X mapserver/app.Version=1.0" +GO_LDFLAGS=-ldflags "-linkmode external -extldflags -static -X mapserver/app.Version=$(VERSION)" +GO_LDFLAGS_WIN=-ldflags "-X mapserver/app.Version=$(VERSION)" +GO_BUILD=CGO_ENABLED=1 go build BINARIES = $(OUT_DIR)/mapserver-linux-x86_64 BINARIES += $(OUT_DIR)/mapserver-linux-x86 @@ -30,21 +35,21 @@ $(STATIC_VFS): $(OUT_DIR)/mapserver-linux-x86_64: $(OUT_DIR) # native (linux x86_64) - CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-gnu-gcc go build $(GO_LDFLAGS) -o $@ + GOOS=linux GOARCH=amd64 CC=x86_64-linux-gnu-gcc $(GO_BUILD) $(GO_LDFLAGS) -o $@ $(OUT_DIR)/mapserver-linux-x86: $(OUT_DIR) # apt install gcc-8-i686-linux-gnu - CGO_ENABLED=1 GOOS=linux GOARCH=386 CC=i686-linux-gnu-gcc-7 go build $(GO_LDFLAGS) -o $@ + GOOS=linux GOARCH=386 CC=i686-linux-gnu-gcc-7 $(GO_BUILD) $(GO_LDFLAGS) -o $@ $(OUT_DIR)/mapserver-windows-x86.exe: $(OUT_DIR) # apt install gcc-mingw-w64 - GOARCH=386 GOOS=windows CC=i686-w64-mingw32-gcc CGO_ENABLED=1 go build -o $@ + GOARCH=386 GOOS=windows CC=i686-w64-mingw32-gcc $(GO_BUILD) $(GO_LDFLAGS_WIN) -o $@ $(OUT_DIR)/mapserver-windows-x86-64.exe: $(OUT_DIR) - GOARCH=amd64 GOOS=windows CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -o $@ + GOARCH=amd64 GOOS=windows CC=x86_64-w64-mingw32-gcc $(GO_BUILD) $(GO_LDFLAGS_WIN) -o $@ $(OUT_DIR)/mapserver-linux-arm: $(OUT_DIR) # apt install gcc-5-arm-linux-gnueabihf - GOARCH=arm GOARM=7 CC=arm-linux-gnueabihf-gcc-5 CGO_ENABLED=1 go build $(GO_LDFLAGS) -o $@ + GOARCH=arm GOARM=7 CC=arm-linux-gnueabihf-gcc-5 $(GO_BUILD) $(GO_LDFLAGS) -o $@ all: $(STATIC_VFS) $(BINARIES) diff --git a/server/app/app.go b/server/app/app.go index ec9134a..20b9573 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -13,10 +13,6 @@ import ( "mapserver/tilerenderer" ) -const ( - Version = "1.0.1" -) - type App struct { Params params.ParamsType Config *Config diff --git a/server/app/version.go b/server/app/version.go new file mode 100644 index 0000000..4a130b2 --- /dev/null +++ b/server/app/version.go @@ -0,0 +1,3 @@ +package app + +var Version = "dev" diff --git a/server/web/config.go b/server/web/config.go index 1b6515b..1469ff6 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -9,6 +9,7 @@ import ( //Public facing config type PublicConfig struct { + Version string `json:"version"` Layers []*layer.Layer `json:"layers"` MapObjects *app.MapObjectConfig `json:"mapobjects"` } @@ -23,6 +24,7 @@ func (h *ConfigHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { webcfg := PublicConfig{} webcfg.Layers = h.ctx.Config.Layers webcfg.MapObjects = h.ctx.Config.MapObjects + webcfg.Version = app.Version json.NewEncoder(resp).Encode(webcfg) }