From 828e6a77aa6aa035f67a5889549f5eba22270aac Mon Sep 17 00:00:00 2001 From: Ev Kontsevoy Date: Tue, 14 Jun 2016 16:52:32 -0700 Subject: [PATCH] Simpler version implementation --- .gitignore | 2 + Godeps/Godeps.json | 4 - Makefile | 82 +++--- README.md | 13 +- lib/utils/utils.go | 11 +- .../github.com/gravitational/version/LICENSE | 202 --------------- .../gravitational/version/README.md | 72 ------ .../github.com/gravitational/version/base.go | 29 --- .../version/cmd/linkflags/main.go | 233 ------------------ .../github.com/gravitational/version/doc.go | 17 -- .../gravitational/version/pkg/tool/tool.go | 65 ----- .../gravitational/version/test/main.go | 13 - .../gravitational/version/version.go | 51 ---- version.go | 9 + version.mk | 32 ++- 15 files changed, 98 insertions(+), 737 deletions(-) delete mode 100644 vendor/github.com/gravitational/version/LICENSE delete mode 100644 vendor/github.com/gravitational/version/README.md delete mode 100644 vendor/github.com/gravitational/version/base.go delete mode 100644 vendor/github.com/gravitational/version/cmd/linkflags/main.go delete mode 100644 vendor/github.com/gravitational/version/doc.go delete mode 100644 vendor/github.com/gravitational/version/pkg/tool/tool.go delete mode 100644 vendor/github.com/gravitational/version/test/main.go delete mode 100644 vendor/github.com/gravitational/version/version.go create mode 100644 version.go diff --git a/.gitignore b/.gitignore index 91188a26c2f21..e44b98a3b6a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +gitref.go + # built web assets web/dist/app/app diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index f618531e05c6d..2b8c21ae1ceb0 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -144,10 +144,6 @@ "ImportPath": "github.com/gravitational/ttlmap", "Rev": "348cf76cace4d93fdacc38dfdaa2306f4f0e9c16" }, - { - "ImportPath": "github.com/gravitational/version", - "Rev": "4459539f89995fd4b12618a2cd29604948d890a2" - }, { "ImportPath": "github.com/jonboulle/clockwork", "Rev": "ed104f61ea4877bea08af6f759805674861e968d" diff --git a/Makefile b/Makefile index 3bead7e7b8c38..e0368f771d720 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +# Update these two variables, then run 'make setver' +VERSION=1.0.0 +SUFFIX=stable +GITTAG=v$(VERSION)-$(SUFFIX) + # These are standard autotools variables, don't change them please BUILDDIR ?= build BINDIR ?= /usr/local/bin @@ -5,11 +10,13 @@ DATADIR ?= /usr/local/share/teleport ADDFLAGS ?= GO15VENDOREXPERIMENT := 1 -PKGPATH=github.com/gravitational/teleport PWD ?= $(shell pwd) ETCD_CERTS := $(realpath fixtures/certs) ETCD_FLAGS := TELEPORT_TEST_ETCD_CONFIG='{"nodes": ["https://localhost:4001"], "key":"/teleport/test", "tls_key_file": "$(ETCD_CERTS)/proxy1-key.pem", "tls_cert_file": "$(ETCD_CERTS)/proxy1.pem", "tls_ca_file": "$(ETCD_CERTS)/ca.pem"}' TELEPORT_DEBUG ?= no +RELEASE := teleport-$(GITTAG)-$(shell go env GOOS)-$(shell go env GOARCH)-bin +RELEASEDIR := $(BUILDDIR)/$(RELEASE) + export $(eval BUILDFLAGS := $(ADDFLAGS) -ldflags -w) @@ -18,41 +25,43 @@ $(eval BUILDFLAGS := $(ADDFLAGS) -ldflags -w) # Default target: builds all 3 executables and plaaces them in a current directory # .PHONY: all -all: build - -.PHONY: build -build: teleport tctl tsh assets +all: setver teleport tctl tsh assets .PHONY: tctl tctl: - go build -o $(BUILDDIR)/tctl -i $(BUILDFLAGS) $(PKGPATH)/tool/tctl + go build -o $(BUILDDIR)/tctl -i $(BUILDFLAGS) ./tool/tctl .PHONY: teleport teleport: - go build -o $(BUILDDIR)/teleport -i $(BUILDFLAGS) $(PKGPATH)/tool/teleport + go build -o $(BUILDDIR)/teleport -i $(BUILDFLAGS) ./tool/teleport .PHONY: tsh tsh: - go build -o $(BUILDDIR)/tsh -i $(BUILDFLAGS) $(PKGPATH)/tool/tsh + go build -o $(BUILDDIR)/tsh -i $(BUILDFLAGS) ./tool/tsh +# +# make install will installs system-wide teleport +# .PHONY: install install: build - sudo cp -f $(BUILDDIR)/tctl $(BINDIR)/ - sudo cp -f $(BUILDDIR)/tsh $(BINDIR)/ - sudo cp -f $(BUILDDIR)/teleport $(BINDIR)/ - sudo mkdir -p $(DATADIR) - sudo cp -fr web/dist/* $(DATADIR) + @echo "\n** Make sure to run 'make install' as root! **\n" + cp -f $(BUILDDIR)/tctl $(BINDIR)/ + cp -f $(BUILDDIR)/tsh $(BINDIR)/ + cp -f $(BUILDDIR)/teleport $(BINDIR)/ + mkdir -p $(DATADIR) + cp -fr web/dist/* $(DATADIR) .PHONY: goinstall goinstall: - go install $(BUILDFLAGS) $(PKGPATH)/tool/tctl - go install $(BUILDFLAGS) $(PKGPATH)/tool/teleport - go install $(BUILDFLAGS) $(PKGPATH)/tool/tsh + go install $(BUILDFLAGS) ./tool/tctl + go install $(BUILDFLAGS) ./tool/teleport + go install $(BUILDFLAGS) ./tool/tsh .PHONY: clean clean: rm -rf $(BUILDDIR) + rm -rf teleport .PHONY: assets assets: @@ -83,9 +92,9 @@ run-docs: .PHONY: test test: FLAGS ?= -cover test: - go test -v $(PKGPATH)/tool/tsh/... \ - $(PKGPATH)/lib/... \ - $(PKGPATH)/tool/teleport... $(FLAGS) -tags test + go test -v ./tool/tsh/... \ + ./lib/... \ + ./tool/teleport... $(FLAGS) -tags test go vet ./tool/... ./lib/... # @@ -93,28 +102,33 @@ test: # .PHONY: integration integration: - go test -v $(PKGPATH)/integration/... + go test -v ./integration/... -.PHONY: foo -foo: - $(MAKE) -f version.mk +# make setver - bump the version of teleport +# Reads the version from version.mk, updates version.go and +# assigns a git tag to the currently checked out tree +.PHONY: setver +setver: + $(MAKE) -f version.mk setver +# make settag - set a git tag with the current version from version.mk +.PHONY: settag +settag: + echo $(GITTAG) # # bianry-release releases binary distribution tarball for this particular version # -.PHONY: binary-release -binary-release: LINKFLAGS := $(shell linkflags -verpkg=$(PKGPATH)/vendor/github.com/gravitational/version) -binary-release: RELEASE := teleport-$(shell linkflags --os-release)-bin -binary-release: RELEASEDIR := $(BUILDDIR)/$(RELEASE) -binary-release: build - sed 's_%BUILDFLAGS%_-ldflags "$(LINKFLAGS)"_' build.assets/release/Makefile > $(BUILDDIR)/Makefile - mkdir -p $(BUILDDIR)/$(RELEASE)/teleport/src/$(PKGPATH)/web $(BUILDDIR)/$(RELEASE)/teleport/build - cp -r $(BUILDDIR)/Makefile LICENSE README.md docs $(BUILDDIR)/$(RELEASE)/teleport - cp -r web/dist $(BUILDDIR)/$(RELEASE)/teleport/src/$(PKGPATH)/web - cp -af $(BUILDDIR)/tctl $(BUILDDIR)/tsh $(BUILDDIR)/teleport $(BUILDDIR)/$(RELEASE)/teleport/build - tar -czf $(BUILDDIR)/$(RELEASE).tar.gz -C $(BUILDDIR)/$(RELEASE) teleport +.PHONY: release +release: clean all + @rm -rf $(RELEASE) + mkdir $(RELEASE) + cp -r $(BUILDDIR)/* $(RELEASE)/ + tar -czf $(RELEASE).tar.gz $(RELEASE) + @echo "\n\n" + @echo "CREATED: $(RELEASE)" + @echo "CREATED: $(RELEASE).tar.gz" .PHONY: test-with-etcd diff --git a/README.md b/README.md index 95cd3bb2655ac..36ea8aa716662 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,18 @@ Then you can run Teleport as a single-node cluster: teleport start ``` -## Why Build Teleport? +## Building Teleport + +You need to have Golang v1.5 or newer. + +Clone this repository into `$GOPATH/gravitational/teleport` and run `make`. + +If you want to release your own Teleport version, edit this [Makefile](Makefile), update +`VERSION` and `SUFFIX` constants, then run `make setver` to update [version.go](version.go) + +If you want to cut another binary release tarball, run `make release`. + +## Why did We Build Teleport? Mature tech companies with significant infrastructure footprints tend to implement most of these patterns internally. Teleport allows smaller companies without diff --git a/lib/utils/utils.go b/lib/utils/utils.go index 806d1028f42be..a2a77082c2334 100644 --- a/lib/utils/utils.go +++ b/lib/utils/utils.go @@ -26,8 +26,8 @@ import ( "strconv" "strings" + "github.com/gravitational/teleport" "github.com/gravitational/trace" - "github.com/gravitational/version" "github.com/pborman/uuid" "golang.org/x/crypto/ssh" ) @@ -155,12 +155,11 @@ func ReadOrMakeHostUUID(dataDir string) (string, error) { // PrintVersion prints human readable version func PrintVersion() { - ver := version.Get() - if ver.GitCommit != "" { - fmt.Printf("%v git:%v\n", ver.Version, ver.GitCommit) - } else { - fmt.Printf("%v\n", ver.Version) + ver := fmt.Sprintf("Teleport v%s-%s", teleport.Version, teleport.Suffix) + if teleport.Gitref != "" { + ver = fmt.Sprintf("%s git:%s", ver, teleport.Gitref) } + fmt.Println(ver) } const ( diff --git a/vendor/github.com/gravitational/version/LICENSE b/vendor/github.com/gravitational/version/LICENSE deleted file mode 100644 index 8f71f43fee3f7..0000000000000 --- a/vendor/github.com/gravitational/version/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/vendor/github.com/gravitational/version/README.md b/vendor/github.com/gravitational/version/README.md deleted file mode 100644 index f4a7e79bb914a..0000000000000 --- a/vendor/github.com/gravitational/version/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# version - -`version` is a Go library for automatic build versioning. It attempts to simplify the mundane task of adding build version information to any Go package. - -### Usage - -Install the command line utility to generate the linker flags necessary for versioning from the cmd/linkflags: - -```shell -go install github.com/gravitational/version/cmd/linkflags -``` - -Add the following configuration to your build script / Makefile -(assuming a bash script): - -```bash -GO_LDFLAGS=$(linkflags -pkg=path/to/your/package) - -# build with the linker flags: -go build -ldflags="${GO_LDFLAGS}" -``` - -To use, simply import the package and either obtain the version with `Get` or print the JSON-formatted version with `Print`: - -```go -package main - -import "github.com/gravitational/version" - -func main() { - version.Print() -} -``` - -If you have a custom vendoring solution, you might have this package stored under a different path than the default (`go get`). -In this case, you can override the default with a command line option (using [godep] as a vendoring solution): - -```shell -MY_PACKAGE=github.com/my/package -MY_PACKAGE_PATH=$(pwd) -GO_LDFLAGS=$(linkflags -pkg=${MY_PACKAGE_PATH} -verpkg=${MY_PACKAGE}/Godeps/_workspace/src/github.com/gravitational/version) -``` - -The version part of the version information requires that you properly [tag] your packages: - -```shell -$ git tag -v1.0.0-alpha.1 -v1.0.0-beta.1 -``` - -The build versioning scheme is a slight modification of the scheme from the [Kubernetes] project. -It consists of three parts: - - a version string in [semver] format - - git commit ID - - git tree state (`clean` or `dirty`) - -```go -type Info struct { - Version string `json:"version"` - GitCommit string `json:"gitCommit"` - GitTreeState string `json:"gitTreeState"` -} -``` - - -[//]: # (Footnots and references) - -[Kubernetes]: -[semver]: -[godep]: -[tag]: diff --git a/vendor/github.com/gravitational/version/base.go b/vendor/github.com/gravitational/version/base.go deleted file mode 100644 index 2864a02ff949b..0000000000000 --- a/vendor/github.com/gravitational/version/base.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2015 Gravitational, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package version - -// Version value defaults -var ( - // Version string, a slightly modified version of `git describe` to be semver-complaint - version string = "v0.0.0-master+$Format:%h$" - gitCommit string = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD) - gitTreeState string = "not a git tree" // state of git tree, either "clean" or "dirty" -) - -// Init sets an alternative default for the version string. -func Init(baseVersion string) { - version = baseVersion -} diff --git a/vendor/github.com/gravitational/version/cmd/linkflags/main.go b/vendor/github.com/gravitational/version/cmd/linkflags/main.go deleted file mode 100644 index 9d6a6a133b727..0000000000000 --- a/vendor/github.com/gravitational/version/cmd/linkflags/main.go +++ /dev/null @@ -1,233 +0,0 @@ -/* -Copyright 2015 Gravitational, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package main - -import ( - "flag" - "fmt" - "log" - "os" - "path/filepath" - "regexp" - "runtime" - "strconv" - "strings" - - "github.com/gravitational/version" - "github.com/gravitational/version/pkg/tool" -) - -// pkg is the path to the package the tool will create linker flags for. -var pkg = flag.String("pkg", "", "root package path") - -// versionPackage is the path to this version package. -// It is used to access version information attributes during link time. -// This flag is useful when the version package is custom-vendored and has a different package path. -var versionPackage = flag.String("verpkg", "github.com/gravitational/version", "path to the version package") - -var compatMode = flag.Bool("compat", false, "generate linker flags using go1.4 syntax") - -var tagOnly = flag.Bool("tag", false, "print tag only") - -var release = flag.Bool("os-release", false, "print version with OS and architecture e.g. v0.0.1-linux-amd64") - -// semverPattern defines a regexp pattern to modify the results of `git describe` to be semver-complaint. -var semverPattern = regexp.MustCompile(`(.+)-([0-9]{1,})-g([0-9a-f]{14})$`) - -// goVersionPattern defines a regexp pattern to parse versions of the `go tool`. -var goVersionPattern = regexp.MustCompile(`go([1-9])\.(\d+)(?:.\d+)*`) - -func main() { - if err := run(); err != nil { - log.Fatalln(err) - } -} - -func run() error { - log.SetFlags(0) - flag.Parse() - if *pkg == "" { - dir, err := filepath.Abs(filepath.Dir(os.Args[0])) - if err != nil { - return err - } - *pkg = dir - } - - goVersion, err := goToolVersion() - if err != nil { - return fmt.Errorf("failed to determine go tool version: %v\n", err) - } - - info, err := getVersionInfo(*pkg) - if err != nil { - return fmt.Errorf("failed to determine version information: %v\n", err) - } - - // print just tag and return - if *tagOnly { - fmt.Printf(info.Version) - return nil - } - - if *release { - fmt.Printf("%v-%v-%v", info.Version, runtime.GOOS, runtime.GOARCH) - return nil - } - - var linkFlags []string - linkFlag := func(key, value string) string { - if goVersion <= 14 || *compatMode { - return fmt.Sprintf("-X %s.%s %s", *versionPackage, key, value) - } - return fmt.Sprintf("-X %s.%s=%s", *versionPackage, key, value) - } - - // Determine the values of version-related variables as commands to the go linker. - if info.GitCommit != "" { - linkFlags = append(linkFlags, linkFlag("gitCommit", info.GitCommit)) - linkFlags = append(linkFlags, linkFlag("gitTreeState", info.GitTreeState)) - } - if info.Version != "" { - linkFlags = append(linkFlags, linkFlag("version", info.Version)) - } - - fmt.Printf("%s", strings.Join(linkFlags, " ")) - return nil -} - -// getVersionInfo collects the build version information for package pkg. -func getVersionInfo(pkg string) (*version.Info, error) { - git := newGit(pkg) - commitID, err := git.commitID() - if err != nil { - return nil, fmt.Errorf("failed to obtain git commit ID: %v\n", err) - } - treeState, err := git.treeState() - if err != nil { - return nil, fmt.Errorf("failed to determine git tree state: %v\n", err) - } - tag, err := git.tag(commitID) - if err != nil { - tag = "" - } - if tag != "" { - tag = semverify(tag) - if treeState == dirty { - tag = tag + "-" + string(treeState) - } - } - return &version.Info{ - Version: tag, - GitCommit: commitID, - GitTreeState: string(treeState), - }, nil -} - -// goToolVersion determines the version of the `go tool`. -func goToolVersion() (toolVersion, error) { - goTool := &tool.T{Cmd: "go"} - out, err := goTool.Exec("version") - if err != nil { - return toolVersionUnknown, err - } - build := strings.Split(out, " ") - if len(build) > 2 { - return parseToolVersion(build[2]), nil - } - return toolVersionUnknown, nil -} - -// parseToolVersion translates a string version of the form 'go1.4.3' to a numeric value 14. -func parseToolVersion(version string) toolVersion { - match := goVersionPattern.FindStringSubmatch(version) - if len(match) > 2 { - // After a successful match, match[1] and match[2] are integers - major := mustAtoi(match[1]) - minor := mustAtoi(match[2]) - return toolVersion(major*10 + minor) - } - return toolVersionUnknown -} - -func newGit(pkg string) *git { - args := []string{"--work-tree", pkg, "--git-dir", filepath.Join(pkg, ".git")} - return &git{&tool.T{ - Cmd: "git", - Args: args, - }} -} - -// git represents an instance of the git tool. -type git struct { - *tool.T -} - -// treeState describes the state of the git tree. -// `git describe --dirty` only considers changes to existing files. -// We track tree state and consider untracked files as they also affect the build. -type treeState string - -const ( - clean treeState = "clean" - dirty = "dirty" -) - -// toolVersion represents a tool version as an integer. -// toolVersion only considers the first two significant version parts and is computed as follows: -// majorVersion*10+minorVersion -type toolVersion int - -const toolVersionUnknown toolVersion = 0 - -func (r *git) commitID() (string, error) { - return r.Exec("rev-parse", "HEAD^{commit}") -} - -func (r *git) treeState() (treeState, error) { - out, err := r.Exec("status", "--porcelain") - if err != nil { - return "", err - } - if len(out) == 0 { - return clean, nil - } - return dirty, nil -} - -func (r *git) tag(commitID string) (string, error) { - return r.Exec("describe", "--tags", "--abbrev=14", commitID+"^{commit}") -} - -// semverify transforms the output of `git describe` to be semver-complaint. -func semverify(version string) string { - var result []byte - match := semverPattern.FindStringSubmatchIndex(version) - if match != nil { - return string(semverPattern.ExpandString(result, "$1.$2+$3", string(version), match)) - } - return version -} - -// mustAtoi converts value to an integer. -// It panics if the value does not represent a valid integer. -func mustAtoi(value string) int { - result, err := strconv.Atoi(value) - if err != nil { - panic(err) - } - return result -} diff --git a/vendor/github.com/gravitational/version/doc.go b/vendor/github.com/gravitational/version/doc.go deleted file mode 100644 index 2db5702183ebf..0000000000000 --- a/vendor/github.com/gravitational/version/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Copyright 2015 Gravitational, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Package version supplies version information collected at build time. -package version diff --git a/vendor/github.com/gravitational/version/pkg/tool/tool.go b/vendor/github.com/gravitational/version/pkg/tool/tool.go deleted file mode 100644 index 2dfb7deca2285..0000000000000 --- a/vendor/github.com/gravitational/version/pkg/tool/tool.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2015 Gravitational, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Package tool provides a currying wrapper around os/exec.Command that fixes a set of arguments. -package tool - -import ( - "bytes" - "fmt" - "os/exec" -) - -// T represents an instance of a running tool specified with cmd and -// an optional list of fixed initial arguments args. -type T struct { - Cmd string - Args []string -} - -// Error is a tool execution error. -type Error struct { - Tool string - Output []byte - Err error -} - -func (r *Error) Error() string { - return fmt.Sprintf("error executing `%s`: %v (%s)", r.Tool, r.Err, r.Output) -} - -// exec executes a given command specified with args prepending a set of fixed arguments. -// Otherwise behaves exactly as rawExec -func (r *T) Exec(args ...string) (string, error) { - args = append(r.Args[:], args...) - return r.RawExec(args...) -} - -// RawExec executes a given command specified with args and returns the output -// with whitespace trimmed. -func (r *T) RawExec(args ...string) (string, error) { - out, err := exec.Command(r.Cmd, args...).CombinedOutput() - if err == nil { - out = bytes.TrimSpace(out) - } - if err != nil { - err = &Error{ - Tool: r.Cmd, - Output: out, - Err: err, - } - } - return string(out), err -} diff --git a/vendor/github.com/gravitational/version/test/main.go b/vendor/github.com/gravitational/version/test/main.go deleted file mode 100644 index ebe0ae7369776..0000000000000 --- a/vendor/github.com/gravitational/version/test/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import "github.com/gravitational/version" - -func init() { - // Reset base version to a custom one in case no tag has been created. - // It will be reset with a git tag if there's one. - version.Init("v0.0.1") -} - -func main() { - version.Print() -} diff --git a/vendor/github.com/gravitational/version/version.go b/vendor/github.com/gravitational/version/version.go deleted file mode 100644 index 9fcbfbb668a93..0000000000000 --- a/vendor/github.com/gravitational/version/version.go +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright 2015 Gravitational, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package version - -import ( - "encoding/json" - "fmt" -) - -// Info describes build version with a semver-complaint version string and -// git-related commit/tree state details. -type Info struct { - Version string `json:"version"` - GitCommit string `json:"gitCommit"` - GitTreeState string `json:"gitTreeState"` -} - -// Get returns current build version. -func Get() Info { - return Info{ - Version: version, - GitCommit: gitCommit, - GitTreeState: gitTreeState, - } -} - -func (r Info) String() string { - return r.Version -} - -// Print prints build version in default format. -func Print() { - payload, err := json.Marshal(Get()) - if err != nil { - panic(err) - } - fmt.Printf("%s", payload) -} diff --git a/version.go b/version.go new file mode 100644 index 0000000000000..709560783fc75 --- /dev/null +++ b/version.go @@ -0,0 +1,9 @@ +/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make setver'*/ +package teleport + +const ( + Version = "1.0.0" + Suffix = "stable" +) + +var Gitref string diff --git a/version.mk b/version.mk index 3617868429112..bf84b36714164 100644 --- a/version.mk +++ b/version.mk @@ -1,12 +1,24 @@ -VERSION=0.9.0 -SUFFIX=stable -GITTAG=v$(VERSION)-$(SUFFIX) -GITREF=$(shell git describe --dirty --tags) +GITREF=$(shell git describe --dirty --long --tags) -FOO="\n\ -one\ntwo" +# $(VERSION_GO) will be written to version.go +VERSION_GO="/* DO NOT EDIT THIS FILE. IT IS GENERATED BY 'make setver'*/\n\ +package teleport\n\ +const(\n\ +Version = \"$(VERSION)\"\n\ +Suffix = \"$(SUFFIX)\"\n\ +)\n\ +var Gitref string\n" -.PHONY:all -all: - @echo $(GITTAG) - @echo $(GITREF) +# $(GIT_GO) will be written to gitref.go +GITREF_GO="/* DO NOT EDIT THIS FILE. IT IS GENERATED BY make */ \n\n\ +package teleport\n\ +func init() { Gitref = \"$(GITREF)\"} " + +# +# setver updates version.go and gitref.go with VERSION and SUFFIX +# constants above. +# +.PHONY:setver +setver: + @echo $(VERSION_GO) | gofmt > version.go + @echo $(GITREF_GO) | gofmt > gitref.go