Skip to content

Commit

Permalink
Merge branch 'develop' of gitlab.bytemark.co.uk:open-source/bytemark-…
Browse files Browse the repository at this point in the history
…client into admin-commands
  • Loading branch information
Phil Manavopoulos committed Mar 9, 2017
2 parents c8eb5ec + 486d83f commit feae0dd
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 34 deletions.
52 changes: 39 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ lint-in-anger:
release-check:
stage: test
image: alpine
before_script: []
before_script: &version_script
- VERSION=${CI_BUILD_REF_NAME##release-}
# If the CI_BUILD_REF_NAME is not prefixed with release- (e.g. for a branch)
# then VERSION will be equal to CI_BUILD_REF_NAME.
- '! [ "$VERSION" = "$CI_BUILD_REF_NAME" ] || VERSION=""'
- CHANGELOG_VERSION=$(sed "s/.*(\([^)]\+\)).*/\1/ ; q" doc/changelog)
- SNAPSHOT_VERSION=${CI_PIPELINE_ID}.git${CI_BUILD_REF:0:7}
script:
- |
VERSION=${CI_BUILD_REF_NAME##release-}
if ! head -n 1 doc/changelog | grep "^bytemark-client ($VERSION)" > /dev/null; then
if ! [ "$VERSION" = "$CHANGELOG_VERSION" ] ;
echo "Mismatch between branch name and changelog version"
exit 1
fi
Expand All @@ -66,7 +71,7 @@ vet:
test:
<<: *test
script:
- go get github.com/modocache/gover golang.org/x/tools/cmd/cover
- go get github.com/modocache/gover golang.org/x/tools/cmd/cover
- OLDPWD="$PWD"
- cd $GOPATH/src/github.com/BytemarkHosting/bytemark-client
- |
Expand All @@ -82,8 +87,6 @@ test:
paths:
- coverage.html
expire_in: '1 week'



.build-job: &build
stage: build
Expand Down Expand Up @@ -147,12 +150,10 @@ build-amd64-windows:

.package-job: &package
stage: package
before_script: []
before_script: *version_script
dependencies:
- build-amd64-linux
- build-manpage
only:
- /^release-\d+(\.\d+)+$/

#package-debian-amd64:
# <<: *package
Expand Down Expand Up @@ -200,6 +201,7 @@ package-debian-amd64:
script:
- ln -s .gitlab-ci/debian
- mv bytemark-amd64-linux bytemark
- '[ "$VERSION" = "$CI_BUILD_REF_NAME" ] || CHANGELOG=doc/changelog dch --nomultimaint --maintmaint -v "$CHANGELOG_VERSION~$SNAPSHOT_VERSION" --force-bad-version "Snapshot build"'
- fakeroot debian/rules binary
- lintian -i ../bytemark-client*.deb
- mv ../bytemark-client*.deb .
Expand All @@ -220,7 +222,7 @@ package-rpm-amd64:
- mkdir -p ~/rpmbuild/SOURCES
- mv bytemark-amd64-linux ~/rpmbuild/SOURCES/bytemark
- mv doc/bytemark.1 ~/rpmbuild/SOURCES/bytemark.1
- rpmbuild --define "version ${CI_BUILD_REF_NAME##release-}" --define "release $CI_BUILD_ID" -bb .gitlab-ci/bytemark-client.spec
- rpmbuild --define "version ${VERSION:-$CHANGELOG_VERSION}" --define "release ${SNAPSHOT_VERSION}" -bb .gitlab-ci/bytemark-client.spec
- mv ~/rpmbuild/RPMS/*/bytemark*.rpm .
artifacts:
paths:
Expand All @@ -236,7 +238,7 @@ package-windows-amd64:
image: gitlab.bytemark.co.uk:8443/docker-images/chocolatey
script:
- mkdir -p choco/tools
- sed -e "s/VERSION/${CI_BUILD_REF_NAME##release-}/g" .gitlab-ci/bytemark-client.nuspec > choco/bytemark-client.nuspec
- sed -e "s/VERSION/${VERSION:-$CHANGELOG_VERSION.$CI_PIPELINE_ID}/g" .gitlab-ci/bytemark-client.nuspec > choco/bytemark-client.nuspec
- mv bytemark-amd64-windows choco/tools/bytemark.exe
- cd choco
- mono /usr/bin/choco.exe pack bytemark-client.nuspec
Expand All @@ -249,6 +251,30 @@ package-windows-amd64:
dependencies:
- build-amd64-windows

publish:
stage: release
tags:
- shell
before_script: *version_script
script:
- mkdir -p pkg/{linux,mac,freebsd,openbsd,windows,debian,rpm}
- VERSION=${VERSION:-$CHANGELOG_VERSION~$SNAPSHOT_VERSION}
- cp bytemark-amd64-linux.tar.gz pkg/linux/bytemark-$VERSION.tar.gz
- cp bytemark-amd64-freebsd.tar.gz pkg/freebsd/bytemark-$VERSION.tar.gz
- cp bytemark-amd64-openbsd.tar.gz pkg/openbsd/bytemark-$VERSION.tar.gz
- cp bytemark-amd64-darwin.tar.gz pkg/mac/bytemark-$VERSION.tar.gz
- cp bytemark-amd64-windows.zip pkg/windows/bytemark-$VERSION.zip
# The debian, rpm, and chocolatey versions have their numbers set already.
- cp bytemark.*.nupkg pkg/windows
- cp bytemark-client_*_amd64.deb pkg/debian
- cp bytemark-client-*.rpm pkg/rpm
- publish
dependencies:
- package-generic-amd64
- package-rpm-amd64
- package-debian-amd64
- package-windows-amd64

.release-job: &release
stage: release
image: gitlab.bytemark.co.uk:8443/docker-images/debian-git
Expand Down Expand Up @@ -304,7 +330,7 @@ release-to-brew:
- HASHRULE=$(echo s!sha256 '"'.*'"'!sha256 '"'$SHA256'"'!)
- echo sed -e "$URLRULE" -e "$HASHRULE" -i bytemark-client.rb
- sed -e "$URLRULE" -e "$HASHRULE" -i bytemark-client.rb
- git commit -m "Update bytemark-client to version VERSION" -- bytemark-client.rb
- git commit -m "Update bytemark-client to version VERSION" -- bytemark-client.rb
- git log HEAD^..HEAD
- git diff HEAD^..HEAD
- git push origin master
Expand All @@ -318,7 +344,7 @@ release-to-chocolatey:
- VERSION=${CI_BUILD_REF_NAME##release-}
- mono /usr/bin/choco.exe apiKey -k "$CHOCO_API_KEY" -source https://chocolatey.org
script:
- mono /usr/bin/choco.exe push bytemark.$VERSION.nupkg -acceptLicense -y
- mono /usr/bin/choco.exe push bytemark.$VERSION.nupkg -acceptLicense -y
dependencies:
- package-windows-amd64

1 change: 1 addition & 0 deletions .gitlab-ci/debian/bytemark-client.manpages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc/bytemark.1
1 change: 1 addition & 0 deletions .gitlab-ci/debian/changelog
8 changes: 0 additions & 8 deletions .gitlab-ci/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ export DH_VERBOSE = 1
override_dh_auto_clean:
exit 0

override_dh_auto_build:
cp doc/bytemark.1 doc/changelog debian

override_dh_auto_test:
exit 0

override_dh_auto_configure:
exit 0

override_dh_auto_install:
cp bytemark debian/tmp
mkdir -p debian/bytemark-client/usr/share/man/man1
cp doc/bytemark.1 debian/bytemark-client/usr/share/man/man1

# debmake generated override targets
# This is example for Cmake (See http://bugs.debian.org/641051 )
#override_dh_auto_configure:
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
Bytemark command-line client
============================

[![Build Status](https://travis-ci.org/BytemarkHosting/bytemark-client.svg)](https://travis-ci.org/BytemarkHosting/bytemark-client) [![Coverage Status](https://coveralls.io/repos/github/BytemarkHosting/bytemark-client/badge.svg?branch=develop)](https://coveralls.io/github/BytemarkHosting/bytemark-client?branch=develop)
[![Build Status](https://travis-ci.org/BytemarkHosting/bytemark-client.svg)](https://travis-ci.org/BytemarkHosting/bytemark-client) [![Coverage Status](https://coveralls.io/repos/github/BytemarkHosting/bytemark-client/badge.svg?branch=develop)](https://coveralls.io/github/BytemarkHosting/bytemark-client?branch=develop)

Installation
------------

If you have a binary then it's easy - just run it!
If you're just looking to get started you can find the most recent stable
release on our [download page](https://github.com/BytemarkHosting/bytemark-client/releases).

If you have a go workspace you can also just `go get github.com/BytemarkHosting/bytemark-client/cmd/bytemark` if you like, to get the latest stable.
If you wish to build, and install, the latest stable-release from source you can do so with:

And if you want to work on the develop branch, probably the easiest way is to `go get` it and then wipe it out and clone it by hand.
go get github.com/BytemarkHosting/bytemark-client/cmd/bytemark

`cmd/bytemark` is where 'main' is, so `cd` into there to build or use the full import path, as with go get.

Feel free to open issues & merge requests on the github repo at http://github.com/BytemarkHosting/bytemark-client
Tracking Development
====================

If you prefer to track our in-development branch you can do that via:

go get -d github.com/BytemarkHosting/bytemark-client/cmd/bytemark
cd $GOPATH/src/github.com/BytemarkHosting/bytemark-client/
git checkout develop
cd cmd/bytemark
go build


If you have problems to report, or contributions to make, feel free to [use the issue-tracker](https://github.com/BytemarkHosting/bytemark-client/issues)

Compatibility Guarantee
=======================
Expand Down
27 changes: 26 additions & 1 deletion cmd/bytemark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"
)

// forceFlag is common to a bunch of commands and can have a generic Usage.
var forceFlag = cli.BoolFlag{
Name: "force",
Usage: "Do not prompt for confirmation when destroying data or increasing costs.",
Expand Down Expand Up @@ -88,11 +89,35 @@ func main() {
global.Client = cli
global.Client.SetDebugLevel(global.Config.GetDebugLevel())

outputDebugInfo()

err = global.App.Run(args)

os.Exit(int(util.ProcessError(err)))
}

func outputDebugInfo() {
log.Debugf(log.LvlOutline, "bytemark-client %s\r\n\r\n", lib.Version)
// assemble a string of config vars (excluding token)
vars, err := global.Config.GetAll()
if err != nil {
log.Debugf(log.LvlFlags, "(not a real problem maybe): had trouble getting all config vars: %s\r\n", err.Error())
}

log.Debugf(log.LvlFlags, "reading config from %s\r\n\r\n", global.Config.ConfigDir())
log.Debug(log.LvlFlags, "config vars:")
for _, v := range vars {
if v.Name == "token" {
log.Debugf(log.LvlFlags, " %s (%s): not printed for security\r\n", v.Name, v.Source)
continue
}
log.Debugf(log.LvlFlags, " %s (%s): '%s'\r\n", v.Name, v.Source, v.Value)
}
log.Debug(log.LvlFlags, "")

log.Debugf(log.LvlFlags, "invocation: %s\r\n\r\n", strings.Join(os.Args, " "))
}

// EnsureAuth authenticates with the Bytemark authentication server, prompting for credentials if necessary.
func EnsureAuth() error {
token, err := global.Config.Get("token")
Expand Down Expand Up @@ -206,6 +231,7 @@ func mergeCommands(base []cli.Command, extras []cli.Command) (result []cli.Comma
return
}

// overrideHelp writes our own help templates into urfave/cli
func overrideHelp() {
cli.SubcommandHelpTemplate = `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down Expand Up @@ -338,7 +364,6 @@ func prepConfig() (flags []cli.Flag, args []string) {
copy(args[1:], flargs)
}
args[0] = os.Args[0]
log.Debugf(log.LvlFlags, "orig: %v\r\nflag: %v\r\n new: %v\r\n", os.Args, flargs, args)

if *help || *h {
helpArgs := make([]string, len(args)+1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/bytemark/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bytemark schedule backups --start 00:00 fileserver very-important-data 86400
To have hourly backups starting at 14:37 (Central European Summer Time) on the 5th of April, 2017:
bytemark schedule backups --start "2017-04-05T14:37:00+02:00" fileserver very-important-data 3600`,
Action: With(OptionalArgs("server", "disc", "interval"), RequiredFlags("server", "disc"), func(c *Context) (err error) {
Action: With(OptionalArgs("server", "disc", "interval"), RequiredFlags("server", "disc"), AuthProvider, func(c *Context) (err error) {
start := c.String("start")
if start == "" {
start = "00:00"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bytemark/unschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The <schedule id> is a number that can be found out using 'bytemark show disc <s
Usage: "the ID of the schedule to remove. See the output of `show disc` to find out schedule IDs.",
},
},
Action: With(OptionalArgs("server", "disc", "schedule-id"), RequiredFlags("server", "disc", "schedule-id"), func(c *Context) (err error) {
Action: With(OptionalArgs("server", "disc", "schedule-id"), RequiredFlags("server", "disc", "schedule-id"), AuthProvider, func(c *Context) (err error) {
if c.Int("schedule-id") < 1 {
return fmt.Errorf("schedule-id not specified or invalid")
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/bytemark/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type ConfigManager interface {
GetDebugLevel() int
EndpointName() string
PanelURL() string
ConfigDir() string

ImportFlags(*flag.FlagSet) []string
}
Expand Down Expand Up @@ -322,10 +323,10 @@ func (config *Config) GetAll() (vars []ConfigVar, err error) {
for i, v := range configVars {
vars[i], err = config.GetV(v)
if err != nil {
return nil, err
return
}
}
return vars, nil
return
}

// GetDefault returns the default ConfigVar for the given key.
Expand Down Expand Up @@ -515,3 +516,8 @@ func (config *Config) EndpointName() string {
endpoint = strings.TrimPrefix(endpoint, "http://") // it never hurts to be prepared
return endpoint
}

// ConfigDir returns the path of the directory used to read config.
func (config *Config) ConfigDir() string {
return config.Dir
}
10 changes: 9 additions & 1 deletion doc/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
bytemark-client (2.2) UNRELEASED; urgency=low

New features:
* First release of admin interface.
* First release of backups interface.

-- Patrick J Cherry <patrick@bytemark.co.uk> Mon, 06 Mar 2017 16:48:31 +0000

bytemark-client (2.1) UNRELEASED; urgency=low

New features:
Expand Down Expand Up @@ -29,7 +37,7 @@ bytemark-client (2.1) UNRELEASED; urgency=low

-- telyn <telyn@bytemark.co.uk> Thu, 29 Dec 2016 11:40:03 +0000

bytemark-client (2.1) UNRELEASED; urgency=low
bytemark-client (2.0.1) UNRELEASED; urgency=low

Changes:
* Registering a card (such as during signup) now sends a token to SPP.
Expand Down
2 changes: 1 addition & 1 deletion lib/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package lib

const (
// Version is the version number the client believes it is
Version = "2.1"
Version = "2.2"
)
4 changes: 4 additions & 0 deletions mocks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func (c *Config) EndpointName() string {
ret := c.Called()
return ret.String(0)
}
func (c *Config) ConfigDir() string {
ret := c.Called()
return ret.String(0)
}
func (c *Config) Force() bool {
ret := c.Called()
return ret.Bool(0)
Expand Down

0 comments on commit feae0dd

Please sign in to comment.