Skip to content

Commit

Permalink
import code
Browse files Browse the repository at this point in the history
  • Loading branch information
trevj committed Mar 14, 2018
1 parent 75c938e commit c44d9f2
Show file tree
Hide file tree
Showing 168 changed files with 20,089 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
ColumnLimit: 100
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
**/bower_components
/build
/node_modules/
/src/metrics_server/node_modules/
/src/server_manager/node_modules/
/src/server_manager/install_scripts/do_install_script.ts
yarn-error.log
135 changes: 135 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
language: node_js

node_js:
- "8"

cache:
yarn: true
directories:
- $HOME/.cache/bower
- $HOME/.cache/electron
- $HOME/.cache/electron-builder

before_install:
# https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-supports-yarn
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.3.2
- export PATH="$HOME/.yarn/bin:$PATH"

stages:
- build and unit test
- integration test
- name: tag
if: type = cron
- name: deploy
if: tag =~ ^daily
- name: release
if: tag =~ ^v[0-9]

# Stages with the same name define multiple jobs which run in parallel.
# To make it more apparent in the Travis UI exactly what each job is
# doing, we add a descriptive environment variable.
jobs:
include:
# Ideally, we would split this stage in some way, e.g. by component or by
# build/test commands, to make it clearer in the Travis UI exactly which
# command failed. However, since each stage incurs a significantly start-up
# cost, we combine test and build commands for all components into one fast
# stage.
- stage: build and unit test
script:
- yarn shadowbox_install
- yarn do shadowbox/server/build
- yarn do shadowbox/test
- yarn do server_manager/electron_app/build
- yarn do server_manager/web_app/build
- yarn do server_manager/web_app/test

- stage: integration test
sudo: required
services: docker
script:
# https://docs.travis-ci.com/user/docker/
- |
sudo rm -f /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-$(uname -s)-$(uname -m) > docker-compose
chmod +x docker-compose
sudo mv docker-compose /usr/local/bin
- yarn shadowbox_install
- yarn do shadowbox/integration_test/run

- stage: tag
script:
- RELEASE_NAME=daily-$(date -I)
- curl --data '{"tag_name":"'$RELEASE_NAME'","name":"'$RELEASE_NAME'","prerelease":true}' https://api.github.com/repos/Jigsaw-Code/outline-server/releases?access_token=$CI_USER_TOKEN

- stage: deploy
env:
- DESC=shadowbox docker image
sudo: required
services: docker
script:
- yarn shadowbox_install
- yarn do shadowbox/docker/build
- docker login quay.io -u="$QUAY_IO_USERNAME" -p="$QUAY_IO_PASSWORD"
- docker tag outline/shadowbox quay.io/outline/shadowbox:$TRAVIS_TAG
- docker push quay.io/outline/shadowbox:$TRAVIS_TAG
- docker tag outline/shadowbox quay.io/outline/shadowbox:daily
- docker push quay.io/outline/shadowbox:daily

- stage: deploy
env:
- DESC=linux manager
addons:
apt:
packages:
- rpm
script: yarn do server_manager/electron_app/package_linux

# https://www.electron.build/multi-platform-build
- stage: deploy
env:
- DESC=windows manager
sudo: required
services: docker
script:
- yarn do server_manager/electron_app/build
- docker pull electronuserland/builder:wine
- docker run --rm
-v ${PWD}:/project
-v ~/.cache/electron:/root/.cache/electron
-v ~/.cache/electron-builder:/root/.cache/electron-builder
electronuserland/builder:wine
/bin/bash -c "yarn do server_manager/electron_app/package_only_windows" || travis_terminate $?

- stage: deploy
env:
- DESC=macos manager
os: osx
script: yarn do server_manager/electron_app/package_macos

# Note that because we cannot currently build signed macOS or Windows
# binaries on Travis, those builds must be manually built and uploaded
# to the release page.
- stage: release
env:
- DESC=linux manager
addons:
apt:
packages:
- rpm
script: yarn do server_manager/electron_app/release_linux

