Skip to content

Commit

Permalink
Merge branch 'master' into john/#244-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
PiggySpeed committed Jul 4, 2018
2 parents 951741b + 0c4136e commit fdb9cfd
Show file tree
Hide file tree
Showing 30 changed files with 573 additions and 384 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
api_key:
secure: eHe5lL6mVp6XQM5sdUQHWcugROAjZC5Gf81flIjM/4K1ceUQfblIQ3/suXOHBXl+jGro0DTlI/a8S9zKb3NDdlTiXjABQD8KkWNMfEqajUInRwSFE7vSvydzJDuwO00KZOuFKdp2hZwpO2jbODZvHEnYONTClle5pV6bzhp4JaY1P0CjAl6/E67WVjpNQmHNIlzcZ7PRLe7KcjEl5N7DIg/B4R19EiBTjaPsCh8xP/T68cqVVa+4cwUAxN6Xd0ca81T9dkhppRL9tiJRn6iP/x64paIeWV0pF80V2PKTwbI9Ox0mcd7TWkHFD4taV+UwQUeOeN3OR7NHfzyPtWUcCVOp3wxFKvWySPYNeh8x8OrFh7HzIMl+20SQ/rdEsJJ6cfMx+qp+RBJmSj+Btm/ZxfEZgjRTg2jiCeUNnNpBL+46U49TVPTuw7+K97x/cGRF9k0JAfkq75tQTPCoQwmkCqTeJ6KGwFwlDx5+OUCJz3WS0XfQ6k88eYQygmBBdWqoHXUS75vOa96GVN1JSp8tBpSp0lUp+U2QQJkIy9VN9NpMlsbn3r5Ssk/AtEhal1fpT5tncPvzphwSKDH3WtCJ+FJjMajBIlZA2yop1VdsVJzKFBo2DH+yn8qd1tIsp5C+HDPvulCYMFCg7zJk0ksXZVERTGnrnRBSENW+Ut1avJ0=
file_glob: true
file: inertia.*
file: inertia.v*
go: "1.10"
on:
repo: ubclaunchpad/inertia
Expand Down
18 changes: 13 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,24 @@ $> git remote rename origin upstream # Set the official repo as you
$> git remote add origin https://github.com/$AMAZING_YOU/inertia.git
```

You will also want to add `GOPATH` and `GOBIN` to your `PATH` to use any Inertia executables you install. Just add the following to your `.bashrc` or `.bash_profile`:

```bash
export PATH="$PATH:$HOME/go/bin"
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin
```

Inertia uses:
- [dep](https://github.com/golang/dep) for managing Golang dependencies
- [npm](https://www.npmjs.com) to manage dependencies for Inertia's React web app
- [Docker](https://www.docker.com/community-edition) for various application functionalities and integration testing

Make sure all of the above are installed before running:
Make sure all of the above are installed (and that the Docker daemon is online) before running:

```bash
$> make # installs dependencies and an Inertia
# build tagged as "test" to gopath
$> make deps # installs dependencies
$> make cli # installs Inertia build tagged as "test" to gopath
$> inertia --version # check what version you have installed
```

Expand All @@ -108,7 +116,7 @@ This code should only include the CLI user interface and code used to manage loc

The Inertia client package manages all clientside functionality. The client codebase is in `./client/`.

To bootstrap servers, some bash scripting is often involved, but we'd like to avoid shipping bash scripts with our go binary - instead, we use [go-bindata](https://github.com/jteeuwen/go-bindata) to compile shell scripts into our Go executables. If you make changes to the bootstrapping shell scripts in `client/bootstrap/`, convert them to `Assets` by running:
To bootstrap servers, some bash scripting is often involved, but we'd like to avoid shipping bash scripts with our go binary - instead, we use [go-bindata](https://github.com/jteeuwen/go-bindata) to compile shell scripts into our Go executables. If you make changes to the bootstrapping shell scripts in `client/scripts/`, convert them to `Assets` by running:

```bash
$> make bootstrap
Expand All @@ -117,7 +125,7 @@ $> make bootstrap
Then use your asset!

