Add git info to version

This commit is contained in:
Deluan 2020-01-25 11:06:04 -05:00
parent 9ed35cbb02
commit 8756f55650
7 changed files with 60 additions and 27 deletions

View File

@ -17,6 +17,12 @@ RUN mkdir -p /src/ui/build
RUN apk add -U --no-cache build-base git
RUN go get -u github.com/go-bindata/go-bindata/...
# Download and unpack static ffmpeg
ARG FFMPEG_VERSION=4.1.4
ARG FFMPEG_URL=https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-${FFMPEG_VERSION}-amd64-static.tar.xz
RUN wget -O /tmp/ffmpeg.tar.xz ${FFMPEG_URL}
RUN cd /tmp && tar xJf ffmpeg.tar.xz && rm ffmpeg.tar.xz
# Download project dependencies
WORKDIR /src
COPY go.mod go.sum ./
@ -30,13 +36,6 @@ COPY --from=jsbuilder /src/build/static/js/* /src/ui/build/static/js/
RUN rm -rf /src/build/css /src/build/js
RUN make buildall
# Download and unpack static ffmpeg
ARG FFMPEG_VERSION=4.1.4
ARG FFMPEG_URL=https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-${FFMPEG_VERSION}-amd64-static.tar.xz
RUN wget -O /tmp/ffmpeg.tar.xz ${FFMPEG_URL}
RUN cd /tmp && tar xJf ffmpeg.tar.xz && rm ffmpeg.tar.xz
#####################################################
### Build Final Image
FROM alpine

View File

@ -1,6 +1,11 @@
GO_VERSION=1.13
NODE_VERSION=v13.7.0
GIT_HASH=$(shell git rev-parse --short HEAD)
GIT_BRANCH=$(shell git symbolic-ref --short -q HEAD)
GIT_TAG=$(shell git describe --tags --abbrev=0 2> /dev/null)
GIT_COUNT=$(shell git rev-list HEAD --count)
.PHONY: dev
dev: check_env data
@goreman -f Procfile.dev -b 4533 start
@ -22,10 +27,6 @@ test: check_go_env
testall: check_go_env test
@(cd ./ui && npm test -- --watchAll=false)
.PHONY: build
build: check_go_env
go build
.PHONY: setup
setup: Jamstash-master
@which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex)
@ -69,7 +70,12 @@ ui/build: $(UI_SRC) $(UI_PUBLIC) ui/package-lock.json
assets/embedded_gen.go: ui/build
go-bindata -fs -prefix "ui/build" -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/...
.PHONY: build
build: check_go_env
go build -ldflags="-X main.gitCount=$(GIT_COUNT) -X main.gitHash=$(GIT_HASH) -X main.gitBranch=$(GIT_BRANCH) -X main.gitTag=$(GIT_TAG)"
.PHONY: buildall
buildall: check_go_env assets/embedded_gen.go
go build -tags embed
go build -ldflags="-X main.gitCount=$(GIT_COUNT) -X main.gitHash=$(GIT_HASH) -X main.gitBranch=$(GIT_BRANCH) -X main.gitTag=$(GIT_TAG)" \
-tags embed

42
banner.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
"fmt"
"strings"
"github.com/deluan/navidrome/static"
)
var (
// This will be set in build time. If not, version will be set to "dev"
gitBranch string
gitTag string
gitHash string
gitCount string
)
// Formats:
// dev
// v0.2.0 (596-5b84188)
// master (600-9ed35cb)
func getVersion() string {
if gitHash == "" {
return "dev"
}
version := fmt.Sprintf(" (%s-%s)", gitCount, gitHash)
if gitTag != "" {
return gitTag + version
}
return gitBranch + version
}
func getBanner() string {
data, _ := static.Asset("banner.txt")
return strings.TrimSuffix(string(data), "\n")
}
func ShowBanner() {
version := "Version: " + getVersion()
padding := strings.Repeat(" ", 52-len(version))
fmt.Printf("%s%s%s\n\n", getBanner(), padding, version)
}

View File

@ -1,18 +1,9 @@
package main
import (
"fmt"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/server"
"github.com/deluan/navidrome/static"
)
func ShowBanner() {
banner, _ := static.Asset("banner.txt")
fmt.Printf(string(banner), server.Version)
}
func main() {
conf.Load()

View File

@ -15,8 +15,6 @@ import (
"github.com/go-chi/cors"
)
const Version = "0.2.0"
type Server struct {
Scanner *scanner.Scanner
router *chi.Mux

View File

@ -4,5 +4,3 @@
| . ` |/ _` \ \ / / |/ _` | '__/ _ \| '_ ` _ \ / _ \
| |\ | (_| |\ V /| | (_| | | | (_) | | | | | | __/
\_| \_/\__,_| \_/ |_|\__,_|_| \___/|_| |_| |_|\___|
Version %s

View File

@ -150,7 +150,6 @@ var _bannerTxt = []byte(` _ _ _ _
| . ` + "`" + ` |/ _` + "`" + ` \ \ / / |/ _` + "`" + ` | '__/ _ \| '_ ` + "`" + ` _ \ / _ \
| |\ | (_| |\ V /| | (_| | | | (_) | | | | | | __/
\_| \_/\__,_| \_/ |_|\__,_|_| \___/|_| |_| |_|\___|
Version %s
`)
@ -164,7 +163,7 @@ func bannerTxt() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "banner.txt", size: 317, mode: os.FileMode(420), modTime: time.Unix(1579927428, 0)}
info := bindataFileInfo{name: "banner.txt", size: 267, mode: os.FileMode(420), modTime: time.Unix(1579965459, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}