put version in binary properly (#73)
Addresses #71 : Set version on the CLI framework. Add a build.sh script that injects variables into the build tooling using git and a version file. Set version in config.
This commit is contained in:
parent
87cf621e21
commit
4f3b3f5c0b
@ -30,7 +30,7 @@ To get started, you first need to have Go installed. GTS was developed with Go 1
|
||||
|
||||
Once you've got go installed, clone this repository into your Go path. Normally, this should be `~/go/src/github.com/superseriousbusiness/gotosocial`.
|
||||
|
||||
Once that's done, you can try building the project: `go build ./cmd/gotosocial`. This will build the `gotosocial` binary.
|
||||
Once that's done, you can try building the project: `./build.sh`. This will build the `gotosocial` binary.
|
||||
|
||||
If there are no errors, great, you're good to go!
|
||||
|
||||
|
11
Dockerfile
11
Dockerfile
@ -1,4 +1,6 @@
|
||||
FROM golang:1.16.4-alpine3.13 AS builder
|
||||
RUN apk update && apk upgrade --no-cache
|
||||
RUN apk add git
|
||||
|
||||
# create build dir
|
||||
RUN mkdir -p /go/src/github.com/superseriousbusiness/gotosocial
|
||||
@ -11,8 +13,15 @@ ADD testrig /go/src/github.com/superseriousbusiness/gotosocial/testrig
|
||||
ADD go.mod /go/src/github.com/superseriousbusiness/gotosocial/go.mod
|
||||
ADD go.sum /go/src/github.com/superseriousbusiness/gotosocial/go.sum
|
||||
|
||||
# move .git dir and version for versioning
|
||||
ADD .git /go/src/github.com/superseriousbusiness/gotosocial/.git
|
||||
ADD version /go/src/github.com/superseriousbusiness/gotosocial/version
|
||||
|
||||
# move the build script
|
||||
ADD build.sh /go/src/github.com/superseriousbusiness/gotosocial/build.sh
|
||||
|
||||
# do the build step
|
||||
RUN go build ./cmd/gotosocial
|
||||
RUN ./build.sh
|
||||
|
||||
FROM alpine:3.13 AS executor
|
||||
RUN apk update && apk upgrade --no-cache
|
||||
|
@ -30,7 +30,11 @@ docker run -d --network host --user postgres -e POSTGRES_PASSWORD=some_password
|
||||
|
||||
### 5: Build the Binary
|
||||
|
||||
On your local machine (not your server), with Go installed, clone the GoToSocial repository, and build the binary with `go build ./cmd/gotosocial`.
|
||||
On your local machine (not your server), with Go installed, clone the GoToSocial repository, and build the binary with the provided build script:
|
||||
|
||||
```bash
|
||||
./build/sh
|
||||
```
|
||||
|
||||
### 6: Prepare VPS
|
||||
|
||||
|
8
build.sh
Executable file
8
build.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
export COMMIT=$(git rev-list -1 HEAD)
|
||||
export VERSION=$(cat ./version)
|
||||
|
||||
go build -ldflags="-X 'main.Commit=$COMMIT' -X 'main.Version=$VERSION'" ./cmd/gotosocial
|
@ -33,12 +33,19 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version is the software version of GtS being used
|
||||
var Version string
|
||||
|
||||
// Commit is the git commit of GtS being used
|
||||
var Commit string
|
||||
|
||||
func main() {
|
||||
flagNames := config.GetFlagNames()
|
||||
envNames := config.GetEnvNames()
|
||||
defaults := config.GetDefaults()
|
||||
app := &cli.App{
|
||||
Usage: "a fediverse social media server",
|
||||
Version: Version + " " + Commit[:7],
|
||||
Usage: "a fediverse social media server",
|
||||
Flags: []cli.Flag{
|
||||
// GENERAL FLAGS
|
||||
&cli.StringFlag{
|
||||
@ -399,7 +406,7 @@ func runAction(c *cli.Context, a cliactions.GTSAction) error {
|
||||
return fmt.Errorf("error creating config: %s", err)
|
||||
}
|
||||
// ... and the flags set on the *cli.Context by urfave
|
||||
if err := conf.ParseCLIFlags(c); err != nil {
|
||||
if err := conf.ParseCLIFlags(c, c.App.Version); err != nil {
|
||||
return fmt.Errorf("error parsing config: %s", err)
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ func loadFromFile(path string) (*Config, error) {
|
||||
}
|
||||
|
||||
// ParseCLIFlags sets flags on the config using the provided Flags object
|
||||
func (c *Config) ParseCLIFlags(f KeyedFlags) error {
|
||||
func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
|
||||
fn := GetFlagNames()
|
||||
|
||||
// For all of these flags, we only want to set them on the config if:
|
||||
@ -261,6 +261,8 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) error {
|
||||
c.AccountCLIFlags[EmailFlag] = f.String(EmailFlag)
|
||||
c.AccountCLIFlags[PasswordFlag] = f.String(PasswordFlag)
|
||||
|
||||
c.SoftwareVersion = version
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package config
|
||||
|
||||
const softwareVersion = "0.1.0-SNAPSHOT"
|
||||
|
||||
// TestDefault returns a default config for testing
|
||||
func TestDefault() *Config {
|
||||
defaults := GetTestDefaults()
|
||||
@ -121,7 +119,6 @@ func GetDefaults() Defaults {
|
||||
ConfigPath: "",
|
||||
Host: "",
|
||||
Protocol: "https",
|
||||
SoftwareVersion: softwareVersion,
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
@ -168,7 +165,6 @@ func GetTestDefaults() Defaults {
|
||||
ConfigPath: "",
|
||||
Host: "localhost:8080",
|
||||
Protocol: "http",
|
||||
SoftwareVersion: softwareVersion,
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!-- footer.tmpl -->
|
||||
<footer>
|
||||
<div id="version">
|
||||
Running GoToSocial version: <span class="accent">{{.instance.Version}}</span><br>
|
||||
GoToSocial: <span class="accent">{{.instance.Version}}</span><br>
|
||||
<a href="https://github.com/superseriousbusiness/gotosocial">Source Code</a>
|
||||
</div>
|
||||
<div id="contact">
|
||||
|
Loading…
Reference in New Issue
Block a user