```go
shellScriptData, err := Asset("client/bootstrap/myshellscript.sh")
shellScriptData, err := Asset("client/scripts/myshellscript.sh")
if err != nil {
log.Fatal("No asset with that name")
}
Expand Down
8 changes: 1 addition & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean:
# Run static analysis
.PHONY: lint
lint:
PATH=$(PATH):./bin bash -c './bin/gometalinter --vendor --deadline=60s ./...'
PATH=$(PATH):./bin bash -c './bin/gometalinter --vendor --deadline=120s ./...'
(cd ./daemon/web; npm run lint)

# Run test suite without Docker ops
Expand All @@ -65,7 +65,6 @@ test-v:
# Also attempts to run linter
.PHONY: test-all
test-all:
make lint
make testenv VPS_OS=$(VPS_OS) VPS_VERSION=$(VPS_VERSION)
make testdaemon
go test ./... -ldflags "-X main.Version=test" --cover
Expand Down
62 changes: 34 additions & 28 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"path"
Expand All @@ -26,25 +25,36 @@ type Client struct {
buildType string
buildFilePath string

out io.Writer

sshRunner SSHSession
verifySSL bool
}

// NewClient sets up a client to communicate to the daemon at
// the given named remote.
func NewClient(remoteName string, config *cfg.Config) (*Client, bool) {
func NewClient(remoteName string, config *cfg.Config, out ...io.Writer) (*Client, bool) {
remote, found := config.GetRemote(remoteName)
if !found {
return nil, false
}

var writer io.Writer
if len(out) > 0 {
writer = out[0]
} else {
writer = common.DevNull{}
}

return &Client{
RemoteVPS: remote,
version: config.Version,
project: config.Project,
buildType: config.BuildType,
buildFilePath: config.BuildFilePath,
sshRunner: NewSSHRunner(remote),

out: writer,
}, true
}

Expand All @@ -59,15 +69,15 @@ func (c *Client) SetSSLVerification(verify bool) {
// public-private key-pair. It outputs configuration information
// for the user.
func (c *Client) BootstrapRemote(repoName string) error {
println("Setting up remote \"" + c.Name + "\" at " + c.IP)
fmt.Fprintf(c.out, "Setting up remote %s at %s", c.Name, c.IP)

println(">> Step 1/4: Installing docker...")
fmt.Fprint(c.out, ">> Step 1/4: Installing docker...")
err := c.installDocker(c.sshRunner)
if err != nil {
return err
}

println("\n>> Step 2/4: Building deploy key...")
fmt.Fprint(c.out, "\n>> Step 2/4: Building deploy key...")
if err != nil {
return err
}
Expand All @@ -78,7 +88,7 @@ func (c *Client) BootstrapRemote(repoName string) error {

// This step needs to run before any other commands that rely on
// the daemon image, since the daemon is loaded here.
println("\n>> Step 3/4: Starting daemon...")
fmt.Fprint(c.out, "\n>> Step 3/4: Starting daemon...")
if err != nil {
return err
}
Expand All @@ -87,34 +97,34 @@ func (c *Client) BootstrapRemote(repoName string) error {
return err
}

println("\n>> Step 4/4: Fetching daemon API token...")
fmt.Fprint(c.out, "\n>> Step 4/4: Fetching daemon API token...")
token, err := c.getDaemonAPIToken(c.sshRunner, c.version)
if err != nil {
return err
}
c.Daemon.Token = token

println("\nInertia has been set up and daemon is running on remote!")
println("You may have to wait briefly for Inertia to set up some dependencies.")
fmt.Printf("Use 'inertia %s logs --stream' to check on the daemon's setup progress.\n\n", c.Name)
fmt.Fprint(c.out, "\nInertia has been set up and daemon is running on remote!")
fmt.Fprint(c.out, "You may have to wait briefly for Inertia to set up some dependencies.")
fmt.Fprintf(c.out, "Use 'inertia %s logs --stream' to check on the daemon's setup progress.\n\n", c.Name)

println("=============================\n")
fmt.Fprint(c.out, "=============================\n")

// Output deploy key to user.
println(">> GitHub Deploy Key (add to https://www.github.com/" + repoName + "/settings/keys/new): ")
println(pub.String())
fmt.Fprintf(c.out, ">> GitHub Deploy Key (add to https://www.github.com/%s/settings/keys/new): ", repoName)
fmt.Fprint(c.out, pub.String())

// Output Webhook url to user.
println(">> GitHub WebHook URL (add to https://www.github.com/" + repoName + "/settings/hooks/new): ")
println("WebHook Address: https://" + c.IP + ":" + c.Daemon.Port + "/webhook")
println("WebHook Secret: " + c.Daemon.WebHookSecret)
println(`Note that you will have to disable SSH verification in your webhook
fmt.Fprintf(c.out, ">> GitHub WebHook URL (add to https://www.github.com/%s/settings/hooks/new): ", repoName)
fmt.Fprintf(c.out, "WebHook Address: https://%s:%s/webhook", c.IP, c.Daemon.Port)
fmt.Fprint(c.out, "WebHook Secret: "+c.Daemon.WebHookSecret)
fmt.Fprint(c.out, `Note that you will have to disable SSH verification in your webhook
settings - Inertia uses self-signed certificates that GitHub won't
be able to verify.` + "\n")
be able to verify.`+"\n")

println(`Inertia daemon successfully deployed! Add your webhook url and deploy
fmt.Fprint(c.out, `Inertia daemon successfully deployed! Add your webhook url and deploy
key to enable continuous deployment.`)
fmt.Printf("Then run 'inertia %s up' to deploy your application.\n", c.Name)
fmt.Fprintf(c.out, "Then run 'inertia %s up' to deploy your application.\n", c.Name)

