make the app version in backend parsing from package.json and git revision
This commit is contained in:
+7
-2
@@ -1,9 +1,14 @@
|
|||||||
# Build backend binary file
|
# Build backend binary file
|
||||||
FROM golang:1.14.10-alpine3.12 AS be-builder
|
FROM golang:1.14.10-alpine3.12 AS be-builder
|
||||||
RUN apk add gcc g++ libc-dev
|
RUN apk add git gcc g++ libc-dev
|
||||||
WORKDIR /go/src/github.com/mayswind/lab
|
WORKDIR /go/src/github.com/mayswind/lab
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -a -v -i -trimpath -o lab lab.go
|
RUN VERSION=`grep '"version": ' package.json | awk -F ':' '{print $2}' | tr -d ' ' | tr -d ',' | tr -d '"'` \
|
||||||
|
&& COMMIT_HASH=$(git rev-parse --short HEAD) \
|
||||||
|
&& GOOS=linux \
|
||||||
|
&& GOARCH=amd64 \
|
||||||
|
&& CGO_ENABLED=1 \
|
||||||
|
&& go build -a -v -i -trimpath -ldflags "-X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH}" -o lab lab.go
|
||||||
RUN chmod +x lab
|
RUN chmod +x lab
|
||||||
|
|
||||||
# Build frontend files
|
# Build frontend files
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -9,13 +10,14 @@ import (
|
|||||||
"github.com/mayswind/lab/cmd"
|
"github.com/mayswind/lab/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
const labVersion = "0.1.0"
|
var version string
|
||||||
|
var commitHash string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "lab",
|
Name: "lab",
|
||||||
Usage: "A lightweight account book app hosted by yourself.",
|
Usage: "A lightweight account book app hosted by yourself.",
|
||||||
Version: labVersion,
|
Version: getVersion(),
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
cmd.WebServer,
|
cmd.WebServer,
|
||||||
cmd.Database,
|
cmd.Database,
|
||||||
@@ -34,3 +36,17 @@ func main() {
|
|||||||
log.Fatalf("Failed to run lab app with %s: %v", os.Args, err)
|
log.Fatalf("Failed to run lab app with %s: %v", os.Args, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getVersion() string {
|
||||||
|
fullVersion := "Local Build"
|
||||||
|
|
||||||
|
if version != "" {
|
||||||
|
fullVersion = version
|
||||||
|
}
|
||||||
|
|
||||||
|
if commitHash != "" {
|
||||||
|
fullVersion = fmt.Sprintf("%s (%s)", fullVersion, commitHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullVersion
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user