forked from TrueCloudLab/distribution
Merge pull request #120 from stevvooe/add-version-reporting
Add version reporting to registry binary
This commit is contained in:
commit
fce5115336
8 changed files with 96 additions and 12 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -22,3 +22,6 @@ _testmain.go
|
|||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
# never checkin from the bin file (for now)
|
||||
bin/*
|
||||
|
|
1
AUTHORS
1
AUTHORS
|
@ -6,3 +6,4 @@ Brian Bland <brian.bland@docker.com>
|
|||
Josh Hawn <josh.hawn@docker.com>
|
||||
Olivier Gambier <olivier@docker.com>
|
||||
Stephen J Day <stephen.day@docker.com>
|
||||
Tianon Gravi <admwiggin@gmail.com>
|
||||
|
|
10
Dockerfile
10
Dockerfile
|
@ -1,15 +1,13 @@
|
|||
FROM golang:1.4
|
||||
|
||||
ENV CONFIG_PATH /etc/docker/registry/config.yml
|
||||
RUN mkdir -pv "$(dirname $CONFIG_PATH)"
|
||||
|
||||
ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution
|
||||
ENV GOPATH $DISTRIBUTION_DIR/Godeps/_workspace:$GOPATH
|
||||
|
||||
WORKDIR $DISTRIBUTION_DIR
|
||||
COPY . $DISTRIBUTION_DIR
|
||||
ENV GOPATH $GOPATH:$DISTRIBUTION_DIR/Godeps/_workspace
|
||||
|
||||
RUN go install -v ./cmd/registry
|
||||
|
||||
RUN make PREFIX=/go clean binaries
|
||||
RUN mkdir -pv "$(dirname $CONFIG_PATH)"
|
||||
RUN cp -lv ./cmd/registry/config.yml $CONFIG_PATH
|
||||
|
||||
EXPOSE 5000
|
||||
|
|
23
Makefile
23
Makefile
|
@ -1,15 +1,26 @@
|
|||
# This project makefile is around for generating peices of documentation and
|
||||
# code. For most purposes, running it is not necessary.
|
||||
# Set an output prefix, which is the local directory if not specified
|
||||
PREFIX?=$(shell pwd)
|
||||
|
||||
.PHONY: clean
|
||||
# Used to populate version variable in main package.
|
||||
GO_LDFLAGS=-ldflags "-X `go list ./version`.Version `git describe --match 'v[0-9]*' --dirty='.m' --always`"
|
||||
|
||||
.PHONY: clean binaries
|
||||
.DEFAULT: default
|
||||
|
||||
default:
|
||||
@echo Please read the make targets before using this Makefile. It is \
|
||||
currently only used for documentation and autogenerated files.
|
||||
@echo Please read the make targets before using this Makefile.
|
||||
|
||||
AUTHORS: .mailmap .git/ORIG_HEAD .git/FETCH_HEAD .git/HEAD
|
||||
git log --format='%aN <%aE>' | sort -fu >> $@
|
||||
|
||||
# This only needs to be generated by hand when cutting full releases.
|
||||
version/version.go:
|
||||
./version/version.sh > $@
|
||||
|
||||
${PREFIX}/bin/registry: version/version.go $(shell find . -type f -name '*.go')
|
||||
go build -o $@ ${GO_LDFLAGS} ./cmd/registry
|
||||
|
||||
binaries: ${PREFIX}/bin/registry
|
||||
|
||||
clean:
|
||||
rm -rf AUTHORS
|
||||
rm -rf "${PREFIX}/bin/registry"
|
||||
|
|
|
@ -19,12 +19,24 @@ import (
|
|||
_ "github.com/docker/distribution/storagedriver/filesystem"
|
||||
_ "github.com/docker/distribution/storagedriver/inmemory"
|
||||
_ "github.com/docker/distribution/storagedriver/s3"
|
||||
"github.com/docker/distribution/version"
|
||||
)
|
||||
|
||||
var showVersion bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&showVersion, "version", false, "show the version and exit")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
if showVersion {
|
||||
version.PrintVersion()
|
||||
return
|
||||
}
|
||||
|
||||
config, err := resolveConfiguration()
|
||||
if err != nil {
|
||||
fatalf("configuration error: %v", err)
|
||||
|
|
26
version/print.go
Normal file
26
version/print.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// FprintVersion outputs the version string to the writer, in the following
|
||||
// format, followed by a newline:
|
||||
//
|
||||
// <cmd> <project> <version>
|
||||
//
|
||||
// For example, a binary "registry" built from github.com/docker/distribution
|
||||
// with version "v2.0" would print the following:
|
||||
//
|
||||
// registry github.com/docker/distribution v2.0
|
||||
//
|
||||
func FprintVersion(w io.Writer) {
|
||||
fmt.Fprintln(w, os.Args[0], Package, Version)
|
||||
}
|
||||
|
||||
// PrintVersion outputs the version information, from Fprint, to stdout.
|
||||
func PrintVersion() {
|
||||
FprintVersion(os.Stdout)
|
||||
}
|
11
version/version.go
Normal file
11
version/version.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package version
|
||||
|
||||
// Package is the overall, canonical project import path under which the
|
||||
// package was built.
|
||||
var Package = "github.com/docker/distribution"
|
||||
|
||||
// Version indicates which version of the binary is running. This is set to
|
||||
// the latest release tag by hand, always suffixed by "+unknown". During
|
||||
// build, it will be replaced by the actual version. The value here will be
|
||||
// used if the registry is run after a go get based install.
|
||||
var Version = "v2.0.0-alpha.1+unknown"
|
22
version/version.sh
Executable file
22
version/version.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This bash script outputs the current, desired content of version.go, using
|
||||
# git describe. For best effect, pipe this to the target file. Generally, this
|
||||
# only needs to updated for releases. The actual value of will be replaced
|
||||
# during build time if the makefile is used.
|
||||
|
||||
set -e
|
||||
|
||||
cat <<EOF
|
||||
package version
|
||||
|
||||
// Package is the overall, canonical project import path under which the
|
||||
// package was built.
|
||||
var Package = "$(go list)"
|
||||
|
||||
// Version indicates which version of the binary is running. This is set to
|
||||
// the latest release tag by hand, always suffixed by "+unknown". During
|
||||
// build, it will be replaced by the actual version. The value here will be
|
||||
// used if the registry is run after a go get based install.
|
||||
var Version = "$(git describe --match 'v[0-9]*' --dirty='.m' --always)+unknown"
|
||||
EOF
|
Loading…
Reference in a new issue