Skip to content

Commit

Permalink
Merge pull request #175 from ubclaunchpad/rob/#134-logs-in-web
Browse files Browse the repository at this point in the history
Inertia Web: Logs
  • Loading branch information
bobheadxi authored Apr 28, 2018
2 parents 2a16368 + f81e5c4 commit c4f8ba0
Show file tree
Hide file tree
Showing 38 changed files with 790 additions and 326 deletions.
164 changes: 105 additions & 59 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing
# :books: Contributing

This document outlines key considerations and tips for anyone contributing to Inertia.

Expand All @@ -10,19 +10,29 @@ This document outlines key considerations and tips for anyone contributing to In

# Opening an Issue

Please do a quick search of past issues before opening a ticket. If working on a ticket, please assign it to yourself or leave a comment saying you are working on it. If you have decide to stop working on a ticket before it gets resolved, please un-assign yourself.
🎉 An issue, whether it be bugs, feature requests, or general feedback is welcome!

However, please do a quick search of past issues before opening a ticket. If you are working on a ticket, please assign it to yourself or leave a comment noting that you are working on it - similarly, if you decide to stop working on a ticket before it gets resolved, please un-assign yourself or leave a comment. This helps us keep track of which tickets are in progress.

# Submitting a Pull Request

👍 Contributions of any size are very much appreciated.

All pull requests should be connected to one or more issues. Please try to fill out the pull request template to the best of your ability and use a clear, descriptive title.

At the very least, all pull requests need to pass our Travis builds and receive an approval from a reviewer. Please include tests whenever possible.

Read on for a comprehensive guide on how to get started with Inertia's codebase!

# Development Tips

This section outlines the various tools available to help you get started developing Inertia. Run `make ls` to list all the Makefile shortcuts available.
👷 This section will walk you through Inertia's codebase, how to get a development environment set up, and outline the various tools available to help you out.

If you would like to contribute, feel free to comment on an issue or make one and open up a pull request!
Please free free to open up a ticket if any of these instructions are unclear or straight up do not work on your platform!

