Add extra build info (#1115)

cc @xuu

```
[07:44:27]  <prologic> xuu how's this?
[07:44:28]  <prologic> 0.15.1-86-geac11004-1673646222
[07:44:41]  <prologic> https://files.mills.io/download/Screenshot%202023-01-14%20at%2007.44.19.png
[07:45:00]  <prologic> Format is: <version>-<commits>-<sha>-<timestamp>
[07:45:13]  <prologic> where commits are no. of commits ahead of last release
[07:45:22]  <prologic> timestamp is a unix epic (UTC)
```

Co-authored-by: James Mills <1290234+prologic@users.noreply.github.com>
Reviewed-on: #1115
pull/1116/head^2
James Mills 2 weeks ago
parent eac1100425
commit 84e7db965b
  1. 3
      Dockerfile
  2. 15
      Makefile
  3. 38
      doc.go
  4. 9
      internal/cache.go
  5. 2
      internal/config.go
  6. 9
      internal/handlers.go
  7. 18
      internal/theme/templates/info.html
  8. 45
      version.go

@ -48,9 +48,10 @@ COPY ./cmd/yarnd/*.go ./cmd/yarnd/
# COMMIT value to change.
ARG VERSION="0.0.0"
ARG COMMIT="HEAD"
ARG BUILD=""
# Build server binary
RUN make server VERSION=$VERSION COMMIT=$COMMIT
RUN make server VERSION=$VERSION COMMIT=$COMMIT BUILD=$BUILD
# Runtime
FROM alpine:latest

@ -5,6 +5,7 @@ export CGO_ENABLED=0
VERSION=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION")
COMMIT=$(shell git rev-parse --short HEAD || echo "$COMMIT")
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
BUILD=$(shell git show -s --pretty=format:%cI)
GOCMD=go
DESTDIR=/usr/local/bin
@ -36,14 +37,16 @@ cli:
@$(GOCMD) build -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w \
-X $(shell go list).Version=$(VERSION) \
-X $(shell go list).Commit=$(COMMIT)" \
-X $(shell go list).Commit=$(COMMIT) \
-X $(shell go list).Build=$(BUILD)" \
./cmd/yarnc/
server: generate
@$(GOCMD) build $(FLAGS) -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w \
-X $(shell go list).Version=$(VERSION) \
-X $(shell go list).Commit=$(COMMIT)" \
-X $(shell go list).Commit=$(COMMIT) \
-X $(shell go list).Build=$(BUILD)" \
./cmd/yarnd/...
build: cli server
@ -63,12 +66,16 @@ install: build
ifeq ($(PUBLISH), 1)
image: generate
@docker buildx build \
--build-arg VERSION="$(VERSION)" --build-arg COMMIT="$(COMMIT)" \
--build-arg VERSION="$(VERSION)" \
--build-arg COMMIT="$(COMMIT)" \
--build-arg BUILD="$(BUILD)" \
--platform linux/amd64,linux/arm64 --push -t $(IMAGE):$(TAG) .
else
image: generate
@docker build \
--build-arg VERSION="$(VERSION)" --build-arg COMMIT="$(COMMIT)" \
--build-arg VERSION="$(VERSION)" \
--build-arg COMMIT="$(COMMIT)" \
--build-arg BUILD="$(BUILD)" \
-t $(IMAGE):$(TAG) .
endif

@ -1,21 +1,19 @@
// Package yarn is a Self-Hosted, Twitter™-like Decentralised microBlogging platform.
//
// # Copyright (C) 2020-present Yarn.social
//
// yarn is covered by the AGPLv3 license:
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package yarn
/* yarn is a Self-Hosted, Twitter-like Decentralised microBlogging platform.
Copyright (C) 2020-present Yarn.social
yarn is covered by the AGPLv3 license:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

@ -381,10 +381,11 @@ func (cached *Cached) SetLastFetched() {
type Pod struct {
URI string `json:"-"`
Name string `json:"name"`
Logo string `json:"logo"`
Description string `json:"description"`
SoftwareVersion string `json:"software_version"`
Name string `json:"name"`
Logo string `json:"logo"`
Description string `json:"description"`
SoftwareVersion string `json:"software_version"`
BuildInformation string `json:"build_info"`
// Maybe we store future data about other peer pods in the future?
// Right now the above is basically what is exposed now as the pod's name, description and what version of yarnd is running.

@ -34,6 +34,7 @@ func init() {
FullVersion: yarn.FullVersion(),
Version: yarn.Version,
Commit: yarn.Commit,
Build: yarn.Build,
}
}
@ -92,6 +93,7 @@ type SoftwareConfig struct {
FullVersion string
Version string
Commit string
Build string
Author string
License string

@ -484,10 +484,11 @@ func (s *Server) PodInfoHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
if r.Header.Get("Accept") == "application/json" {
data, err := json.Marshal(Pod{
Name: s.config.Name,
Logo: s.config.baseURL.JoinPath("/logo").String(),
Description: s.config.Description,
SoftwareVersion: s.config.Version.FullVersion,
Name: s.config.Name,
Logo: s.config.baseURL.JoinPath("/logo").String(),
Description: s.config.Description,
SoftwareVersion: s.config.Version.FullVersion,
BuildInformation: s.config.Version.Build,
})
if err != nil {
log.WithError(err).Error("error serializing pod version response")

@ -5,14 +5,16 @@
<em>{{ tr . "InstanceNameInfo" (dict "InstanceName" $.InstanceName) | html }}</em>
</hgroup>
<div id="versionInfo">
<span title="PodName">{{ .InstanceName }}</span>
<span title="Software">{{ .SoftwareVersion.Software }}</span>
<span title="FullVersion">{{ .SoftwareVersion.FullVersion }}</span>
<span title="Version">{{ .SoftwareVersion.Version }}</span>
<span title="Commit">{{ .SoftwareVersion.Commit }}</span>
<span title="Author">{{ .SoftwareVersion.Author }}</span>
<span title="License">{{ .SoftwareVersion.License }}</span>
<span title="Copyright">{{ .SoftwareVersion.Copyright }}</span>
<table>
<tr><th>PodName</th><td>{{ .InstanceName }}</td></tr>
<tr><th>Software</th><td>{{ .SoftwareVersion.Software }}</td></tr>
<tr><th>FullVersion</th><td>{{ .SoftwareVersion.FullVersion }}</td></tr>
<tr><th>Version</th><td>{{ .SoftwareVersion.Version }}</td></tr>
<tr><th>Commit</th><td>{{ .SoftwareVersion.Commit }} {{ .SoftwareVersion.Build }}</td></tr>
<tr><th>Author</th><td>{{ .SoftwareVersion.Author }}</td></tr>
<tr><th>License</th><td>{{ .SoftwareVersion.License }}</td></tr>
<tr><th>Copyright</th><td>{{ .SoftwareVersion.Copyright }}</td></tr>
</table>
</div>
</article>
{{ end }}

@ -1,21 +1,50 @@
// Copyright 2020-present Yarn.social
// SPDX-License-Identifier: AGPL-3.0-or-later
package yarn
import (
"fmt"
"runtime/debug"
"strings"
)
const (
defaultVersion = "0.0.0"
defaultCommit = "HEAD"
defaultBuild = "0000-01-01:00:00+00:00"
)
var (
// Version release version
Version = "0.0.2"
// Version is the tagged release version in the form <major>.<minor>.<patch>
// following semantic versioning and is overwritten by the build system.
Version = defaultVersion
// Commit is the commit sha of the build (normally from Git) and is overwritten
// by the build system.
Commit = defaultCommit
// Commit will be overwritten automatically by the build system
Commit = "HEAD"
// Build is the date and time of the build as an RFC3339 formatted string
// and is overwritten by the build system.
Build = defaultBuild
)
// FullVersion display the full version and build
func FullVersion() string {
return fmt.Sprintf("%s@%s", Version, Commit)
var sb strings.Builder
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
if !isDefault {
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
}
if info, ok := debug.ReadBuildInfo(); ok {
if isDefault {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
}
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
if info.Main.Sum != "" {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
}
}
return sb.String()
}

Loading…
Cancel
Save