Skip to content

Commit

Permalink
Merge pull request #171 from ubclaunchpad/rob/#152-docker-and-staged-…
Browse files Browse the repository at this point in the history
…docker-compose

Dockerfile builds and staged docker-compose
  • Loading branch information
bobheadxi committed Apr 21, 2018
2 parents 793fd60 + fe50c72 commit 2a16368
Show file tree
Hide file tree
Showing 46 changed files with 1,504 additions and 1,234 deletions.
10 changes: 8 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ test
# Documentation
*.md

# All hidden folders
.*
# All hidden things
.github
.scripts
.static
.dockerignore
.travis.yml
.eslintrc
.gometalinter.json

# Non-daemon source code
client
Expand Down
1 change: 0 additions & 1 deletion .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"misspell",
"gofmt",
"goimports",
"gosimple",
"vet"
],
"Exclude": [
Expand Down
2 changes: 1 addition & 1 deletion .scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
go get -u github.com/mitchellh/gox

# Specify platforms and release version
PLATFORMS="linux/amd64 linux/386 darwin/amd64 darwin/386 windows/amd64 windows/386"
PLATFORMS="linux/amd64 linux/386 darwin/386 windows/amd64 windows/386"
RELEASE=$(git describe --tags)
echo "Building release $RELEASE"

Expand Down
Binary file removed .static/inertia-v0-0-2-slides.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ script:
- go test -v -race -coverprofile=coverage.out ./... # Execute tests
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken "$COVERALLS_TOKEN"
- make lint # Static code analysis
- docker kill $(docker ps -q) # Remove testvps, etc

# Push version-tagged Docker image and build platform binaries
before_deploy:
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
version = "4.2.0"
version = "4.3.1"

[[constraint]]
name = "github.com/google/go-github"
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ ls:

# Sets up all dependencies
deps:
curl -sfL https://install.goreleaser.com/github.com/alecthomas/gometalinter.sh | bash
dep ensure
make web-deps
bash test/deps.sh

# Install Inertia with release version
inertia:
Expand All @@ -32,7 +32,7 @@ clean:
find . -type f -name inertia.\* -exec rm {} \;

lint:
PATH=$(PATH):./bin bash -c './bin/gometalinter --vendor ./...'
PATH=$(PATH):./bin bash -c './bin/gometalinter --vendor --deadline=60s ./...'

# Run unit test suite
test:
Expand Down Expand Up @@ -64,11 +64,11 @@ test-integration-fast:
# Create test VPS
testenv:
docker stop testvps || true && docker rm testvps || true
docker build -f ./test/env/Dockerfile.$(VPS_OS) \
docker build -f ./test/vps/Dockerfile.$(VPS_OS) \
-t $(VPS_OS)vps \
--build-arg VERSION=$(VPS_VERSION) \
./test
bash ./test/env/startvps.sh $(SSH_PORT) $(VPS_OS)vps
bash ./test/start_vps.sh $(SSH_PORT) $(VPS_OS)vps

# Create test daemon and scp the image to the test VPS for use.
# Requires Inertia version to be "test"
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ The primary design goals of Inertia are to:

Inertia consists of two major components: a deployment daemon and a command line interface.

The deployment daemon runs persistently in the background on the server, receiving webhook events from GitHub whenever new commits are pushed. The CLI provides an interface to adjust settings and manage the deployment - this is done through requests to the daemon, authenticated using JSON web tokens generated by the daemon. Remote configuration is stored locally in `.inertia.toml`.
The deployment daemon runs persistently in the background on the server, receiving webhook events from GitHub whenever new commits are pushed. The CLI provides an interface to adjust settings and manage the deployment - this is done through HTTPS requests to the daemon, authenticated using JSON web tokens generated by the daemon. Remote configuration is stored locally in `.inertia.toml`.

<p align="center">
<img src="https://bobheadxi.github.io/assets/images/posts/inertia-diagram.png" width="70%" />
<img src="https://bobheadxi.github.io/assets/images/posts/inertia-diagram.png" width="70%" />
</p>

Inertia is set up serverside by executing a script over SSH that installs Docker and starts an Inertia daemon image with [access to the host Docker socket](https://bobheadxi.github.io/dockerception/#docker-in-docker). This Docker-in-Docker configuration gives the daemon the ability to start up other containers *alongside* it, rather than *within* it, as required. Once the daemon is set up, we avoid using further SSH commands and execute Docker commands through Docker's Golang API. Instead of installing the docker-compose toolset, we [use a docker-compose image](https://bobheadxi.github.io/dockerception/#docker-compose-in-docker) to build and deploy user projects.
Inertia is set up serverside by executing a script over SSH that installs Docker and starts an Inertia daemon image with [access to the host Docker socket](https://bobheadxi.github.io/dockerception/#docker-in-docker). This Docker-in-Docker configuration gives the daemon the ability to start up other containers *alongside* it, rather than *within* it, as required. Once the daemon is set up, we avoid using further SSH commands and execute Docker commands through Docker's Golang API. Instead of installing the docker-compose toolset, we [use a docker-compose image](https://bobheadxi.github.io/dockerception/#docker-compose-in-docker) to build and deploy user projects. Inertia also supports projects configured for Heroku buildpacks using the [gliderlabs/herokuish](https://github.com/gliderlabs/herokuish) Docker image for builds and deployments.

The team has made a few presentations about Inertia that go over its design in a bit more detail:
- [First UBC Launch Pad internal demo](https://drive.google.com/file/d/1foO57l6egbaQ7I5zIDDe019XOgJm-ocn/view?usp=sharing)
- [Vancouver DevOpsDays 2018: Building a Simple, Self-hosted Continuous Deployment Application](https://drive.google.com/open?id=1DV2NR_YXpUZai-S7ttGcwrhWJXL7BcwiIrBJn69-IJg)

# :books: Contributing

Expand Down
6 changes: 6 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Client

[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/ubclaunchpad/inertia/client)

This package contains Inertia's clientside configuration and interface to remote Inertia daemons.

28 changes: 14 additions & 14 deletions client/bootstrap.go

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

2 changes: 1 addition & 1 deletion client/bootstrap/daemon-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ CONTAINER_PORT=8081

# Set up directories.
mkdir -p $HOME/project
mkdir -p $HOME/ssl
mkdir -p $HOME/.inertia
mkdir -p $HOME/.inertia/.ssl

# Check if already running and take down existing daemon.
ALREADY_RUNNING=`sudo docker ps -q --filter "name=$DAEMON_NAME"`
Expand Down
9 changes: 8 additions & 1 deletion client/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"path"
"strings"

"github.com/ubclaunchpad/inertia/common"
git "gopkg.in/src-d/go-git.v4"
Expand Down Expand Up @@ -84,7 +86,12 @@ func (d *Deployment) Down() (*http.Response, error) {

// Status lists the currently active containers on the remote VPS instance
func (d *Deployment) Status() (*http.Response, error) {
return d.request("GET", "/status", nil)
resp, err := d.request("GET", "/status", nil)
if err != nil &&
(strings.Contains(err.Error(), "EOF") || strings.Contains(err.Error(), "refused")) {
return nil, fmt.Errorf("daemon on remote %s appears offline or inaccessible", d.Name)
}
return resp, err
}

// Reset shuts down deployment and deletes the contents of the deployment's
Expand Down
27 changes: 24 additions & 3 deletions client/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ var (
)

func getMockDeployment(ts *httptest.Server, s *memory.Storage) (*Deployment, error) {
wholeURL := strings.Split(ts.URL, ":")
url := strings.Trim(wholeURL[1], "/")
port := wholeURL[2]
var (
url string
port string
)
if ts != nil {
wholeURL := strings.Split(ts.URL, ":")
url = strings.Trim(wholeURL[1], "/")
port = wholeURL[2]
} else {
url = "0.0.0.0"
port = "8080"
}

mockRemote := &RemoteVPS{
User: "",
IP: url,
Expand Down Expand Up @@ -145,6 +155,17 @@ func TestStatus(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestStatusFail(t *testing.T) {
memory := memory.NewStorage()
defer func() { memory = nil }()

d, err := getMockDeployment(nil, memory)
assert.Nil(t, err)

_, err = d.Status()
assert.Contains(t, err.Error(), "appears offline")
}

func TestReset(t *testing.T) {
testServer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
Expand Down
5 changes: 5 additions & 0 deletions common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Common

[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/ubclaunchpad/inertia/common)

This package contains utility functions and things shared by both the client and the daemon, such as request structs.
Loading

0 comments on commit 2a16368

Please sign in to comment.