deploy:
provider: releases
api_key:
secure: "a7JJwbwgWQpXAaGCKbMf/HySyhiBOPeyjZZkSeZBECpqS671j6rbZ2MHvXp7QfU3LZ+Z7MYwkl/DTgbdOZ8ndbwWMn5yJjeIBnreQqZlbyR5jh1G66vu+r55aBxd6+svGp2VynGlWLI+1+4L6U33VHNXnkH6D7fwSKze1glu1XqeUzUkNEPRkWCg/Y6/WGMh19yOgoxulN3mTL65s5FzFpXKdDT7F8J6BPzoz5cWXTMiZM+fs0BjTIfNNabkIWdRvVFJ5s2Cx3EJM0BU1NDRVxGeYJsvli/gkYW82ZTeQdXfn9KQxAK1n6lQsUQJUnErH6jSfrv6QJkSnnKjVogXcP/SSj0p73UAcZuUZ7hRW/TX0HAtgCxnY7dkMaxyBHiNwxprSm4+83VRHIALzUqmcJ28b6VvXo1znD3r9frDsY5PuNAmew3VbpQyxit515tZRpiRXzzSnrFqAovWl6wY0UIkQEFLpi18PGOhUFcewKBpN4W4PszGvWkPgdPNBq5nizUtaHX62lPFoPjGkhcunD4Tn9RIrUcbRTfWVokI5qT8oLZM3mgBS8H85N80ngq1tQBUCJ1Xfd3vqJ+xE0x6boIzYHs4cz0Qoao1vmo1wsycRhr1PAqvtBztAkq+pwOwd9qI9VL8QCJErHBd56I3jkPTsPgMx8K3M8N4/EtOsA0="
file_glob: true
file: "build/server_manager/electron_app/static/dist/*.*"
skip_cleanup: true
on:
tags: true

env:
global:
- ELECTRON_CACHE=$HOME/.cache/electron
- ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# How to Contribute

We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement. You (or your employer) retain the copyright to your contribution,
this simply gives us permission to use and redistribute your contributions as
part of the project. Head over to <https://cla.developers.google.com/> to see
your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
117 changes: 115 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,115 @@
# outline-server
Create and manage access to Outline servers
# Outline Server Creator

