-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 28036d5
Showing
1,113 changed files
with
495,984 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
We use Github to track bugs in Staffjoy. Please answer these questions before submitting your issue. All of our code is in one place, so please preface the title with the system where the bug is (e.g. "company api" or "www"). Thanks! | ||
|
||
### What environment did you encounter the issue in? | ||
|
||
development, staging, or production? (staffjoy.com is "production") | ||
|
||
### Which browser are you using? | ||
|
||
(if applicable) | ||
|
||
### What did you do? | ||
|
||
If possible, provide a recipe for reproducing the error. For web requests that fail, a `CURL` statement is best. Please try to include the request body. | ||
|
||
### What did you expect to see? | ||
|
||
|
||
### What did you see instead? | ||
|
||
The response from the server contains information that will help us isolate the issue | ||
|
||
### Are there any logs indicating an issue? | ||
|
||
In staging and production, Sentry (https://sentry.io) will show error information. Please paste that link here. | ||
|
||
In development, check the running pods and look at their logs. (For api errors, look at the "server" version of the application for the error - because the api is just a gateway). | ||
|
||
Development logs link: http://kubernetes.staffjoy-v2.local/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/#/pod?namespace=development | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
*.swo | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof | ||
|
||
# ignore bazel bins | ||
bazel-* | ||
|
||
# ignore vagrant | ||
.vagrant | ||
|
||
# ignore visual studio configuration | ||
.vscode | ||
|
||
# Silly macs | ||
.DS_Store | ||
*.swp | ||
|
||
# allow local go/glide vendor | ||
vendor | ||
|
||
# ignore glide cache | ||
.glide/ | ||
|
||
# in case you accidentally run npm at this level | ||
npm-debug.log | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:build_rules/go.bzl", "go_package_prefix") | ||
|
||
go_package_prefix("v2.staffjoy.com/") | ||
|
||
filegroup( | ||
name = "nothing", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@bazel_tools//tools/build_defs/docker:docker.bzl", "docker_build") | ||
|
||
docker_build( | ||
name = "trusty", | ||
tars = [ | ||
"trusty/ubuntu-trusty-core-cloudimg-amd64-root.tar.gz", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Contributing to Staffjoy | ||
|
||
## Community and contact information | ||
|
||
- [Pull requests](https://github.com/staffjoy/v2/pulls) | ||
- Support and bug report email: [[email protected]](mailto:[email protected]) | ||
|
||
## Testing | ||
|
||
We run static code analysis wherever possible, including linting and | ||
formatting checks. We also extensively monitor all systems and | ||
staging/production errors. | ||
|
||
We believe in strategically testing important logic, but that achieving 100% | ||
coverage is not always worth the time. | ||
|
||
## Commit message format | ||
|
||
We follow a rough convention for commit messages that is designed to answer two | ||
questions: what changed and why. The subject line should feature the what and | ||
the body of the commit should describe the why. | ||
|
||
``` | ||
scripts: add the test-cluster command | ||
this uses tmux to setup a test cluster that you can easily kill and | ||
start for debugging. | ||
Fixes #38 | ||
``` | ||
|
||
The format can be described more formally as follows: | ||
|
||
``` | ||
<subsystem>: <what changed> | ||
<BLANK LINE> | ||
<why this change was made> | ||
<BLANK LINE> | ||
<footer> | ||
``` | ||
|
||
The first line is the subject and should be no longer than 70 characters, the | ||
second line is always blank, and other lines should be wrapped at 80 characters. | ||
This allows the message to be easier to read on GitHub as well as in various | ||
git tools. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2015-2017 StaffJoy, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Staffjoy V2 | ||
|
||
[![Build Status](https://travis-ci.org/Staffjoy/v2.svg?branch=master)](https://travis-ci.org/Staffjoy/v2) [![Moonlight](https://img.shields.io/badge/contractors-1-brightgreen.svg)](https://moonlightwork.com/staffjoy) | ||
|
||
[Staffjoy is shutting down](https://blog.staffjoy.com/staffjoy-is-shutting-down-39f7b5d66ef6#.ldsdqb1kp), so we are open-sourcing our code. This the second version of our product, a ground-up rewrite intended for small businesses, like restaurants. You can learn about the design journey from V1 to V2 in [this blog post](https://blog.staffjoy.com/staffjoy-v2-ca15ff1a1169#.e7lmhde6v). | ||
|
||
We started building V2 in August 2016, became feature complete in November 2016, and [launched to the press in January 2017](http://venturebeat.com/2017/01/10/staffjoy-raises-1-2-million-to-help-small-businesses-manage-workflow-scheduling/). | ||
|
||
This is a *monorepo*, so all of the code for all of the services are in this repo. The core technologies are the [Bazel build system](https://bazel.build/), [Kubernetes](https://kubernetes.io/) (including its DNS for internal service discovery), [Redux](http://redux.js.org/), [Go](https://golang.org/), and [Yarn](https://yarnpkg.com/en/). In staging and production, we used [Google Container Engine](https://cloud.google.com/container-engine/) and their managed databases. | ||
|
||
## Credit | ||
|
||
The authors of the original code were [@philipithomas](https://github.com/philipithomas), [@samdturner](https://github.com/samdturner), [@andhess](https://github.com/andhess), and some contractors. This is a fork of the internal repository. For security purposes, the Git history has been squashed. | ||
|
||
## Services | ||
|
||
[Read about the V2 architecture on our blog](https://blog.staffjoy.com/staffjoys-v2-architecture-9d2fcb4015fd#.pggmlbtmw) | ||
|
||
[![Staffjoy V2 Architecture](https://blog.staffjoy.com/staffjoys-v2-architecture-9d2fcb4015fd#.pggmlbtmw)](https://blog.staffjoy.com/staffjoys-v2-architecture-9d2fcb4015fd#.pggmlbtmw) | ||
|
||
* Faraday proxies all traffic from external services to internal ones. It also tells backend services whether a user is logged in. It's the only service that has a public IP address! | ||
* www (www.staffjoy.com) is the main marketing website. It also handles login and logout. | ||
* myaccount (myaccount.staffjoy.com) is a single-page javascript app that lets users modify their accounts | ||
* account-gateway (account.staffjoy.com) is the externally-available REST api for modifying accounts. It converts REST to gRPC for the accounts-datastore | ||
* accounts-server is the internal system that processes gRPC calls and stores/retrieves information using the account database. | ||
* company-gateway (company.staffjoy.com) is the externally-available REST api for modifying companies. It converts REST to gRPC for the companys-datastore | ||
* company-server is the internal system that processes gRPC calls and stores/retrieves information using the company database. | ||
* whoami (whoami.staffjoy.com) is a website that sends information about the current web session for easy access in the front-end. | ||
* superpowers (superpowers.staffjoy-v2.local) is a development-only website that lets you gain super user powers across Staffjoy (denoted as "support" flag on user accounts) | ||
* ical (ical.staffjoy-v2.local) is service serving up a worker's shift list through ical | ||
|
||
### External API Standards | ||
|
||
* Services should be RESTful JSON over HTTPS | ||
* Serve the spec at `/swagger.json` | ||
* Use the `apidocs` package to serve a swagger UI at `/ui/` | ||
|
||
## Dev | ||
|
||
### Getting started | ||
|
||
Welcome to Staffjoy! | ||
|
||
We use a **monorepo** that stores all of our code in this single repo. We use Vagrant to run a kubernetes cluster locally on your laptop. This makes it easy to run all of Staffjoy's services. | ||
|
||
### Setting up your Gopath | ||
|
||
If you are running Go code, you should [set up your $GOPATH](https://golang.org/doc/install), then clone this repository into the `v2.staffjoy.com` package: | ||
|
||
``` | ||
mkdir -p $GOPATH/src/ | ||
git clone [email protected]:Staffjoy/staffjoy.git $GOPATH/src/v2.staffjoy.com/ | ||
``` | ||
|
||
### One-time dependencies on host machine (laptop) | ||
|
||
* [Virtualbox](https://www.virtualbox.org/) | ||
* [Vagrant](https://www.vagrantup.com/docs/getting-started/), then run `vagrant up` to boot the dev server. | ||
* Vagrant host manager: `vagrant plugin install vagrant-hostmanager` | ||
* unison (see below) | ||
* [modd](https://github.com/cortesi/modd) (either from Go source or binary available [here]) | ||
|
||
### Installing Unison | ||
|
||
Unison syncs files between the host and the VM in a way that preserves simlinks. | ||
|
||
Unfortunately, installing it on OSX is a bit of a pain because the version and the compiler must be the same as the one in Vagrant! | ||
|
||
First, install OCaml version 3.12 - you may need to say "yes" to some command prompts: | ||
|
||
``` | ||
wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin 3.12.1 | ||
``` | ||
|
||
Check that `ocaml -version` is 3.12.1. If it is not, try removing `/usr/local/bin/ocaml` and running `opam switch 3.12.1`. | ||
|
||
Then, compile unison with this version of ocaml. You may be prompted for your password. | ||
|
||
``` | ||
cd /tmp | ||
curl -O https://www.seas.upenn.edu/~bcpierce/unison/download/releases/unison-2.40.102/unison-2.40.102.tar.gz | ||
tar -xvzf unison-2.40.102.tar.gz | ||
cd unison-2.40.102 | ||
make UISTYLE=text | ||
sudo cp unison /usr/local/bin | ||
``` | ||
|
||
|
||
### Running the Environment | ||
|
||
|
||
Run `make dev`. Code will boot and run at [staffjoy-v2.local](http://www.staffjoy-v2.local). Note that the first time you do this could take up to 45 minutes in order to provision the VM! | ||
|
||
Changes will trigger an automatic rebuild and redeployment. (Check deployment progress at [kubernetes.staffjoy-v2.local/ui/](http://kubernetes.staffjoy-v2.local/ui/)). End the dev server with `control + c` (and it will automatically shut off the VM). | ||
|
||
**Known Bug on OSX Sierra**: If Vagrant cannot find download the box, run `sudo rm /opt/vagrant/embedded/bin/curl`. ([Bug tracking link](https://github.com/Varying-Vagrant-Vagrants/VVV/issues/354)) | ||
|
||
If you run into issues with stuck deployments in development - then run `make dev-k8s-fix` then re-run `make dev`. | ||
|
||
### Accessing the environment | ||
|
||
Access the VM by running `vagrant ssh`. Code is located in `/home/vagrant/golang/src/v2.staffjoy.com/` (aliased to `$STAFFJOY`, i.e. `cd $STAFFJOY`). | ||
|
||
To build code and run it locally, in vagrant go to the code directory `$STAFFJOY` in vagrant, then run `make dev-build` for a one-time build. | ||
|
||
If things are really goofing, run `vagrant destroy -f` then rebuild. | ||
|
||
## Debugging | ||
|
||
* There is a **known bug** where kubernetes does not come back after vagrant halts. To identify this, ssh into vagrant (`vagrant ssh`), then examine running docker containers (`docker ps`). If it's not running dozens of contianers, there's a problem. **To fix this:**, run `make dev-k8s-fix`. (Your local data may be wiped out). | ||
* If files are not syncing between your laptop and vagrant (to Vagrant's `$STAFFJOY` directory) - try running `make dev` again, or manually running unison (the syncer) on the host machine with `./vagrant/unison.sh`. | ||
* If your machine can't keep up with autobuilding on changes, it may be preferred to stop using `make dev` and to instead call its two subcommands separately (manually): `./vagrant/unison.sh` to sync files on your computer, then SSHing into Vagrant and manually triggering builds (`cd $STAFFJOY && make dev-build`) | ||
|
||
### Development resources | ||
|
||
* [Kubernetes UI](http://kubernetes.staffjoy-v2.local/ui/). We use the `development` namespace. You can see logs from a "pod" (container) through the UI ([link](http://kubernetes.staffjoy-v2.local/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/#/pod?namespace=development)) | ||
* [HTTP Debugger (for faraday)](http://faraday.staffjoy-v2.local/) - use this to examine headers being sent to internal systems | ||
* [Superpowers lets you do magic things](http://superpowers.staffjoy-v2.local) - use it while logged in to get `support` api permissions in dev. | ||
|
||
## Go | ||
|
||
### Assets in Go | ||
|
||
If you are loading assets like templates, CSS, JS, etc - you need to package the the data into the binary. Otherwise, the app will ship and it won't be able to find the assets! | ||
|
||
To do this, use the [go-bindata](https://github.com/jteeuwen/go-bindata) project. If you modify any of the asset files, you will need to rebuild them then commit the resulting `bindata.go` file and commit it. You have been warned! | ||
|
||
Most services provide a `build.sh` file that compiles all the data that needs to be committed. | ||
|
||
### Development tools | ||
|
||
The tool [GoConvey](https://github.com/smartystreets/goconvey) is great for seeing tests. | ||
|
||
### Environment variables for configuration | ||
|
||
* `ENV`: Set to `development`,`staging`, or `production`. Null defaults to `development` | ||
* `SENTRY_DSN`: Set to the [Sentry](https://getsentry.com) api key in every Go service for proper error tracking and reporting | ||
|
||
## Protocol Buffers | ||
|
||
If you modify the files in `protobuf/`, run `make protobuf` to recompile all of the generated files. | ||
|
||
If you're getting started with protocol buffers, here are some resources: | ||
|
||
* [Protocol Buffers](https://developers.google.com/protocol-buffers/) | ||
* [gRPC](http://grpc.io) | ||
* [gRPC health checks](https://github.com/grpc/grpc/blob/master/doc/health-checking.md) | ||
|
||
## Working Offline | ||
|
||
* Email will break, but you can look at the system logs for the email service to see what would have been sent. (Useful for grabbing account activation links!) | ||
* See all Go documentation installed on the host machie with `godoc -http=":8080"`. You'll be able to see all docs at [localhost:8080](http://localhost:8080/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
ip = '192.168.33.11' | ||
cpus = 2 | ||
memory = 1024 * 6 | ||
|
||
def fail_with_message(msg) | ||
fail Vagrant::Errors::VagrantError.new, msg | ||
end | ||
|
||
|
||
Vagrant.configure(2) do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" | ||
config.vm.network :private_network, ip: ip, hostsupdater: 'skip' | ||
config.vm.hostname = 'staffjoy-v2.local' | ||
|
||
config.vm.provider 'virtualbox' do |vb| | ||
vb.name = config.vm.hostname | ||
vb.customize ['modifyvm', :id, '--cpus', cpus] | ||
vb.customize ['modifyvm', :id, '--memory', memory] | ||
|
||
# Fix for slow external network connections | ||
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] | ||
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] | ||
end | ||
|
||
if Vagrant.has_plugin? 'vagrant-hostmanager' | ||
config.hostmanager.enabled = true | ||
config.hostmanager.manage_host = true | ||
config.hostmanager.aliases = [ | ||
'account.staffjoy-v2.local', | ||
'app.staffjoy-v2.local', | ||
'company.staffjoy-v2.local', | ||
'faraday.staffjoy-v2.local', | ||
'kubernetes.staffjoy-v2.local', | ||
'myaccount.staffjoy-v2.local', | ||
'superpowers.staffjoy-v2.local', | ||
'signal.staffjoy-v2.local', | ||
'waitlist.staffjoy-v2.local', | ||
'whoami.staffjoy-v2.local', | ||
'www.staffjoy-v2.local', | ||
'ical.staffjoy-v2.local', | ||
] | ||
else | ||
fail_with_message "vagrant-hostmanager missing, please install the plugin with this command:\nvagrant plugin install vagrant-hostmanager" | ||
end | ||
config.vm.provision "shell", path: "vagrant/provision.sh" | ||
end |
Oops, something went wrong.