Add version to docker build (#301)

* add version to build.

* update docs.
This commit is contained in:
Miroslav Šedivý 2023-04-29 00:12:56 +02:00 committed by GitHub
parent cd4acb5eec
commit 92ad202bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 26 deletions

View File

@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
# #
# build server # build server
COPY server/ . COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go RUN ./build
# #
# STAGE 2: CLIENT # STAGE 2: CLIENT

View File

@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
# #
# build server # build server
COPY server/ . COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go RUN ./build
# #
# STAGE 2: CLIENT # STAGE 2: CLIENT

View File

@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
# #
# build server # build server
COPY server/ . COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go RUN ./build
# #
# STAGE 2: CLIENT # STAGE 2: CLIENT

View File

@ -82,7 +82,7 @@ RUN set -eux; apt-get update; \
# #
# build server # build server
COPY server/ . COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go RUN ./build
# #
# STAGE 2: CLIENT # STAGE 2: CLIENT

View File

@ -6,6 +6,9 @@
- Added nvidia support for firefox. - Added nvidia support for firefox.
- Added `?lang=<lang>` parameter to the URL, which will set the language of the interface (by @mbattista). - Added `?lang=<lang>` parameter to the URL, which will set the language of the interface (by @mbattista).
### Misc
- Git commit and tag are now included in the build when creating a docker image.
## [n.eko v2.8.0](https://github.com/m1k1o/neko/releases/tag/v2.8.0) ## [n.eko v2.8.0](https://github.com/m1k1o/neko/releases/tag/v2.8.0)
### New Features ### New Features

View File

@ -1,24 +1,35 @@
#!/bin/bash #!/bin/bash
set -ex #
# aborting if any command returns a non-zero value
set -e
BUILD_TIME=`date -u +'%Y-%m-%dT%H:%M:%SZ'` BUILD_TIME=`date -u +'%Y-%m-%dT%H:%M:%SZ'`
# #
# set git build variables if git exists # set git build variables if git exists
if git status > /dev/null 2>&1 && [ -z $GIT_COMMIT ] && [ -z $GIT_BRANCH ] && [ -z $GIT_DIRTY ]; if git status > /dev/null 2>&1 && [ -z $GIT_COMMIT ] && [ -z $GIT_BRANCH ] && [ -z $GIT_TAG ];
then then
GIT_COMMIT=`git rev-parse --short HEAD` GIT_COMMIT=`git rev-parse --short HEAD`
GIT_BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` GIT_BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
GIT_TAG=`git tag --points-at $GIT_COMMIT | head -n 1`
GIT_DIRTY=`git diff-index --quiet HEAD -- || echo "✗-"` GIT_DIRTY=`git diff-index --quiet HEAD -- || echo "✗-"`
GIT_COMMIT="${GIT_DIRTY}${GIT_COMMIT}"
fi fi
#
# load dependencies
go get -v -t -d .
#
# build server
go build \ go build \
-o bin/neko \ -o bin/neko \
-ldflags " -ldflags "
-s -w -s -w
-X 'm1k1o/neko.buildDate=${BUILD_TIME}' -X 'm1k1o/neko.buildDate=${BUILD_TIME}'
-X 'm1k1o/neko.gitCommit=${GIT_DIRTY}${GIT_COMMIT}' -X 'm1k1o/neko.gitCommit=${GIT_COMMIT}'
-X 'm1k1o/neko.gitBranch=${GIT_BRANCH}' -X 'm1k1o/neko.gitBranch=${GIT_BRANCH}'
-X 'm1k1o/neko.gitTag=${GIT_TAG}'
" \ " \
cmd/neko/main.go; cmd/neko/main.go;

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"runtime" "runtime"
"strings"
"m1k1o/neko/internal/capture" "m1k1o/neko/internal/capture"
"m1k1o/neko/internal/config" "m1k1o/neko/internal/config"
@ -25,7 +26,7 @@ const Header = `&34
/ |/ / _ \/ //_/ __ \ ) ( ') / |/ / _ \/ //_/ __ \ ) ( ')
/ /| / __/ ,< / /_/ / ( / ) / /| / __/ ,< / /_/ / ( / )
/_/ |_/\___/_/|_|\____/ \(__)| /_/ |_/\___/_/|_|\____/ \(__)|
&1&37 nurdism/m1k1o &33%s v%s&0 &1&37 nurdism/m1k1o &33%s %s&0
` `
var ( var (
@ -35,13 +36,8 @@ var (
gitCommit = "dev" gitCommit = "dev"
// //
gitBranch = "dev" gitBranch = "dev"
//
// Major version when you make incompatible API changes, gitTag = "dev"
major = "2"
// Minor version when you add functionality in a backwards-compatible manner, and
minor = "8"
// Patch version when you make backwards-compatible bug fixes.
patch = "0"
) )
var Service *Neko var Service *Neko
@ -49,11 +45,9 @@ var Service *Neko
func init() { func init() {
Service = &Neko{ Service = &Neko{
Version: &Version{ Version: &Version{
Major: major,
Minor: minor,
Patch: patch,
GitCommit: gitCommit, GitCommit: gitCommit,
GitBranch: gitBranch, GitBranch: gitBranch,
GitTag: gitTag,
BuildDate: buildDate, BuildDate: buildDate,
GoVersion: runtime.Version(), GoVersion: runtime.Version(),
Compiler: runtime.Compiler, Compiler: runtime.Compiler,
@ -69,11 +63,9 @@ func init() {
} }
type Version struct { type Version struct {
Major string
Minor string
Patch string
GitCommit string GitCommit string
GitBranch string GitBranch string
GitTag string
BuildDate string BuildDate string
GoVersion string GoVersion string
Compiler string Compiler string
@ -81,20 +73,25 @@ type Version struct {
} }
func (i *Version) String() string { func (i *Version) String() string {
return fmt.Sprintf("%s.%s.%s %s", i.Major, i.Minor, i.Patch, i.GitCommit) version := i.GitTag
if version == "" || version == "dev" {
version = i.GitBranch
}
return fmt.Sprintf("%s@%s", version, i.GitCommit)
} }
func (i *Version) Details() string { func (i *Version) Details() string {
return fmt.Sprintf( return "\n" + strings.Join([]string{
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n", fmt.Sprintf("Version %s", i.String()),
fmt.Sprintf("Version %s.%s.%s", i.Major, i.Minor, i.Patch),
fmt.Sprintf("GitCommit %s", i.GitCommit), fmt.Sprintf("GitCommit %s", i.GitCommit),
fmt.Sprintf("GitBranch %s", i.GitBranch), fmt.Sprintf("GitBranch %s", i.GitBranch),
fmt.Sprintf("GitTag %s", i.GitTag),
fmt.Sprintf("BuildDate %s", i.BuildDate), fmt.Sprintf("BuildDate %s", i.BuildDate),
fmt.Sprintf("GoVersion %s", i.GoVersion), fmt.Sprintf("GoVersion %s", i.GoVersion),
fmt.Sprintf("Compiler %s", i.Compiler), fmt.Sprintf("Compiler %s", i.Compiler),
fmt.Sprintf("Platform %s", i.Platform), fmt.Sprintf("Platform %s", i.Platform),
) }, "\n") + "\n"
} }
type Neko struct { type Neko struct {