[![Build Status](https://travis-ci.com/Jigsaw-Code/outline-server.svg?token=HiP4RTme8LSvyrP9kNJq&branch=master)](https://travis-ci.com/Jigsaw-Code/outline-server)

This repository has all the code needed to create and manage Outline servers on DigitalOcean. An Outline server runs
instances of Shadowsocks proxies and provides an API used by the Outline Manager application.


## Components

The system comprises the following components:

- **Server Manager Electron App:** an Election application that wraps the Server Manager web application and runs
natively on Desktop. It adds some extra functionality, like validation of the server self-signed certificate and interception of the DigitalOcean registration flow.

Code: `src/server_manager/electron_app`
- **Proxy Server**: a server that runs the Shadowsocks instances and a REST API to manage its users. Used as backend by the
Server Manager app.

Code: `src/shadowbox`

## Server Manager

### Setup

Ensure you have the following installed:
- [Node](https://nodejs.org/)
- [Yarn](https://yarnpkg.com/en/docs/install)
- [Wine](https://www.winehq.org/download), if you would like to generate binaries for Windows.

Install dependencies:
```
yarn
```

### Electron App

To run the electron app:
```
yarn do server_manager/electron_app/run
```

To build the app for all platforms:
```
yarn do server_manager/electron_app/package
```

The per-platform standalone apps will be at `build/electron_app/bundled`.

The per-platform standalone apps packaged for distribution will be at
`build/electron_app/packaged` in the following formats:

- Windows: zip files. Only generated if you have [wine](https://www.winehq.org/download) installed.
- Linux: tar.gz files.
- macOS: dmg files if built from macOS, zip files otherwise.

To perform a release, use
```
yarn do server_manager/electron_app/release
```

This will perform a clean and reinstall all dependencies to make sure the build is not tainted.


## Proxy Server

See [`src/shadowbox/README.md`](src/shadowbox/README.md).

## Unit Tests

To run all the tests, run `yarn test`


## Build System

We have a very simple build system based on package.json scripts that are called called using `yarn`
and a thin wrapper for what we call build "actions".

We've defined a `do` package.json script that takes an `action` parameter:
```shell
yarn do $ACTION
```

This command will define a `do_action()` function and call `${ACTION}_action.sh`, which must exist.
The called action script can use `do_action` to call its dependencies. The $ACTION parameter is
always resolved from the project root, regardless of the caller location.

The idea of `do_action` is to keep the build logic next to where the relevant code is.
It also defines two environmental variables:

- ROOT_DIR: the root directory of the project, as an absolute path.
- BUILD_DIR: where the build output should go, as an absolute path.

### Build output

Building creates the following directories under `build/`:
- `web_app/`: The Manager web app.
- `static/`: The standalone web app static files. This is what one deploys to a web server or runs with Electron.
- `electron_app/`: The launcher desktop Electron app
- `static/`: The Manager Electron app to run with the electron command-line
- `bundled/`: The Electron app bundled to run standalone on each platform
- `packaged/`: The Electron app bundles packaged as single files for distribution
- `invite_page`: the Invite Page
- `static`: The standalone static files to be deployed
- `shadowbox`: The Proxy Server

The directories have subdirectories for intermediate output:
- `ts/`: Autogenerated Typescript files
- `js/`: The output from compiling Typescript code
- `browserified/`: The output of browserifying the Javascript code

To clean up:
```
yarn run clean
```
9 changes: 9 additions & 0 deletions jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"spec_dir": ".",
"spec_files": [
"build/**/*.spec.js"
],
"helpers": ["src/base64mocks.js"],
"stopSpecOnExpectationFailure": false,
"random": false
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "outline-server",
"devDependencies": {
"@types/jasmine": "^2.5.53",
"clang-format": "^1.2.2",
"husky": "^0.14.3",
"jasmine": "^2.6.0",
"tslint": "^5.9.1",
"typescript": "^2.6.2"
},
"scripts": {
"postinstall": "yarn run server_manager_install",
"server_manager_install": "cd src/server_manager && yarn install --modules-folder ../../node_modules && yarn bower install",
"clean": "rm -rf src/server_manager/bower_components/ src/{metrics_server,server_manager}/node_modules/ build/ node_modules/ src/server_manager/install_scripts/do_install_script.ts",
"shadowbox_install": "cd src/shadowbox && yarn install --modules-folder ../../node_modules --no-bin-links",
"metrics_server_install": "cd src/metrics_server && yarn install --modules-folder ../../node_modules",
"do": "bash ./scripts/do_action.sh",
"precommit": "for i in . src/server_manager/electron_app src/metrics_server src/shadowbox; do tslint -p $i --fix; done; git-clang-format"
}
}
37 changes: 37 additions & 0 deletions scripts/do_action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Copyright 2018 The Outline Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eux

# TODO: Because Node.js on Cygwin doesn't handle absolute paths very
# well, it would be worth pushd-ing to ROOT_DIR before invoking
# them and making BUILD_DIR a relative path, viz. just "build".

export ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
export BUILD_DIR=${BUILD_DIR:-$ROOT_DIR/build}

function do_action() {
readonly STYLE_BOLD_WHITE='\033[1;37m'
readonly STYLE_RESET='\033[0m'
local action=$1
echo -e "$STYLE_BOLD_WHITE[Running $action]$STYLE_RESET"
shift
$ROOT_DIR/src/${action}_action.sh "$@"
echo -e "$STYLE_BOLD_WHITE[Done $action]$STYLE_RESET"
}
export -f do_action

do_action "$@"
Loading

0 comments on commit c44d9f2

Please sign in to comment.