return nil
}
Expand All @@ -140,8 +150,7 @@ func (c *Client) DaemonDown() error {

_, stderr, err := c.sshRunner.Run(string(scriptBytes))
if err != nil {
println(stderr.String())
return err
return fmt.Errorf("daemon shutdown failed: %s: %s", err.Error(), stderr.String())
}

return nil
Expand All @@ -158,8 +167,7 @@ func (c *Client) installDocker(session SSHSession) error {
cmdStr := string(installDockerSh)
_, stderr, err := session.Run(cmdStr)
if err != nil {
println(stderr.String())
return err
return fmt.Errorf("docker installation: %s: %s", err.Error(), stderr.String())
}

return nil
Expand All @@ -177,8 +185,7 @@ func (c *Client) keyGen(session SSHSession) (*bytes.Buffer, error) {
result, stderr, err := session.Run(string(scriptBytes))

if err != nil {
log.Println(stderr.String())
return nil, err
return nil, fmt.Errorf("key generation failed: %s: %s", err.Error(), stderr.String())
}

return result, nil
Expand All @@ -195,8 +202,7 @@ func (c *Client) getDaemonAPIToken(session SSHSession, daemonVersion string) (st

stdout, stderr, err := session.Run(daemonCmdStr)
if err != nil {
log.Println(stderr.String())
return "", err
return "", fmt.Errorf("api token generation failed: %s: %s", err.Error(), stderr.String())
}

// There may be a newline, remove it.
Expand Down
4 changes: 4 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -47,6 +48,7 @@ func getMockClient(ts *httptest.Server) *Client {

return &Client{
RemoteVPS: mockRemote,
out: os.Stdout,
project: "test_project",
}
}
Expand All @@ -66,12 +68,14 @@ func getIntegrationClient(mockRunner *mockSSHRunner) *Client {
return &Client{
version: "test",
RemoteVPS: remote,
out: os.Stdout,
sshRunner: mockRunner,
}
}
return &Client{
version: "test",
RemoteVPS: remote,
out: os.Stdout,
sshRunner: NewSSHRunner(remote),
}
}
Expand Down

0 comments on commit fdb9cfd

Please sign in to comment.