diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a071df65..5fef333b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -113,4 +113,4 @@ jobs: if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v2 - - run: docker build . + - run: docker build --build-arg VERSION=$(./scripts/version.sh) . diff --git a/Dockerfile b/Dockerfile index 5aec526e..46bd7506 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y \ && rm -rf /var/lib/apt/lists/* # go setup layer -ARG GO=go1.16.3.linux-amd64.tar.gz +ARG GO=go1.16.6.linux-amd64.tar.gz RUN wget -q https://golang.org/dl/$GO \ && rm -rf /usr/local/go \ && tar -C /usr/local -xzf $GO \ @@ -35,7 +35,9 @@ RUN go mod download COPY pkg ./pkg COPY cmd ./cmd COPY Makefile . -RUN make build +COPY scripts ./scripts +ARG VERSION +RUN GIT_VERSION=${VERSION} make build # base image FROM debian:bullseye-slim @@ -51,5 +53,9 @@ RUN cp -s $(pwd)/* /usr/local/bin COPY assets/cores ./assets/cores COPY configs ./configs COPY web ./web +ARG VERSION +COPY scripts/version.sh version.sh +RUN bash ./version.sh ./web/index.html ${VERSION} && \ + rm -rf version.sh EXPOSE 8000 9000 diff --git a/Makefile b/Makefile index 7f1feb26..649d1124 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,8 @@ clean: @go clean ./cmd/* build: - CGO_ENABLED=0 go build -ldflags '-w -s' -o bin/ ./cmd/coordinator - go build -buildmode=exe -tags static -ldflags '-w -s' $(EXT_WFLAGS) -o bin/ ./cmd/worker + CGO_ENABLED=0 go build -ldflags "-w -s -X 'main.Version=$(GIT_VERSION)'" -o bin/ ./cmd/coordinator + go build -buildmode=exe -tags static -ldflags "-w -s -X 'main.Version=$(GIT_VERSION)'" $(EXT_WFLAGS) -o bin/ ./cmd/worker verify-cores: go test -run TestAllEmulatorRooms ./pkg/worker/room -v -renderFrames $(GL_CTX) -outputPath "../../../_rendered" @@ -120,6 +120,7 @@ CORES_DIR = assets/cores GAMES_DIR = assets/games .PHONY: release .SILENT: release +release: GIT_VERSION := "$(shell ./scripts/version.sh)" release: clean build rm -rf ./$(RELEASE_DIR) && mkdir ./$(RELEASE_DIR) mkdir -p $(COORDINATOR_DIR) && mkdir -p $(WORKER_DIR) @@ -133,6 +134,8 @@ release: clean build $(DLIB_TOOL) $(WORKER_DIR) $(WORKER_DIR)/worker endif cp -R ./web $(COORDINATOR_DIR) + # add version tag into index.html + shell ./scripts/version.sh $(COORDINATOR_DIR)/web/index.html mkdir -p $(WORKER_DIR)/$(GAMES_DIR) ifneq (,$(wildcard ./$(GAMES_DIR))) cp -R ./$(GAMES_DIR) $(WORKER_DIR)/assets diff --git a/cmd/coordinator/main.go b/cmd/coordinator/main.go index 49654265..bdabb333 100644 --- a/cmd/coordinator/main.go +++ b/cmd/coordinator/main.go @@ -16,6 +16,8 @@ import ( flag "github.com/spf13/pflag" ) +var Version = "" + func main() { rand.Seed(time.Now().UTC().UnixNano()) @@ -28,6 +30,7 @@ func main() { ctx, cancelCtx := context.WithCancel(context.Background()) + glog.Infof("[coordinator] version: %v", Version) glog.Infof("Initializing coordinator server") glog.V(4).Infof("Coordinator configs %v", conf) o := coordinator.New(ctx, conf) diff --git a/cmd/worker/main.go b/cmd/worker/main.go index bc8f979a..3126b8b1 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -17,6 +17,8 @@ import ( flag "github.com/spf13/pflag" ) +var Version = "" + func init() { rand.Seed(time.Now().UTC().UnixNano()) } @@ -31,6 +33,7 @@ func run() { ctx, cancelCtx := context.WithCancel(context.Background()) + glog.Infof("[worker] version: %v", Version) glog.V(4).Info("[worker] Initialization") glog.V(4).Infof("[worker] Local configuration %+v", conf) wrk := worker.New(ctx, conf) diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 00000000..f56f9936 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +file="$1" +version="$2" +from="().*?(<\/span>)" + +# Prints app version derived from git in the following format: +# +# v2-1-gcafeb +# ^ ^ ^ ^ +# | | | | +# | | | '- commit hash of HEAD (1st 5 symbols) +# | | '-- "g" stands for git +# | '---- n commits since the last tag +# '------- last tag +# +# See: https://git-scm.com/docs/git-describe +# +# The first input param replaces the version placeholder in the provided file. +# The second input param forces the use of some version value instead of a git-derived one. +# +if [ "$version" = "" ]; then + version=$(git describe --abbrev=5 --always --tags 2> /dev/null) +fi +if [ "$file" != "" ]; then + sed -i -E "s/$from/\1$version\2/" "$file" + echo "$file $version" +else + echo "$version" +fi diff --git a/web/css/main.css b/web/css/main.css index 14a886ad..d0b2058f 100644 --- a/web/css/main.css +++ b/web/css/main.css @@ -780,3 +780,8 @@ input:checked + .dpad-toggle-slider:before { -ms-transform: translateX(15px); transform: translateX(15px); } + +#version { + color: #dddddd; + text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; +} diff --git a/web/index.html b/web/index.html index 2f6d306c..fbd2722a 100644 --- a/web/index.html +++ b/web/index.html @@ -109,6 +109,10 @@ src="https://github.blog/wp-content/uploads/2008/12/forkme_right_gray_6d6d6d.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"> +
+ +
+