Skip to content

Commit

Permalink
Merge pull request #71 from ubclaunchpad/rob/#23-dockerize-testenv
Browse files Browse the repository at this point in the history
Simple dockerized test environment
  • Loading branch information
bobheadxi committed Feb 10, 2018
2 parents 8d64174 + 40a1933 commit 8203900
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 115 deletions.
17 changes: 16 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ go:

install: true

services:
- docker

# Test different VPS platforms we want to support
env:
- VPS_OS=ubuntu VERSION=16.04
- VPS_OS=ubuntu VERSION=14.04
- VPS_OS=centos VERSION=7
- VPS_OS=ubuntu VERSION=latest
- VPS_OS=centos VERSION=latest

matrix:
# It's ok if our code fails on unstable development versions of Go.
# It's ok if our code fails on unstable development versions of Go
# and/or VPS platforms (VERSION=latest)
allow_failures:
- go: master
- env: VPS_OS=ubuntu VERSION=latest
- env: VPS_OS=centos VERSION=latest
# Don't wait for tip tests to finish. Mark the test run green if the
# tests pass on the stable versions of Go.
fast_finish: true
Expand All @@ -26,6 +40,7 @@ before_script:
- go get github.com/mattn/goveralls
- go get -u github.com/golang/dep/cmd/dep
- dep ensure
- make testenv-"$VPS_OS" VERSION="$VERSION" SSH_PORT=69

# script always run to completion (set +e).
script:
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.

8 changes: 0 additions & 8 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
branch = "master"
name = "github.com/google/go-github"

[[constraint]]
branch = "master"
name = "github.com/bramvdbogaerde/go-scp"

[[constraint]]
name = "gopkg.in/sourcegraph/go-vcsurl.v1"
version = "1.0.0"

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
.PHONY: test test-verbose test-profile test-race clean docker bootstrap
.PHONY: test test-verbose test-profile testenv-ubuntu clean docker bootstrap

PACKAGES = `go list ./... | grep -v vendor/`
SSH_PORT = 22
VERSION = latest
VPS_OS = ubuntu

all: inertia

inertia:
go build

test:
make testenv-$(VPS_OS) VERSION=$(VERSION)
go test $(PACKAGES) --cover

test-verbose:
make testenv-$(VPS_OS) VERSION=$(VERSION)
go test $(PACKAGES) -v --cover

test-race:
go test $(PACKAGES) -race --cover
testenv-ubuntu:
docker stop testvps || true && docker rm testvps || true
docker build -f ./test_env/Dockerfile.ubuntu \
-t ubuntuvps \
--build-arg VERSION=$(VERSION) \
./test_env
bash ./test_env/startvps.sh $(SSH_PORT) ubuntuvps

testenv-centos:
docker stop testvps || true && docker rm testvps || true
docker build -f ./test_env/Dockerfile.centos \
-t centosvps \
--build-arg VERSION=$(VERSION) \
./test_env
bash ./test_env/startvps.sh $(SSH_PORT) centosvps

clean: inertia
rm -f inertia
Expand Down
132 changes: 75 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
# 👩‍🚀 Inertia
<p>
<h1 align="center"> 👩‍🚀 Inertia </h1>
</p>

Inertia makes it easy to set up automated deployment for Dockerized
applications.
<p align="center">
Simple, self-hosted continuous deployment.
</p>

