Skip to content

Commit

Permalink
Add version to docker build (m1k1o#301)
Browse files Browse the repository at this point in the history
* add version to build.

* update docs.
  • Loading branch information
m1k1o authored Apr 28, 2023
1 parent cd4acb5 commit 92ad202
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
#
# build server
COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go
RUN ./build

#
# STAGE 2: CLIENT
Expand Down
2 changes: 1 addition & 1 deletion .docker/base/Dockerfile.arm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
#
# build server
COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go
RUN ./build

#
# STAGE 2: CLIENT
Expand Down
2 changes: 1 addition & 1 deletion .docker/base/Dockerfile.intel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN set -eux; apt-get update; \
#
# build server
COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go
RUN ./build

#
# STAGE 2: CLIENT
Expand Down
2 changes: 1 addition & 1 deletion .docker/base/Dockerfile.nvidia
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ RUN set -eux; apt-get update; \
#
# build server
COPY server/ .
RUN go get -v -t -d . && go build -o bin/neko cmd/neko/main.go
RUN ./build

#
# STAGE 2: CLIENT
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Added nvidia support for firefox.
- 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)

### New Features
Expand Down
17 changes: 14 additions & 3 deletions server/build
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
#!/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'`

#
# 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
GIT_COMMIT=`git rev-parse --short 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_COMMIT="${GIT_DIRTY}${GIT_COMMIT}"
fi

#
# load dependencies
go get -v -t -d .

#
# build server
go build \
-o bin/neko \
-ldflags "
-s -w
-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.gitTag=${GIT_TAG}'
" \
cmd/neko/main.go;
35 changes: 16 additions & 19 deletions server/neko.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/signal"
"runtime"
"strings"

"m1k1o/neko/internal/capture"
"m1k1o/neko/internal/config"
Expand All @@ -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 (
Expand All @@ -35,25 +36,18 @@ var (
gitCommit = "dev"
//
gitBranch = "dev"

// Major version when you make incompatible API changes,
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"
//
gitTag = "dev"
)

var Service *Neko

func init() {
Service = &Neko{
Version: &Version{
Major: major,
Minor: minor,
Patch: patch,
GitCommit: gitCommit,
GitBranch: gitBranch,
GitTag: gitTag,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Expand All @@ -69,32 +63,35 @@ func init() {
}

type Version struct {
Major string
Minor string
Patch string
GitCommit string
GitBranch string
GitTag string
BuildDate string
GoVersion string
Compiler string
Platform 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 {
return fmt.Sprintf(
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
fmt.Sprintf("Version %s.%s.%s", i.Major, i.Minor, i.Patch),
return "\n" + strings.Join([]string{
fmt.Sprintf("Version %s", i.String()),
fmt.Sprintf("GitCommit %s", i.GitCommit),
fmt.Sprintf("GitBranch %s", i.GitBranch),
fmt.Sprintf("GitTag %s", i.GitTag),
fmt.Sprintf("BuildDate %s", i.BuildDate),
fmt.Sprintf("GoVersion %s", i.GoVersion),
fmt.Sprintf("Compiler %s", i.Compiler),
fmt.Sprintf("Platform %s", i.Platform),
)
}, "\n") + "\n"
}

type Neko struct {
Expand Down

0 comments on commit 92ad202

Please sign in to comment.