Merge pull request #55 from roman-khimov/deduplicate-bin-build

Deduplicate binary builds
This commit is contained in:
Roman Khimov 2021-05-20 22:11:22 +03:00 committed by GitHub
commit 43864fdd86
13 changed files with 39 additions and 58 deletions

View file

@ -5,36 +5,25 @@ REPO ?= $(shell go list -m)
VERSION ?= "$(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD | sed 's/^v//')" VERSION ?= "$(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD | sed 's/^v//')"
BINDIR = bin BINDIR = bin
# s3 gw variables # Binaries to build
BIN_NAME=neofs-s3-gw CMDS = $(addprefix neofs-, $(notdir $(wildcard cmd/*)))
BIN = "$(BINDIR)/$(BIN_NAME)" BINS = $(addprefix $(BINDIR)/, $(CMDS))
# Variables for docker # Variables for docker
HUB_IMAGE ?= "nspccdev/$(BIN_NAME)" HUB_IMAGE ?= "nspccdev/$(BIN_NAME)"
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')" HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
# Authmate variables
AUTHMATE_BIN_NAME=neofs-authmate
AUTHMATE_BIN = "$(BINDIR)/$(AUTHMATE_BIN_NAME)"
.PHONY: help all dep clean format test cover lint docker/lint image-push image dirty-image .PHONY: help all dep clean format test cover lint docker/lint image-push image dirty-image
# Make all binaries # Make all binaries
all: $(BIN) $(AUTHMATE_BIN) all: $(BINS)
$(BIN): $(BINDIR) dep $(BINS): $(BINDIR) dep
@echo "⇒ Build $@" @echo "⇒ Build $@"
CGO_ENABLED=0 \ CGO_ENABLED=0 \
go build -v -trimpath \ go build -v -trimpath \
-ldflags "-X main.Version=$(VERSION)" \ -ldflags "-X $(REPO)/internal/version.Version=$(VERSION)" \
-o $@ ./cmd/gate -o $@ ./cmd/$(subst neofs-,,$(notdir $@))
$(AUTHMATE_BIN): $(BINDIR) dep
@echo "⇒ Build $@"
CGO_ENABLED=0 \
go build -v -trimpath \
-ldflags "-X main.Version=$(VERSION)" \
-o $@ ./cmd/authmate
$(BINDIR): $(BINDIR):
@echo "⇒ Ensure dir: $@" @echo "⇒ Ensure dir: $@"

View file

@ -1,7 +1,7 @@
package metrics package metrics
import ( import (
"github.com/nspcc-dev/neofs-s3-gw/misc" "github.com/nspcc-dev/neofs-s3-gw/internal/version"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
@ -19,8 +19,6 @@ var (
[]string{ []string{
// current version // current version
"version", "version",
// build time of the current version
"build_time",
}, },
) )
@ -62,7 +60,7 @@ func (s *stats) Describe(ch chan<- *prometheus.Desc) {
func (s *stats) Collect(ch chan<- prometheus.Metric) { func (s *stats) Collect(ch chan<- prometheus.Metric) {
// Expose current version information // Expose current version information
versionInfo.WithLabelValues(misc.Version, misc.Build).Set(1.0) versionInfo.WithLabelValues(version.Version).Set(1.0)
// connect collectors // connect collectors
collectHTTPMetrics(ch) collectHTTPMetrics(ch)

View file

@ -10,7 +10,7 @@ import (
"strconv" "strconv"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/nspcc-dev/neofs-s3-gw/misc" "github.com/nspcc-dev/neofs-s3-gw/internal/version"
) )
type ( type (
@ -153,7 +153,7 @@ func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
// Write http common headers. // Write http common headers.
func setCommonHeaders(w http.ResponseWriter) { func setCommonHeaders(w http.ResponseWriter) {
w.Header().Set(hdrServerInfo, "NeoFS-S3-GW/"+misc.Version) w.Header().Set(hdrServerInfo, version.Server)
w.Header().Set(hdrAcceptRanges, "bytes") w.Header().Set(hdrAcceptRanges, "bytes")
// Remove sensitive information // Remove sensitive information

View file

@ -15,6 +15,7 @@ import (
"github.com/nspcc-dev/cdn-sdk/pool" "github.com/nspcc-dev/cdn-sdk/pool"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-s3-gw/authmate" "github.com/nspcc-dev/neofs-s3-gw/authmate"
"github.com/nspcc-dev/neofs-s3-gw/internal/version"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -30,11 +31,6 @@ const (
poolRequestTimeout = 5 * time.Second poolRequestTimeout = 5 * time.Second
) )
var (
// Version of the program.
Version = "dev"
)
var ( var (
neoFSKeyPathFlag string neoFSKeyPathFlag string
peerAddressFlag string peerAddressFlag string
@ -89,7 +85,7 @@ func main() {
app := &cli.App{ app := &cli.App{
Name: "NeoFS gate authentication manager", Name: "NeoFS gate authentication manager",
Usage: "Helps manage delegated access via gates to data stored in NeoFS network", Usage: "Helps manage delegated access via gates to data stored in NeoFS network",
Version: Version, Version: version.Version,
Flags: appFlags(), Flags: appFlags(),
Commands: appCommands(), Commands: appCommands(),
} }

View file

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/nspcc-dev/neofs-s3-gw/misc" "github.com/nspcc-dev/neofs-s3-gw/internal/version"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/zap" "go.uber.org/zap"
@ -87,6 +87,12 @@ const ( // Settings.
// Command line args. // Command line args.
cmdHelp = "help" cmdHelp = "help"
cmdVersion = "version" cmdVersion = "version"
// applicationName is gateway name.
applicationName = "neofs-s3-gw"
// envPrefix is environment variables prefix used for configuration.
envPrefix = "S3_GW"
) )
type empty int type empty int
@ -145,7 +151,7 @@ func newSettings() *viper.Viper {
v := viper.New() v := viper.New()
v.AutomaticEnv() v.AutomaticEnv()
v.SetEnvPrefix(misc.Prefix) v.SetEnvPrefix(envPrefix)
v.SetConfigType("yaml") v.SetConfigType("yaml")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
@ -158,7 +164,7 @@ func newSettings() *viper.Viper {
flags.Bool(cfgEnableMetrics, false, "enable prometheus metrics") flags.Bool(cfgEnableMetrics, false, "enable prometheus metrics")
help := flags.BoolP(cmdHelp, "h", false, "show help") help := flags.BoolP(cmdHelp, "h", false, "show help")
version := flags.BoolP(cmdVersion, "v", false, "show version") versionFlag := flags.BoolP(cmdVersion, "v", false, "show version")
flags.String(cfgNeoFSPrivateKey, "", "set value to hex string, WIF string, or path to NeoFS private key file") flags.String(cfgNeoFSPrivateKey, "", "set value to hex string, WIF string, or path to NeoFS private key file")
flags.String(cfgGateAuthPrivateKey, "", "set path to file with auth (curve25519) private key to use in auth scheme") flags.String(cfgGateAuthPrivateKey, "", "set path to file with auth (curve25519) private key to use in auth scheme")
@ -179,9 +185,8 @@ func newSettings() *viper.Viper {
domains := flags.StringArrayP(cfgListenDomains, "d", nil, "set domains to be listened") domains := flags.StringArrayP(cfgListenDomains, "d", nil, "set domains to be listened")
// set prefers: // set prefers:
v.Set(cfgApplicationName, misc.ApplicationName) v.Set(cfgApplicationName, applicationName)
v.Set(cfgApplicationVersion, misc.Version) v.Set(cfgApplicationVersion, version.Version)
v.Set(cfgApplicationBuildTime, misc.Build)
// set defaults: // set defaults:
@ -229,7 +234,7 @@ func newSettings() *viper.Viper {
switch { switch {
case help != nil && *help: case help != nil && *help:
fmt.Printf("NeoFS S3 Gateway %s (%s)\n", misc.Version, misc.Build) fmt.Printf("NeoFS S3 gateway %s\n", version.Version)
flags.PrintDefaults() flags.PrintDefaults()
fmt.Println() fmt.Println()
@ -244,19 +249,19 @@ func newSettings() *viper.Viper {
} }
k := strings.Replace(keys[i], ".", "_", -1) k := strings.Replace(keys[i], ".", "_", -1)
fmt.Printf("%s_%s = %v\n", misc.Prefix, strings.ToUpper(k), v.Get(keys[i])) fmt.Printf("%s_%s = %v\n", envPrefix, strings.ToUpper(k), v.Get(keys[i]))
} }
fmt.Println() fmt.Println()
fmt.Println("Peers preset:") fmt.Println("Peers preset:")
fmt.Println() fmt.Println()
fmt.Printf("%s_%s_[N]_ADDRESS = string\n", misc.Prefix, strings.ToUpper(cfgPeers)) fmt.Printf("%s_%s_[N]_ADDRESS = string\n", envPrefix, strings.ToUpper(cfgPeers))
fmt.Printf("%s_%s_[N]_WEIGHT = 0..1 (float)\n", misc.Prefix, strings.ToUpper(cfgPeers)) fmt.Printf("%s_%s_[N]_WEIGHT = 0..1 (float)\n", envPrefix, strings.ToUpper(cfgPeers))
os.Exit(0) os.Exit(0)
case version != nil && *version: case versionFlag != nil && *versionFlag:
fmt.Printf("NeoFS S3 Gateway %s (%s)\n", misc.Version, misc.Build) fmt.Printf("NeoFS S3 gateway %s\n", version.Version)
os.Exit(0) os.Exit(0)
case ttl != nil && ttl.Minutes() < minimumTTLInMinutes: case ttl != nil && ttl.Minutes() < minimumTTLInMinutes:
fmt.Printf("connection ttl should not be less than %s", defaultTTL) fmt.Printf("connection ttl should not be less than %s", defaultTTL)

View file

@ -0,0 +1,9 @@
package version
var (
// Version contains application version.
Version = "dev"
// Server contains server identification string.
Server = "NeoFS-S3-GW/" + Version
)

View file

@ -1,16 +0,0 @@
package misc
const (
// ApplicationName is gateway name.
ApplicationName = "neofs-s3-gw"
// Prefix is configuration environment variables prefix.
Prefix = "S3_GW"
)
var (
// Build holds build timestamp.
Build = "now"
// Version contains application version.
Version = "dev"
)