[![Build Status](https://travis-ci.org/ubclaunchpad/inertia.svg?branch=master)](https://travis-ci.org/ubclaunchpad/inertia)[![Coverage Status](https://coveralls.io/repos/github/ubclaunchpad/inertia/badge.svg?branch=master)](https://coveralls.io/github/ubclaunchpad/inertia?branch=master)
<p align="center">
<a href="https://travis-ci.org/ubclaunchpad/inertia">
<img src="https://travis-ci.org/ubclaunchpad/inertia.svg?branch=master"
alt="Built Status" />
</a>

<a href="https://coveralls.io/github/ubclaunchpad/inertia?branch=master">
<img src="https://coveralls.io/repos/github/ubclaunchpad/inertia/badge.svg?branch=master"
alt="Coverage Status" />
</a>

<a href="">
<img src="https://img.shields.io/badge/Shipping_faster_with-ZenHub-5e60ba.svg?style=flat" alt="We use Zenhub!" />
</a>
</p>

<p align="center">
<img src="https://img.shields.io/badge/Supported%20VPS%20platforms-Ubuntu%2014.04%2F16.04%20%7C%20CentOS%207-blue.svg" />
</p>

----------------

Inertia is a cross-platform command line tool that aims to simplify setup and management of automated deployment for docker-compose projects on any virtual private server.

## Installation

```bash
go get -u github.com/ubclauncpad/inertia
go get -u github.com/ubclaunchpad/inertia
```

Alternatively, you can download Inertia from the [Releases](https://github.com/ubclaunchpad/inertia/releases) page.
Alternatively, you can download Inertia executables from the [Releases](https://github.com/ubclaunchpad/inertia/releases) page.

## Usage

Inside of a git repository, run the following:
Inside of a git repository, simply running the following commands to initialize Inertia and add a remote VPS:

```bash
$> inertia init
Expand All @@ -33,7 +58,11 @@ Run this 'inertia remote add' with the -p flag to set a custom port.
Remote 'gcloud' has been added!
You can now run 'inertia gcloud init' to set this remote up
for continuous deployment.
```

After adding a remote, you can now bring the Inertia daemon online:

```bash
$> inertia gcloud init
Bootstrapping remote
Installing docker
Expand All @@ -56,18 +85,14 @@ $> inertia remote status gcloud
Remote instance 'gcloud' accepting requests at http://myhost.com:8081
```

A daemon is now running on your remote instance - but your application is not yet
continuously deployed.
A daemon is now running on your remote instance - but your application is not yet continuously deployed.

The output of `inertia [REMOTE] init` has given you two important pieces of information:

1. A deploy key. The Inertia daemon requires readonly access to your GitHub repository.
Add it to your GitHub repository settings at the URL provided in the output.
2. A GitHub webhook URL. The daemon will accept POST requests from GitHub at the URL
provided. Again, add this webhook URL in your GitHub settings area (at the URL
provided).
1. A deploy key. The Inertia daemon requires readonly access to your GitHub repository. Add it to your GitHub repository settings at the URL provided in the output.
2. A GitHub webhook URL. The daemon will accept POST requests from GitHub at the URL provided. Again, add this webhook URL in your GitHub settings area (at the URL provided).

After adding these pieces of information to your GitHub settings,
After adding these pieces of information to your GitHub settings, the Inertia daemon will automatically deploy any changes you make to your repository's default branch. You can also manually manage your project's deployment through the CLI:

```bash
$> inertia gcloud up
Expand All @@ -89,42 +114,32 @@ $> inertia gcloud down

### Dependencies

We use [dep](https://github.com/golang/dep) for managing dependencies. Install
that first if you haven't already.

```
brew install dep
```

Install project dependencies.
We use [dep](https://github.com/golang/dep) for managing dependencies.

```bash
dep ensure
$> brew install dep
$> dep ensure
```

### Bootstrapping
### Compiling Bash Scripts

To bootstrap servers, often some bash scripting is involved,
but we'd like to avoid shipping bash scripts with our go binary.
So we use [go-bindata](https://github.com/jteeuwen/go-bindata) to
compile shell scripts into our go executables.
To bootstrap servers, some bash scripting is often involved, but we'd like to avoid shipping bash scripts with our go binary. So we use [go-bindata](https://github.com/jteeuwen/go-bindata) to compile shell scripts into our go executables.

```bash
go get -u github.com/jteeuwen/go-bindata/...
$> go get -u github.com/jteeuwen/go-bindata/...
```

If you make changes to the bootstrapping shell scripts in
`client/bootstrap/`, convert them to `Assets` by running.
`client/bootstrap/`, convert them to `Assets` by running:

```bash
make bootstrap
$> make bootstrap
```

Then use your asset!

```go
shellScriptData, err := Asset("cmd/bootstrap/myshellscript.sh")

if err != nil {
log.Fatal("No asset with that name")
}
Expand All @@ -136,38 +151,41 @@ result, _ := remote.RunSSHCommand(string(shellScriptData))
### Testing

```bash
make test
$> make test # test against ubuntu:latest
$> make test VPS_OS=ubuntu VERSION=14:04 # test against ubuntu:14.04
```

## Motivation
You can also start a container that sets up a mock VPS for testing:

At Launch Pad we are frequently changing hosting providers based on available
funding and sponsorship. Inertia is a project to develop an in-house continuous
deployment system to make deploying applications simple and painless, regardless
of the hosting provider.
```bash
$> go install
$> make testenv-ubuntu
# note the location of the key that is printed
```

## Design
You can treat this container just as you would treat a real VPS:

Inertia will contain two major components:
```bash
$> cd /path/to/my/dockercompose/project
$> inertia init
$> inertia remote add local
# PEM file: /test_env/test_key, User: 'root', Address: 0.0.0.0
$> inertia local init
$> inertia remote status local
Remote instance 'local' accepting requests at http://0.0.0.0:8081
```

* Deployment daemon
* Command line interface
### Motivation and Design

At Launch Pad we are frequently changing hosting providers based on available funding and sponsorship. Inertia is a project to develop an in-house continuous deployment system to make deploying applications simple and painless, regardless of the hosting provider.

The deployment daemon will run persistently in the background, receiving webhook
events from GitHub whenever new commits are pushed. The CLI will provide an
interface to adjust settings, add repositories, etc.
Inertia contains two major components:

This design differs from other similar tools because Inertia runs on the same
server as the project it is deploying.
* Deployment daemon
* Command line interface

## Setup
The deployment daemon will run persistently in the background, receiving webhook events from GitHub whenever new commits are pushed. The CLI will provide an interface to adjust settings, add repositories, etc.

A primary design goal of Inertia is to minimize setup time for new projects. The
current setup flow is:
This design differs from other similar tools because Inertia runs on the same server as the project it is deploying.

* Install and run Inertia on a new server
* Inertia will generate:
* A SSH public key
* A webhook URL and secret
* Add the SSH key to your project's Deploy Keys on GitHub
* Create a webhook with the URL and secret on your project repository
Another primary design goal of Inertia is to minimize setup time for new projects and maximize compatibility across different client and VPS platforms.
12 changes: 6 additions & 6 deletions client/bootstrap.go

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

2 changes: 2 additions & 0 deletions client/bootstrap/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ if !(hash docker 2>/dev/null); then
sh $DOCKER_DEST
fi
fi

sudo service docker start
8 changes: 4 additions & 4 deletions client/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func getMockDeployment(ts *httptest.Server, s *memory.Storage) (*Deployment, err
url := strings.Trim(wholeURL[1], "/")
port := wholeURL[2]
mockRemote := &RemoteVPS{
User: "",
IP: url,
PEM: "",
Port: port,
User: "",
IP: url,
PEM: "",
DaemonPort: port,
}
mockRepo, err := git.Init(s, nil)
if err != nil {
Expand Down
Loading

0 comments on commit 8203900

Please sign in to comment.