|
1 |
| -# Contribution Guidelines |
| 1 | +# Gitbase Playground Contribution Guidelines |
2 | 2 |
|
3 | 3 | As all source{d} projects, this project follows the
|
4 | 4 | [source{d} Contributing Guidelines](https://github.com/src-d/guide/blob/master/engineering/documents/CONTRIBUTING.md).
|
5 | 5 |
|
| 6 | +In addition to those guidelines, this document describes how to build and run the application for development purposes. |
6 | 7 |
|
7 |
| -## Additional Contribution Guidelines |
| 8 | +# Requirements |
8 | 9 |
|
9 |
| -In addition to the [source{d} Contributing Guidelines](https://github.com/src-d/guide/blob/master/engineering/documents/CONTRIBUTING.md), |
10 |
| -this project follows the guidelines described below. |
| 10 | +Refer to the main [README](../README.md) for the common requirements and configuration environment variables. |
11 | 11 |
|
| 12 | +Make sure you also satisfy these requirements: |
| 13 | +- [Install Go](https://golang.org/doc/install) and [configure the $GOPATH](https://github.com/golang/go/wiki/SettingGOPATH). |
| 14 | +- This project should be cloned in `$GOPATH/github.com/src-d/gitbase-playground`. |
| 15 | +- Install [Node.js](https://nodejs.org) and [Yarn](https://yarnpkg.com/en/docs/install). |
12 | 16 |
|
13 |
| -# Architecture |
| 17 | +## Run bblfsh and gitbase Dependencies |
| 18 | + |
| 19 | +As with a normal deployment, if you don't use Docker Compose you will need to configure a [gitbase](https://docs.sourced.tech/gitbase) server, and a [bblfsh](https://doc.bblf.sh/) server. It is recommended to read their documentation, but here is a quick guide on how to run both as docker containers. |
| 20 | + |
| 21 | +Launch bblfshd and install the required drivers: |
| 22 | + |
| 23 | +```bash |
| 24 | +$ docker run \ |
| 25 | + --privileged \ |
| 26 | + --publish 9432:9432 \ |
| 27 | + --volume /var/lib/bblfshd:/var/lib/bblfshd \ |
| 28 | + --name bblfsh \ |
| 29 | + bblfsh/bblfshd |
| 30 | +$ docker exec -it bblfsh bblfshctl driver install --recommended |
| 31 | +``` |
14 | 32 |
|
15 |
| -The application is a go binnary that serves the statics and the API used for the UI. |
| 33 | +gitbase will serve Git repositories, so you will need to to populate a directory with them: |
16 | 34 |
|
17 |
| -The statics (`html`, `js` and `css`) are generated by `yarn`, embedded in the go binary using bindata, and served from the binary itself. |
| 35 | +```bash |
| 36 | +$ mkdir $HOME/repos |
| 37 | +$ cd $HOME/repos |
| 38 | +$ git clone [email protected]:src-d/gitbase.git |
| 39 | +$ git clone [email protected]:bblfsh/bblfshd.git |
| 40 | +$ git clone [email protected]:src-d/gitbase-playground.git |
| 41 | +``` |
18 | 42 |
|
19 |
| -There are two main different ways to run the app: |
| 43 | +Launch gitbase: |
| 44 | + |
| 45 | +```bash |
| 46 | +$ docker run \ |
| 47 | + --publish 3306:3306 \ |
| 48 | + --link bblfsh \ |
| 49 | + --volume $HOME/repos:/opt/repos \ |
| 50 | + --env BBLFSH_ENDPOINT=bblfsh:9432 \ |
| 51 | + --name gitbase \ |
| 52 | + srcd/gitbase |
| 53 | +``` |
20 | 54 |
|
21 |
| -- using released artifacts, as [listed in the README.md](../README.md#run-the-playground) |
22 |
| -- serving the app for development purposes, [building and running it from sources](#run-from-sources) |
| 55 | +# Architecture |
23 | 56 |
|
| 57 | +The application is a Go binary that serves the static files and the API used for the UI. |
24 | 58 |
|
25 |
| -# Configuration |
| 59 | +The static files (`html`, `js`, and `css`) are generated by `yarn`, embedded in the Go binary using `go-bindata`, and served from the binary itself. |
26 | 60 |
|
27 |
| -| Variable | Required | Default value | Meaning | |
28 |
| -| -- | -- | -- | -- | |
29 |
| -| `GITBASEPG_HOST` | | `0.0.0.0` | IP address to bind the HTTP server | |
30 |
| -| `GITBASEPG_PORT` | | `8080` | Port address to bind the HTTP server | |
31 |
| -| `GITBASEPG_SERVER_URL` | | `<GITBASEPG_HOST>:<GITBASEPG_PORT>` | URL used to access the application (i.e. public hostname) | |
32 |
| -| `GITBASEPG_DB_CONNECTION` | | `root@tcp(localhost:3306)/none?maxAllowedPacket=4194304` | gitbase connection string | |
33 |
| -| `GITBASEPG_BBLFSH_SERVER_URL` | | `127.0.0.1:9432` | Address where bblfsh server is listening | |
34 |
| -| `GITBASEPG_ENV` | | `production` | Sets the log level. Use `dev` to enable debug log messages | |
35 |
| -| `FOOTER_HTML` | | | Allows to add any custom html to the page footer. It must be encoded in base64 | |
| 61 | +# API |
36 | 62 |
|
| 63 | +The backend API is documented in the [rest API guide](rest-api.md) |
37 | 64 |
|
38 | 65 | # Development
|
39 | 66 |
|
40 |
| -## Requirements |
| 67 | +Each one of the following sections describes an alternative method to run the project from sources. You may use the one that suits your needs. |
41 | 68 |
|
42 |
| -You should already have [Go installed](https://golang.org/doc/install#install), and properly [configured the $GOPATH](https://github.com/golang/go/wiki/SettingGOPATH) |
| 69 | +They all require the project is cloned into your `$GOPATH`. |
43 | 70 |
|
| 71 | +```bash |
| 72 | +$ go get -d -u github.com/src-d/gitbase-playground/... |
| 73 | +$ cd $GOPATH/github.com/src-d/gitbase-playground |
44 | 74 | ```
|
45 |
| -go version; # prints your go version |
46 |
| -go env GOPATH; # prints your $GOPATH path |
| 75 | + |
| 76 | +## Run from Sources |
| 77 | + |
| 78 | +The following command will build the frontend and serve it from the Go backend: |
| 79 | + |
| 80 | +```bash |
| 81 | +$ make serve |
47 | 82 | ```
|
48 | 83 |
|
49 |
| -The project must be under $GOPATH, as required by the Go tooling. |
50 |
| -You should be able to navigate into the source code by running: |
| 84 | +This will start a server locally, which you can access at [http://localhost:8080](http://localhost:8080). |
| 85 | + |
| 86 | +## Run Using webpack Hot Module Replacement |
| 87 | + |
| 88 | +Instead of rebuilding the frontend and restarting the backend every time you do a change, you may instead run the backend to provide the API, and use webpack to serve the frontend. |
51 | 89 |
|
| 90 | +In one terminal run the Go backend: |
| 91 | + |
| 92 | +```bash |
| 93 | +$ GITBASEPG_ENV=dev go run cmd/gitbase-playground/main.go |
52 | 94 | ```
|
53 |
| -cd $GOPATH/src/github.com/src-d/gitbase-playground |
| 95 | + |
| 96 | +In another terminal, run the frontend: |
| 97 | +```bash |
| 98 | +$ yarn --cwd frontend install |
| 99 | +$ yarn --cwd frontend start |
54 | 100 | ```
|
55 | 101 |
|
56 |
| -You need also [Yarn v1.x.x installed](https://yarnpkg.com/en/docs/install) |
| 102 | +## Run with Docker Compose from Sources |
| 103 | + |
| 104 | +The file `docker-compose.build.yml` overrides the default compose file. Using it a new docker image, `gitbase-playground-dev`, will be created from the current sources. |
57 | 105 |
|
| 106 | +```bash |
| 107 | +$ make dependencies |
| 108 | +$ make packages |
| 109 | +$ GITBASEPG_REPOS_FOLDER=$HOME/repos docker-compose \ |
| 110 | + -f docker-compose.yml -f docker-compose.build.yml \ |
| 111 | + up --force-recreate --build |
58 | 112 | ```
|
59 |
| -yarn --version; # prints your Yarn version |
| 113 | + |
| 114 | +For convenience you may run the same commands with: |
| 115 | + |
| 116 | +```bash |
| 117 | +$ make compose-serve |
60 | 118 | ```
|
61 | 119 |
|
| 120 | +## Build a Docker Container |
62 | 121 |
|
63 |
| -## Run from Sources |
| 122 | +These commands will build a stand-alone docker image, that will require external gitbase and bblfshd servers. |
64 | 123 |
|
65 |
| -You need to satisfy all [project requirements](#requirements), and then run: |
| 124 | +```bash |
| 125 | +$ make dependencies |
| 126 | +$ make packages |
| 127 | +$ make docker-build |
| 128 | +``` |
| 129 | + |
| 130 | +# Testing |
| 131 | + |
| 132 | +## Lint |
| 133 | + |
| 134 | +Use `make lint` to make sure the code follows the project's coding style. |
66 | 135 |
|
67 | 136 | ```bash
|
68 |
| -$ go get -d -u github.com/src-d/gitbase-playground/... |
69 |
| -$ cd $GOPATH/github.com/src-d/gitbase-playground |
70 |
| -$ make serve |
| 137 | +$ make lint |
71 | 138 | ```
|
72 | 139 |
|
73 |
| -This will start a server locally, which you can access on [http://localhost:8080](http://localhost:8080) |
| 140 | +## Unit Tests |
74 | 141 |
|
| 142 | +The command `make test` will run JavaScript and Go tests. |
| 143 | + |
| 144 | +```bash |
| 145 | +$ make test |
| 146 | +``` |
75 | 147 |
|
76 | 148 | ## Integration Tests
|
77 | 149 |
|
78 |
| -The integration tests require that `gitbase` and `bblfshd` are running and available for the playground. |
| 150 | +Use the `GITBASEPG_INTEGRATION_TESTS=true` environment variable with the same `make test` command. |
| 151 | + |
| 152 | +The integration tests require that `gitbase` and `bblfshd` are running and reachable. See the [Requirements section](#requirements) above for more details. |
79 | 153 |
|
80 | 154 | It is also required to configure the running `gitbase` to serve a copy of the `https://github.com/src-d/gitbase-playground` repository.
|
81 | 155 |
|
82 | 156 | ```bash
|
83 |
| -$ docker run -d --name bblfshd --privileged -p "9432:9432" bblfsh/bblfshd |
84 |
| -$ docker exec -it bblfshd bblfshctl driver install --recommended |
85 |
| -$ mkdir $HOME/repos |
86 |
| -$ git clone https://github.com/src-d/gitbase-playground.git $HOME/repos/gitbase-playground |
87 |
| -$ docker run -d --name gitbase -p "3306:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase |
88 | 157 | $ GITBASEPG_INTEGRATION_TESTS=true make test
|
89 | 158 | ```
|
0 commit comments