Skip to content
Permalink
Browse files
Closes #47
simpler go CLI project setup and tweaks to instructions for n00bs
  • Loading branch information
geomacy committed Apr 25, 2017
2 parents 3486f6f + b6657c7 commit d705af1f4811d1d9bfa5c0dcb53d6a9a711be720
Showing 2 changed files with 58 additions and 30 deletions.
@@ -10,8 +10,9 @@ A command line client for [Apache Brooklyn](https://brooklyn.apache.org).
The CLI tool is written in Go and should be obtained and built as a standard Go project.
You will need the following tools to build it:

- Go (version 1.6.1 or higher), with full cross-compiler support (see https://golang.org/dl).
On Mac, if using Homebrew, use "brew install go --with-cc-all"
- Go (version 1.6.1 or higher), with full cross-compiler support:
the standard [binary packages](https://golang.org/dl) include this,
or you can use your favorite package managers (e.g. `brew install go --with-cc-all`).

Optional:
- Maven (used by the Brooklyn build process)
@@ -21,34 +22,61 @@ Optional:

## Workspace Setup

Go is very particular about the layout of a source tree, and the naming of packages. It is therefore important to
get the code from github.com/apache/brooklyn-client/cli and not your own fork. If you want to contribute to the
project, the procedure to follow is still to get the code from github.com/apache/brooklyn-client/cli, and then to add your
own fork as a remote.
Go is very particular about the layout of a source tree and the source repository,
as it relies on this in the naming of packages.

- Ensure your [$GOPATH](http://golang.org/cmd/go/#hdr-GOPATH_environment_variable) is set correctly
to a suitable location for your Go code, for example, simply $HOME/go.
- Get the Brooklyn CLI and dependencies.
If you're familiar with Go and just want to develop the `br` tool itself you may simply work in your usual `GOPATH`,
using `go get github.com/apache/brooklyn-client/cli/br` and adding your own fork as a remote.
If you know `glide` then you probably know what to do and can ignore these instructions;
`br` is built just like any other Go project.

If you're new to Go and you want to work on the CLI alongside non-Go components in Apache Brooklyn,
then the common Go setup -- where code lives under the `GOPATH` -- may be tedious to work with.
A good pattern is to have the requisite `GOPATH` entry linking to the `brooklyn-client` project
elsewhere on disk, so you have just one copy in the usual space and there is no need to touch the `GOPATH` thereafter.
This is the recommended default described by the instructions below.

First ensure that a `GOPATH` is set; this is where Go will store its files.
`~/go` is the default, and `~/.go` is acceptable also. For example:

```bash
export GOPATH=$HOME/go
```

These instructions now assume that you have `brooklyn-client` checked out and are
in the `cli` subdirectory, where this file resides.
Tell Go to use this checked-out project by linking to it under `GOPATH`:

```bash
go get github.com/apache/brooklyn-client/cli/br
rm -rf $GOPATH/src/github.com/apache/brooklyn-client
cd ..
ln -s `pwd` $GOPATH/src/github.com/apache/brooklyn-client
cd cli
```


## Installing Dependencies

The CLI has a small number of dependencies, notably on `urfave/cli`. To manage the version of dependencies, the CLI
code currently uses [Glide](https://github.com/Masterminds/glide). The dependencies are installed to the top level 'vendor' directory.
The CLI has a small number of dependencies, including the popular `urfave/cli`.
To manage the version of dependencies, the CLI
code currently uses [Glide](https://github.com/Masterminds/glide) to fetch
and maintain these:

```bash
go get github.com/Masterminds/glide
cd $GOPATH/src/github.com/apache/brooklyn-client/cli
glide install
$GOPATH/bin/glide install
```


## Compiling the code with Go for development purposes

Just use the regular Go build commands.
Just use the regular Go build commands:

```bash
go build -o target/br ./br
```

The binary is now ready to use in `target/br`.


## Testing
@@ -64,11 +92,11 @@ sh test.sh http://your-brooklyn-host:8081 myuser mypassword

Note, the tests are not yet comprehensive, and contributions are welcome.


## Building the code as part of the Brooklyn build process

For consistency with the other sub-projects of the overall [Brooklyn](https://github.com/apache/brooklyn) build, Maven
is used to perform the build when brooklyn-client is built as one of the sub-modules of Brooklyn. Most of the work is
delegated to the release/build.sh script, which cross-compiles the code for a number of platform-architecture combinations.
is used to perform the build when brooklyn-client is built as one of the sub-modules of Brooklyn, cross-compiling the code for a number of platform-architecture combinations.

Invoke the build script via Maven with one of

@@ -82,23 +110,28 @@ location, the Maven build makes no assumption about the location of the project
`target` directory is used as the GOPATH, and a soft link is created as `target/src/github.com/apache/brooklyn-cli` to
the code in the root directory.

This builds the requested binaries into the "target" directory, each in its own subdirectory with a name that includes
the platform/architecture details, e.g. bin/linux.386/br. The build installs a maven artifact to the maven repository,
This builds the requested binaries into the `target/` directory, each in its own subdirectory with a name that includes
the platform/architecture details, e.g. `bin/linux.386/br`. The build installs a maven artifact to the maven repository,
consisting of a zip file containing all the binaries. This artifact can be referenced in a POM as

```xml
<groupId>org.apache.brooklyn</groupId>
<artifactId>brooklyn-client-cli</artifactId>
<classifier>bin</classifier>
<type>zip</type>
<version>...</version>
<version>0.12.0-SNAPSHOT</version> <!-- BROOKLYN_VERSION -->
```

Most of the work is delegated to the `release/build.sh` script;
it is not normally necessary to use this, but if you need to know more,
try `release/build.sh -h` for more information.


## Running
## Usage

See instructions in the included [Runtime README](release/files/README) file.


----
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -36,8 +36,8 @@ START_TIME=$(date +%s)
os=""
arch=""
all=""
outdir="."
sourcedir="."
outdir=`pwd`/target
sourcedir=`pwd`
label=""
timestamp=""

@@ -174,12 +174,7 @@ See golang.org for more information, or run maven with '-Dno-go-client' to skip.
exit 1
fi
if [ -n "$outdir" -a ! -d "$outdir" ]; then
show_help
echo "No such directory: $outdir"
exit 1
fi
mkdir -p $outdir
# Set GOPATH to $outdir and link to source code.
export GOPATH=${outdir}

0 comments on commit d705af1

Please sign in to comment.