diff --git a/Dockerfile b/Dockerfile index 3b3cbbb3..1b712a8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 603a4ef9..8f667d49 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/banner.go b/banner.go new file mode 100644 index 00000000..83f86f55 --- /dev/null +++ b/banner.go @@ -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) +} diff --git a/main.go b/main.go index 301a7dd5..6f98fa1c 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/server/server.go b/server/server.go index 4fd51e61..f31b9902 100644 --- a/server/server.go +++ b/server/server.go @@ -15,8 +15,6 @@ import ( "github.com/go-chi/cors" ) -const Version = "0.2.0" - type Server struct { Scanner *scanner.Scanner router *chi.Mux diff --git a/static/banner.txt b/static/banner.txt index ab4be290..cd6828ec 100644 --- a/static/banner.txt +++ b/static/banner.txt @@ -4,5 +4,3 @@ | . ` |/ _` \ \ / / |/ _` | '__/ _ \| '_ ` _ \ / _ \ | |\ | (_| |\ V /| | (_| | | | (_) | | | | | | __/ \_| \_/\__,_| \_/ |_|\__,_|_| \___/|_| |_| |_|\___| - Version %s - diff --git a/static/bindata.go b/static/bindata.go index 3877216b..0d0191c5 100644 --- a/static/bindata.go +++ b/static/bindata.go @@ -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 }