- [Setup](#setup)
- [Overview](#overview)
- [Testing Environment](#setting-up-a-testing-environment)

## Setup

Expand All @@ -32,69 +42,64 @@ First, [install Go](https://golang.org/doc/install#install) and grab Inertia's s
$> go get -u github.com/ubclaunchpad/inertia
```

We use [dep](https://github.com/golang/dep) for managing Golang dependencies, and [npm](https://www.npmjs.com) to manage dependencies for Inertia's React web app. Make sure both are installed before running the following commands.
If you are looking to contribute, you can then set your own fork as a remote:

```bash
$> make deps # Install all dependencies
$> make RELEASE=test # installs Inertia build tagged as "test"
$> inertia --version # check what version you have installed
$> git remote rename origin upstream # Set the official repo as you
# "upstream" so you can pull
# updates
$> git remote add origin https://github.com/$AMAZING_YOU/inertia.git
```

A build tagged as `test` allows you to use `make testdaemon` for local development. See the next section for more details.
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

Alternatively, you can manually edit `.inertia.toml` to use your desired daemon version - see the [Release Streams](#release-streams) documentation for more details.
Make sure all of the above are installed before running:

Note that if you install Inertia using these commands or any variation of `go install`, you may have to remove the binary using `go clean -i github.com/ubclaunchpad/inertia` to go back to using an Inertia CLI installed using Homebrew. To go back to a `go install`ed version of Inertia, you need to run `brew uninstall inertia`.

## Repository Structure

The codebase for the CLI is in the root directory. This code should only include the user interface - all client-based logic and functionality should go into the client.
```bash
$> make RELEASE=test # installs dependencies and an Inertia
# build tagged as "test" to gopath
$> inertia --version # check what version you have installed
```

### Client
A build tagged as `test` allows you to use `make testdaemon` for local development. See the next section for more details. Alternatively, you can manually edit `.inertia.toml` to use your desired daemon version - see the [Release Streams](#release-streams) documentation for more details.

The Inertia client manages all clientside functionality. The client codebase is in `client/`.
Note that if you install Inertia using these commands or any variation of `go install`, you may have to remove the binary using `go clean -i github.com/ubclaunchpad/inertia` to use an Inertia CLI installed using Homebrew. To go back to a `go install`ed version of Inertia, you need to run `brew uninstall inertia`.

### Daemon
## Overview

The Inertia daemon manages all serverside functionality. The daemon codebase is in `daemon/inertia`.
### CLI

### Inertia Web
The codebase for the CLI is in the root directory. This code should only include the CLI user interface - all client-based logic and functionality should go into the `client` package.

The Inertia Web application provides a web interface to manage an Inertia deployment. The web application codebase is in `daemon/web`.
### Client

## Testing and Locally Deploying
The Inertia client package manages all clientside functionality. The client codebase is in `./client/`.

You will need Docker installed and running to run the Inertia test suite, which includes a number of integration tests.
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:

```bash
$> make test-all # test against ubuntu:latest
$> make test-all VPS_OS=ubuntu VERSION=14.04 # test against ubuntu:14.04
$> make bootstrap
```

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

```bash
$> make testenv VPS_OS=ubuntu VERSION=16.04
# This defaults to ubuntu:lastest without args.
# Note the location of the key that is printed and use that when
# adding your local remote.
```
Then use your asset!

You can [SSH into this testvps container](https://bobheadxi.github.io/dockerception/#ssh-services-in-docker) and otherwise treat it just as you would treat a real VPS:
```go
shellScriptData, err := Asset("client/bootstrap/myshellscript.sh")
if err != nil {
log.Fatal("No asset with that name")
}

```bash
$> cd /path/to/my/dockercompose/project
$> inertia init
$> inertia remote add local
# PEM file: inertia/test/keys/id_rsa, User: 'root', Address: 0.0.0.0
$> inertia local init
$> inertia local status
// Optionally run shell script over SSH.
result, _ := remote.RunSSHCommand(string(shellScriptData))
```

The above steps will pull and use a daemon image from Docker Hub based on the version in your `.inertia.toml`.

### Daemon

The Inertia daemon package manages all serverside functionality. The daemon codebase is in `./daemon/inertia/`.

To use a daemon compiled from source, set your Inertia version in `.inertia.toml` to `test` and run:

```bash
Expand All @@ -121,38 +126,79 @@ You probably need to go into your Docker settings and add this line to the Docke

This sneaky configuration file can be found under `Docker -> Preferences -> Daemon -> Advanced -> Edit File`.

### Web App
### Web

Inertia Web provides a web interface to manage an Inertia deployment. The web application codebase is in `./daemon/web/`.

Inertia Web is a React application. To run a local instance of Inertia Web:
To run a local instance of Inertia Web:

```bash
$> make web-run
$> make web-deps # install npm dependencies
$> make web-run # run local instance of application
```

Make sure you have a local daemon set up for this web app to work - see the previous section for more details.

## Compiling Bash Scripts
## Setting up a Testing Environment

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.
You will need Docker installed and running to run whole the Inertia test suite, which includes a number of integration tests.

```bash
$> go get -u github.com/jteeuwen/go-bindata/...
$> make test-all # test against ubuntu:latest
$> make test-all VPS_OS=ubuntu VERSION=14.04 # test against ubuntu:14.04
```

If you make changes to the bootstrapping shell scripts in `client/bootstrap/`, convert them to `Assets` by running:
Alternatively, `make test` will just run the unit tests.

Setting up a more comprehensive test environment, where you take a project from setup to deployment using Inertia, is a bit trickier - these are the recommended steps:

1. **Manually set up a mock VPS**

```bash
$> make bootstrap
$> make testenv VPS_OS=ubuntu VERSION=16.04
# This defaults to ubuntu:lastest without args.
# Note the location of the key that is printed and use that when
# adding your local remote.
```

Then use your asset!
You can [SSH into this testvps container](https://bobheadxi.github.io/dockerception/#ssh-services-in-docker) and otherwise treat it just as you would treat a real VPS.

```go
shellScriptData, err := Asset("cmd/bootstrap/myshellscript.sh")
if err != nil {
log.Fatal("No asset with that name")
}
2. **Compile and install Inertia**

// Optionally run shell script over SSH.
result, _ := remote.RunSSHCommand(string(shellScriptData))
```bash
$> make RELEASE=test
```

3. **Build and deliver Inertia daemon to the `testvps`**

```bash
$> make testdaemon
```

4. **Set up a test project**

You will need a GitHub repository you own, since you need permission to add deploy keys. The Inertia team typically uses the [inertia-deploy-test](https://github.com/ubclaunchpad/inertia-deploy-test) repository - you could just fork this repository.

```bash
$> git clone https://github.com/$AWESOME_YOU/inertia-deploy-test.git
$> cd inertia-deploy-test
$> inertia init
$> inertia remote add local
# - PEM file: $INERTIA_PATH/test/keys/id_rsa
# - Address: 127.0.0.1
# - User: root
$> inertia local init
$> inertia local status
```

The above steps will pull and use a daemon image from Docker Hub based on the version in your `.inertia.toml`.

Following these steps, you can run Inertia through deployment:

```bash
$> inertia local up --stream
$> inertia local status
$> inertia local logs
```

Please free free to open up an Issue if any of these steps are no clear or don't work!
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ before_install:
script:
- make testenv VPS_OS="$VPS_OS" VPS_VERSION="$VERSION" SSH_PORT=69
- make testdaemon SSH_PORT=69 # Send test daemon to testVPS
- go test -v -race -coverprofile=coverage.out ./... # Execute tests
- go test -race -coverprofile=coverage.out ./... # Execute tests
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken "$COVERALLS_TOKEN"
- make lint # Static code analysis

Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ RUN npm run build

### Part 2 - Building the Inertia daemon
FROM golang:alpine AS daemon-build-env
ENV BUILD_HOME=/go/src/github.com/ubclaunchpad/inertia
ARG INERTIA_VERSION
ENV BUILD_HOME=/go/src/github.com/ubclaunchpad/inertia \
INERTIA_VERSION=${INERTIA_VERSION}
# Mount source code.
ADD . ${BUILD_HOME}
WORKDIR ${BUILD_HOME}
# Install dependencies if not already available.
RUN apk add --update --no-cache git
RUN if [ ! -d "vendor" ]; then \
apk add --update --no-cache git; \
go get -u github.com/golang/dep/cmd/dep; \
dep ensure; \
fi
# Build daemon binary.
RUN go build -o /bin/inertia \
-ldflags "-X main.Version=$(git describe --tags)" \
-ldflags "-X main.Version=$INERTIA_VERSION" \
./daemon/inertia

### Part 3 - Copy builds into combined image
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ VPS_VERSION = latest
VPS_OS = ubuntu
RELEASE = canary

all: inertia
all: deps bootstrap inertia

# List all commands
ls:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

# Sets up all dependencies
deps:
go get -u github.com/jteeuwen/go-bindata/...
dep ensure
make web-deps
bash test/deps.sh
Expand Down Expand Up @@ -74,7 +75,8 @@ testenv:
# Requires Inertia version to be "test"
testdaemon:
rm -f ./inertia-daemon-image
docker build -t ubclaunchpad/inertia:test .
docker build --build-arg INERTIA_VERSION=$(TAG) \
-t ubclaunchpad/inertia:test .
docker save -o ./inertia-daemon-image ubclaunchpad/inertia:test
docker rmi ubclaunchpad/inertia:test
chmod 400 ./test/keys/id_rsa
Expand All @@ -89,7 +91,8 @@ testdaemon:
# Creates a daemon release and pushes it to Docker Hub repository.
# Requires access to the UBC Launch Pad Docker Hub.
daemon:
docker build -t ubclaunchpad/inertia:$(RELEASE) .
docker build --build-arg INERTIA_VERSION=$(RELEASE) \
-t ubclaunchpad/inertia:$(RELEASE) .
docker push ubclaunchpad/inertia:$(RELEASE)

# Recompiles assets. Use whenever a script in client/bootstrap is
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ Inertia is a simple cross-platform command line application that enables effortl
----|-----------------
🚀 | Simple setup from your computer without ever having to manually SSH into your remote
🍰 | Use any Linux-based remote virtual private server platform you want
⚒ | Deploy a wide range of supported project types (including docker-compose and Heroku buildpacks)
🚄 | Have your project automatically updated as soon as you `git push`
🛂 | Start up and shut down your deployment with ease
📚 | Monitor your deployed application's logs straight from your command line
⚒ | Deploy a wide range of supported project types (including Dockerfile, docker-compose, and Heroku projects)
🚄 | Have your project automatically updated, rebuilt, and deployed as soon as you `git push`
🛂 | Start up, shut down, and monitor your deployment with ease
🏷 | Configure deployment to your liking with branch settings and more
🌐 | Add users and check on your deployment anywhere through Inertia Web
🔑 | Secured with tokens and HTTPS across the board

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

Expand Down Expand Up @@ -101,13 +102,15 @@ $> inertia $VPS_NAME up --stream

Run `inertia $VPS_NAME --help` to see the other commands Inertia offers for managing your deployment.

Inertia also offers a web application - this can be accessed at `https://$ADDRESS:8081/web` once users have been added through the `inertia $VPS_NAME user` commands.

## Continuous Deployment

To enable continuous deployment, you need the webhook URL that is printed during `inertia $VPS_NAME init`:

```bash
GitHub WebHook URL (add here https://www.github.com/<your_repo>/settings/hooks/new):
http://myhost.com:8081
http://myhost.com:8081/webhook
Github WebHook Secret: inertia
```

Expand Down Expand Up @@ -160,9 +163,11 @@ The deployment daemon runs persistently in the background on the server, receivi
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)
- [UBC Launch Pad internal demo](https://drive.google.com/file/d/1foO57l6egbaQ7I5zIDDe019XOgJm-ocn/view?usp=sharing)
- [Vancouver DevOpsDays 2018](https://docs.google.com/presentation/d/e/2PACX-1vRJXUnRmxpegHNVTgn_Kd8VFyeuiIwzDQl9c0oQqi1QSnIjFUIIjawsvLdu2RfHAXv_5T8kvSgSWGuq/pub?start=false&loop=false&delayms=15000) ([video](https://youtu.be/amBYMEKGzTs?t=4h59m5s))

# :books: Contributing

Any contribution (pull requests, feedback, bug reports, ideas, etc.) is welcome! Please see our [contribution guide](https://github.com/ubclaunchpad/inertia/blob/master/.github/CONTRIBUTING.md) for more details and development tips.
Any contribution (pull requests, feedback, bug reports, ideas, etc.) is welcome!

Please see our [contribution guide](https://github.com/ubclaunchpad/inertia/blob/master/.github/CONTRIBUTING.md) for contribution guidelines and a detailed guide to help you get started with Inertia's codebase.
Loading

0 comments on commit c4f8ba0

Please sign in to comment.