Skip to content

Commit

Permalink
development instructions with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkircos committed Jun 28, 2024
1 parent 5f7c05e commit bc7ea6e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 181 deletions.
139 changes: 1 addition & 138 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,144 +18,7 @@ Check out our open roles ⟶ [careers.quadratichq.com](https://careers.quadratic

### Local development environment

1. Install [nvm](https://github.com/nvm-sh/nvm)

2. Install Node and NPM

```sh
nvm install && nvm use
```

3. Install [rustup](https://www.rust-lang.org/tools/install)

4. Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)

5. Install WASM toolchain

```sh
rustup target add wasm32-unknown-unknown
```

6. Install cargo watch

```sh
cargo install cargo-watch
```

7. Install [Python](https://wiki.python.org/moin/BeginnersGuide/Download)

8. Install [Docker Desktop](https://docs.docker.com/desktop/)

### Configure Auth0 account (Optional)

This is only required if the `quadratic-community` Auth0 account does not work.

1. Create an account on [Auth0](https://auth0.com/)

2. Create a new Regular Web Application

3. In the settings tab, configure the following:
- Allowed Callback URLs: `http://localhost:3000/login-result?redirectTo`
- Allowed Logout URLs: `http://localhost:3000`
- Allowed Web Origins: `http://localhost:3000`
- Allowed Origins (CORS): `http://localhost:3000`

### Configure .env files

1. Create .env files using the template .env.example files

```sh
cp .env.example .env && \
cp quadratic-api/.env.example quadratic-api/.env && \
cp quadratic-client/.env.example quadratic-client/.env && \
cp quadratic-files/.env.example quadratic-files/.env && \
cp quadratic-multiplayer/.env.example quadratic-multiplayer/.env
```

These are prefilled with `quadratic-community` Auth0 account credentials and values required to access services in docker.

2. If the `quadratic-community` Auth0 account does not work, update the Auth0 values in the following files with your Auth0 account values:

- `.env`
- `quadratic-api/.env`
- `quadratic-client/.env`
- `quadratic-multiplayer/.env`

## Run Quadratic

1. Install dependencies

```sh
npm install
```

2. Start Redis, Postgres and Localstack in docker

```sh
npm run docker:up
```

3. Start all quadratic packages

```sh
npm run start
```

Press `h` in termial to open help menu. Use shortcuts from this menu to toggle watch mode, logs, etc.

To run all packages in watch mode, use

```sh
npm run dev
```

## Run tests

### TypeScript

1. Go to the `quadratic-client` directory

```sh
cd quadratic-client
```

2. Compile the Rust code

```sh
build:wasm:nodejs
```

3. Install dependencies (run again when updating Rust)

```sh
npm install
```

4. Run all tests

```sh
npm run test:all
```

or run just unit tests

```sh
npm run test:unit
```

### Rust

1. Go to the `quadratic-core` directory

```sh
cd quadratic-core
```

2. Run test

```sh
cargo test --workspace
```
See [DEVELOPMENT.md](/DEVELOPMENT.md)

## Feature requests and bugs

Expand Down
89 changes: 52 additions & 37 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,21 @@

Let's get everything setup to develop on Quadratic!

- [Install Dependencies](#install-dependencies)
- [Local Environment Setup](#local-environment-setup)
- [Docker](#docker)
- [Docker Compose](#docker-compose)
- [Building Images Manually](#building-images-manually)
- [Developing without Docker](#developing-without-docker)
- [Installing PostgreSQL](#installing-postgresql)
- [Mac](#mac)
- [Create Database](#create-database)
- [Installing Redis](#installing-redis)
- [Mac](#mac-1)
- [Using node dev](#using-node-dev)
- [Commands while `node dev` is running](#commands-while-node-dev-is-running)
- [Running for React-only development](#running-for-react-only-development)
- [Testing](#testing)
- [Testing Quadratic Client](#testing-quadratic-client)
- [Testing Quadratic API](#testing-quadratic-api)
- [Testing Rust Crates](#testing-rust-crates)
- [Rust Coverage](#rust-coverage)
- [Linting](#linting)
- [Linting Rust Crates](#linting-rust-crates)
- [Load Testing](#load-testing)


## Install Dependencies

First, follow the instructions to install:
First, install base dependencies:

1. [NVM](https://github.com/nvm-sh/nvm)
1. [rustup](https://www.rust-lang.org/tools/install)
1. [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
1. [Docker Desktop](https://docs.docker.com/desktop/)
1. [Python3] (should be preinstalled on mac)

Start the Docker Desktop by opening Docker.

Start Docker Desktop after installing required software. Now install the depedencies:
`open -a Docker`

Now install the tool chain:

```shell
# install node version 18
Expand All @@ -51,20 +32,41 @@ cargo install cargo-watch

## Local Environment Setup

First, copy over the example file:
1. Create .env files using the template .env.example files

```shell
cp .env.example .env.local
```
```sh
cp .env.example .env && \
cp quadratic-api/.env.example quadratic-api/.env && \
cp quadratic-client/.env.example quadratic-client/.env && \
cp quadratic-files/.env.example quadratic-files/.env && \
cp quadratic-multiplayer/.env.example quadratic-multiplayer/.env && \
cp quadratic-connection/.env.example quadratic-connection/.env
```

These are prefilled with `quadratic-community` Auth0 account credentials and values required to access services in docker.

If you are on the Quadratic team you can get AUTH0 credentials from Notion.
Auth0 creds need to be updated in: API, Client, Multiplayer, and Connections.

## Start Docker

`docker compose --profile base up`

Enter the missing Auth0 values and save.
`docker compose --profile base up -d` to run as a daemon

Now that dependencies are installed, all you need to do is run `node dev` to
## Start Quadratic Dev

In a new terminal tab
`npm start`

Now that dependencies are installed, all you need to do is run `npm start` which runs `node dev` to
bring up the all services. Invoke `node run --help` for information on how
to use this script, as you can use it to watch individual (or groups of)
services during development. See the [Using node dev](Using-node-dev) section
for more more information.

# Additional Information for Development

### Docker

#### Docker Compose
Expand All @@ -84,8 +86,6 @@ npm run docker:up
Along with the dependent services, scripts are executed that create S3 buckets and
migrate the database. Docker is run in the background in this script.



#### Building Images Manually

To build images for individual services (from project root):
Expand Down Expand Up @@ -280,14 +280,29 @@ JAVA_HOME="/opt/homebrew/opt/openjdk" bash /opt/homebrew/Cellar/jmeter/5.6.3/lib

Output will be located in the terminal.

# Prompting user after version change
## Prompting user after version change

The current version numbers are stored in `updateAlertVersion.json`. This JSON is ready by both the client and the multiplayer server. When the client has a lower version number then the multiplayer (the version is sent by the multiplayer server with the EnterFileRoom message), then the user is prompted to refresh with slightly different experience based on required vs. recommended changes.

# Install Pyodide
## Install Pyodide
* Delete the quadratic-client/public/pyodide directory
* npm i pyodide@latest
* mkdir quadratic-client/public/pyodide
* cp -rf node_modules/pyodide quadratic-client/public/
* download the latest pyodide packages (the largest file available in https://github.com/pyodide/pyodide/releases)
* unpack the file and copy its contents to quadratic-client/public/
* unpack the file and copy its contents to quadratic-client/public/


### Configure Auth0 account (Optional)

This is only required if the `quadratic-community` Auth0 account does not work.

1. Create an account on [Auth0](https://auth0.com/)

2. Create a new Regular Web Application

3. In the settings tab, configure the following:
- Allowed Callback URLs: `http://localhost:3000/login-result?redirectTo`
- Allowed Logout URLs: `http://localhost:3000`
- Allowed Web Origins: `http://localhost:3000`
- Allowed Origins (CORS): `http://localhost:3000`
11 changes: 6 additions & 5 deletions quadratic-api/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ENVIRONMENT=local

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
DATABASE_URL=postgresql://postgres:postgres@0.0.0.0:5432/postgres

CORS=http://localhost:3000
CORS='*'

AUTH0_JWKS_URI=https://quadratic-community.us.auth0.com/.well-known/jwks.json
AUTH0_ISSUER=https://quadratic-community.us.auth0.com/
Expand All @@ -16,12 +16,13 @@ AWS_S3_ACCESS_KEY_ID=test
AWS_S3_SECRET_ACCESS_KEY=test
AWS_S3_BUCKET_NAME=quadratic-api-docker

OPENAI_API_KEY=...
OPENAI_API_KEY=

SENTRY_DSN=...
SENTRY_DSN=

M2M_AUTH_TOKEN=M2M_AUTH_TOKEN

STRIPE_SECRET_KEY=STRIPE_SECRET_KEY
STRIPE_WEBHOOK_SECRET=STRIPE_WEBHOOK_SECRET

STRIPE_WEBHOOK_SECRET=
ENCRYPTION_KEY=f7f646bcdff9c5ec849687ffb01e879ae23017daad27974ad141c18a353cd863
2 changes: 1 addition & 1 deletion quadratic-connection/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ HOST=127.0.0.1
PORT=3003
ENVIRONMENT=docker

AUTH0_JWKS_URI=https://dev-nje7dw8s.us.auth0.com/.well-known/jwks.json
AUTH0_JWKS_URI=https://quadratic-community.us.auth0.com/.well-known/jwks.json
QUADRATIC_API_URI=http://localhost:8000
M2M_AUTH_TOKEN=M2M_AUTH_TOKEN

0 comments on commit bc7ea6e

Please sign in to comment.