Adding initial skeleton
This commit is contained in:
parent
fc39631f44
commit
0b91f01cbf
55
Makefile
Normal file
55
Makefile
Normal file
|
@ -0,0 +1,55 @@
|
|||
DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
|
||||
PACKAGES = $(shell go list ./...)
|
||||
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
||||
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
||||
|
||||
all: deps format
|
||||
@mkdir -p bin/
|
||||
@bash --norc -i ./scripts/build.sh
|
||||
|
||||
cov:
|
||||
gocov test ./... | gocov-html > /tmp/coverage.html
|
||||
open /tmp/coverage.html
|
||||
|
||||
deps:
|
||||
@echo "--> Installing build dependencies"
|
||||
@go get -d -v ./... $(DEPS)
|
||||
|
||||
updatedeps: deps
|
||||
@echo "--> Updating build dependencies"
|
||||
@go get -d -f -u ./... $(DEPS)
|
||||
|
||||
test: deps
|
||||
@./scripts/verify_no_uuid.sh
|
||||
@./scripts/test.sh
|
||||
@$(MAKE) vet
|
||||
|
||||
integ:
|
||||
go list ./... | INTEG_TESTS=yes xargs -n1 go test
|
||||
|
||||
cover: deps
|
||||
./scripts/verify_no_uuid.sh
|
||||
go list ./... | xargs -n1 go test --cover
|
||||
|
||||
format: deps
|
||||
@echo "--> Running go fmt"
|
||||
@go fmt $(PACKAGES)
|
||||
|
||||
vet:
|
||||
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
|
||||
go get golang.org/x/tools/cmd/vet; \
|
||||
fi
|
||||
@echo "--> Running go tool vet $(VETARGS) ."
|
||||
@go tool vet $(VETARGS) . ; if [ $$? -eq 1 ]; then \
|
||||
echo ""; \
|
||||
echo "Vet found suspicious constructs. Please check the reported constructs"; \
|
||||
echo "and fix them if necessary before submitting the code for reviewal."; \
|
||||
fi
|
||||
|
||||
web:
|
||||
./scripts/website_run.sh
|
||||
|
||||
web-push:
|
||||
./scripts/website_push.sh
|
||||
|
||||
.PHONY: all cov deps integ test vet web web-push test-nodep
|
44
commands.go
Normal file
44
commands.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/hashicorp/vault/command"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
// Commands returns the mapping of CLI commands for Vault. The meta
|
||||
// parameter lets you set meta options for all commands.
|
||||
func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
|
||||
if metaPtr == nil {
|
||||
metaPtr = new(command.Meta)
|
||||
}
|
||||
|
||||
meta := *metaPtr
|
||||
if meta.Ui == nil {
|
||||
meta.Ui = &cli.BasicUi{
|
||||
Writer: os.Stdout,
|
||||
ErrorWriter: os.Stderr,
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]cli.CommandFactory{
|
||||
"version": func() (cli.Command, error) {
|
||||
ver := Version
|
||||
rel := VersionPrerelease
|
||||
if GitDescribe != "" {
|
||||
ver = GitDescribe
|
||||
}
|
||||
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
||||
rel = "dev"
|
||||
}
|
||||
|
||||
return &command.VersionCommand{
|
||||
Revision: GitCommit,
|
||||
Version: ver,
|
||||
VersionPrerelease: rel,
|
||||
Ui: meta.Ui,
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
}
|
43
main.go
Normal file
43
main.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(Run(os.Args[1:]))
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
return RunCustom(args, Commands(nil))
|
||||
}
|
||||
|
||||
func RunCustom(args []string, commands map[string]cli.CommandFactory) int {
|
||||
// Get the command line args. We shortcut "--version" and "-v" to
|
||||
// just show the version.
|
||||
for _, arg := range args {
|
||||
if arg == "-v" || arg == "-version" || arg == "--version" {
|
||||
newArgs := make([]string, len(args)+1)
|
||||
newArgs[0] = "version"
|
||||
copy(newArgs[1:], args)
|
||||
args = newArgs
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
cli := &cli.CLI{
|
||||
Args: args,
|
||||
Commands: commands,
|
||||
HelpFunc: cli.BasicHelpFunc("nomad"),
|
||||
}
|
||||
|
||||
exitCode, err := cli.Run()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
||||
return 1
|
||||
}
|
||||
return exitCode
|
||||
}
|
4
main_test.go
Normal file
4
main_test.go
Normal file
|
@ -0,0 +1,4 @@
|
|||
package main
|
||||
|
||||
// This file is intentionally empty to force early versions of Go
|
||||
// to test compilation for tests.
|
52
scripts/build.sh
Executable file
52
scripts/build.sh
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script builds the application from source.
|
||||
set -e
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||
|
||||
# Change into that directory
|
||||
cd $DIR
|
||||
|
||||
# Get the git commit
|
||||
GIT_COMMIT=$(git rev-parse HEAD)
|
||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||
GIT_DESCRIBE=$(git describe --tags)
|
||||
|
||||
# If we're building on Windows, specify an extension
|
||||
EXTENSION=""
|
||||
if [ "$(go env GOOS)" = "windows" ]; then
|
||||
EXTENSION=".exe"
|
||||
fi
|
||||
|
||||
GOPATHSINGLE=${GOPATH%%:*}
|
||||
if [ "$(go env GOOS)" = "windows" ]; then
|
||||
GOPATHSINGLE=${GOPATH%%;*}
|
||||
fi
|
||||
|
||||
if [ "$(go env GOOS)" = "freebsd" ]; then
|
||||
export CC="clang"
|
||||
fi
|
||||
|
||||
# On OSX, we need to use an older target to ensure binaries are
|
||||
# compatible with older linkers
|
||||
if [ "$(go env GOOS)" = "darwin" ]; then
|
||||
export MACOSX_DEPLOYMENT_TARGET=10.6
|
||||
fi
|
||||
|
||||
# Install dependencies
|
||||
echo "--> Installing dependencies to speed up builds..."
|
||||
go get \
|
||||
-ldflags "${CGO_LDFLAGS}" \
|
||||
./...
|
||||
|
||||
# Build!
|
||||
echo "--> Building..."
|
||||
go build \
|
||||
-ldflags "${CGO_LDFLAGS} -X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY} -X main.GitDescribe ${GIT_DESCRIBE}" \
|
||||
-v \
|
||||
-o bin/nomad${EXTENSION}
|
||||
cp bin/nomad${EXTENSION} ${GOPATHSINGLE}/bin
|
74
scripts/dist.sh
Executable file
74
scripts/dist.sh
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Get the version from the command line
|
||||
VERSION=$1
|
||||
if [ -z $VERSION ]; then
|
||||
echo "Please specify a version."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure we have a bintray API key
|
||||
if [ -z $BINTRAY_API_KEY ]; then
|
||||
echo "Please set your bintray API key in the BINTRAY_API_KEY env var."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||
|
||||
# Change into that dir because we expect that
|
||||
cd $DIR
|
||||
|
||||
# Zip all the files
|
||||
rm -rf ./dist/pkg
|
||||
mkdir -p ./dist/pkg
|
||||
for FILENAME in $(find ./dist -mindepth 1 -maxdepth 1 -type f); do
|
||||
FILENAME=$(basename $FILENAME)
|
||||
EXTENSION="${FILENAME##*.}"
|
||||
PLATFORM="${FILENAME%.*}"
|
||||
|
||||
if [ "${EXTENSION}" != "exe" ]; then
|
||||
EXTENSION=""
|
||||
else
|
||||
EXTENSION=".${EXTENSION}"
|
||||
fi
|
||||
|
||||
NOMADNAME="nomad${EXTENSION}"
|
||||
|
||||
pushd ./dist
|
||||
|
||||
if [ "${FILENAME}" = "ui.zip" ]; then
|
||||
cp ${FILENAME} ./pkg/${VERSION}_web_ui.zip
|
||||
else
|
||||
if [ "${EXTENSION}" = "" ]; then
|
||||
chmod +x ${FILENAME}
|
||||
fi
|
||||
|
||||
cp ${FILENAME} ${NOMADNAME}
|
||||
zip ./pkg/${VERSION}_${PLATFORM}.zip ${NOMADNAME}
|
||||
rm ${NOMADNAME}
|
||||
fi
|
||||
|
||||
popd
|
||||
done
|
||||
|
||||
# Make the checksums
|
||||
pushd ./dist/pkg
|
||||
shasum -a256 * > ./${VERSION}_SHA256SUMS
|
||||
popd
|
||||
|
||||
# Upload
|
||||
for ARCHIVE in ./dist/pkg/*; do
|
||||
ARCHIVE_NAME=$(basename ${ARCHIVE})
|
||||
|
||||
echo Uploading: $ARCHIVE_NAME
|
||||
curl \
|
||||
-T ${ARCHIVE} \
|
||||
-umitchellh:${BINTRAY_API_KEY} \
|
||||
"https://api.bintray.com/content/mitchellh/nomad/nomad/${VERSION}/${ARCHIVE_NAME}"
|
||||
done
|
||||
|
||||
exit 0
|
17
scripts/website_push.sh
Executable file
17
scripts/website_push.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||
|
||||
# Change into that directory
|
||||
cd $DIR
|
||||
|
||||
# Add the git remote if it doesn't exist
|
||||
git remote | grep heroku || {
|
||||
git remote add heroku git@heroku.com:nomad-www.git
|
||||
}
|
||||
|
||||
# Push the subtree (force)
|
||||
git push heroku `git subtree split --prefix website master`:master --force
|
13
version.go
Normal file
13
version.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
var GitCommit string
|
||||
var GitDescribe string
|
||||
|
||||
// The main version number that is being run at the moment.
|
||||
const Version = "0.1.0"
|
||||
|
||||
// A pre-release marker for the version. If this is "" (empty string)
|
||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||
// such as "dev" (in development), "beta", "rc1", etc.
|
||||
const VersionPrerelease = "dev"
|
Loading…
Reference in a new issue