Skip to content

Commit

Permalink
Simplified setting up a local dev setup (#159)
Browse files Browse the repository at this point in the history
* Simplified the local dev setup
  • Loading branch information
cristi8 authored Mar 31, 2021
1 parent 39cf158 commit 02992c9
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 85 deletions.
59 changes: 59 additions & 0 deletions docker-compose-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: "3"
services:

# Actual Speckle Server dependencies

postgres:
image: "postgres:13.1-alpine"
restart: always
environment:
POSTGRES_DB: speckle
POSTGRES_USER: speckle
POSTGRES_PASSWORD: speckle
volumes:
- postgres-data:/var/lib/postgresql/data/
ports:
- "127.0.0.1:5432:5432"

redis:
image: "redis:6.0-alpine"
restart: always
volumes:
- redis-data:/data
ports:
- "127.0.0.1:6379:6379"


# Useful for debugging / exploring local databases

pgadmin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@localhost
PGADMIN_DEFAULT_PASSWORD: admin
volumes:
- pgadmin-data:/var/lib/pgadmin
ports:
- "127.0.0.1:16543:80"
depends_on:
- postgres

redis_insight:
image: redislabs/redisinsight:latest
restart: always
volumes:
- redis_insight-data:/db
ports:
- "127.0.0.1:8001:8001"
depends_on:
- redis


# Storage persistency

volumes:
postgres-data:
redis-data:
pgadmin-data:
redis_insight-data:
32 changes: 32 additions & 0 deletions docker-compose-speckle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3"
services:

speckle-frontend:
build:
context: .
dockerfile: packages/frontend/Dockerfile
restart: always

speckle-server:
build:
context: .
dockerfile: packages/server/Dockerfile
args:
NODE_ENV: development
restart: always
environment:
CANONICAL_URL: "http://localhost:3000"
SESSION_SECRET: "-local-"
STRATEGY_LOCAL: "true"
DEBUG: "speckle:*"
FRONTEND_HOST: "speckle-frontend"
FRONTEND_PORT: 80

POSTGRES_URL: "postgres"
POSTGRES_USER: "speckle"
POSTGRES_PASSWORD: "speckle"
POSTGRES_DB: "speckle"

REDIS_URL: "redis://redis"
ports:
- "127.0.0.1:3000:3000"
60 changes: 0 additions & 60 deletions docker-compose.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions packages/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ We're working to stabilize the 2.0 API, and until then there will be breaking ch

Notes:

- In **development** mode, the Speckle Server will proxy the frontend from `localhost:8080` to `localhost:3000`. If you don't see anything, ensure you've run `npm run dev` in the frontend package.
- In **development** mode, the Speckle Server will proxy the frontend from `localhost:3000` to `localhost:8080`. If you don't see anything, ensure you've run `npm run dev` in the frontend package.

- In **production** mode, the Speckle Server will statically serve the frontend app from `/dist`. You will need to run `npm run build` to populate this folder.
- In **production** mode, the Speckle Frontend will be statically served by nginx (see the Dockerfile in the current directory).

## Documentation

Expand Down
19 changes: 10 additions & 9 deletions packages/server/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
# your deployment environment.
############################################################
PORT=3000
# for `docker-compose up` use "redis://redis"
REDIS_URL="redis://localhost:6379"

CANONICAL_URL="http://localhost:3000"
SESSION_SECRET="-> FILL IN <-"

# Redis connection: default for local development environment
REDIS_URL="redis://localhost:6379"

############################################################
# Postgres Database
# the connection uri is built up from these variables
############################################################
# If you specify a user and password, do not specify the protocol in the
# POSTGRES_URL variable.
# If the app is ran via `docker-compose up`, it has to be the name of the
# service (defaults to "database").
POSTGRES_URL="-> FILL IN <-"
# These defaults are set for the local development environment
POSTGRES_URL="localhost"
# this overrides the default root user in the postgres instance
POSTGRES_USER="-> FILL IN <-"
POSTGRES_USER="speckle"
# this sets the root user password in the postgres instance
POSTGRES_PASSWORD="-> FILL IN <-"
POSTGRES_PASSWORD="speckle"
# this overrides the default database name in postgres
POSTGRES_DB="-> FILL IN <-"
POSTGRES_DB="speckle"

############################################################
# Emails
Expand All @@ -42,7 +42,7 @@ EMAIL=false
############################################################
STRATEGY_LOCAL=true

# STRATEGY_GITHUB=true
# STRATEGY_GITHUB=false
# GITHUB_CLIENT_ID="-> FILL IN <-"
# GITHUB_CLIENT_SECRET="-> FILL IN <-"

Expand All @@ -65,4 +65,5 @@ STRATEGY_LOCAL=true
# If your frontend is served in dev from somewhere else,
# this is going to help out :)
############################################################
# FRONTEND_HOST=localhost
# FRONTEND_PORT=8081
3 changes: 2 additions & 1 deletion packages/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ RUN apt-get update && apt-get install -y \
tini \
&& rm -rf /var/lib/apt/lists/*

ENV NODE_ENV=production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app

COPY packages/server/package*.json ./
Expand Down
3 changes: 2 additions & 1 deletion packages/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ exports.startHttp = async ( app ) => {
let port = process.env.PORT || 3000
app.set( 'port', port )

let frontendHost = process.env.FRONTEND_HOST || 'localhost'
let frontendPort = process.env.FRONTEND_PORT || 8080

// Handles frontend proxying:
// Dev mode -> proxy form the local webpack server
if ( process.env.NODE_ENV === 'development' ) {
const { createProxyMiddleware } = require( 'http-proxy-middleware' )
const frontendProxy = createProxyMiddleware( { target: `http://localhost:${frontendPort}`, changeOrigin: true, ws: false, logLevel: 'silent' } )
const frontendProxy = createProxyMiddleware( { target: `http://${frontendHost}:${frontendPort}`, changeOrigin: true, ws: false, logLevel: 'silent' } )
app.use( '/', frontendProxy )

debug( 'speckle:startup' )( '✨ Proxying frontend (dev mode):' )
Expand Down
15 changes: 7 additions & 8 deletions packages/server/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ Comprehensive developer and user documentation can be found in our:

The Speckle Server is a node application tested against v12. To start it locally:

First, ensure you have postgres and redis ready and running:

- ensure you have a local instance of postgres running
- create a postgres db called `speckle2_dev`
- ensure you have an instance of redis running
First, ensure you have postgres and redis ready and running (check the [readme.md](../../readme.md) from the root of the git repo)

Finally, in the `packages/server` folder:

- copy the `.env-example` file to `.env`,
- open and edit the `.env` file, filling in the required variables,
- If you have a custom setup, open and edit the `.env` file, filling in the required variables,
- run `npm install`,
- finally `npm run dev`,
- check `localhost:3000/graphql` out!

For more setup details and options, check out our [Server Setup Docs](https://speckle.guide/dev/server-setup.html)


## Developing

The server consists of several semi-related components, or modules. These can be found in `/modules`. Module composition:
Expand All @@ -45,9 +44,9 @@ The server consists of several semi-related components, or modules. These can be

### Frontend

- In **development** mode, the Speckle Server will proxy the frontend from `localhost:8080` to `localhost:3000`. If you don't see anything, ensure you've run `npm run dev` in the frontend package.
- In **development** mode, the Speckle Server will proxy the frontend from `localhost:3000` to `localhost:8080`. If you don't see anything, ensure you've run `npm run dev` in the frontend package.

- In **production** mode, the Speckle Server will statically serve the frontend app from `../packages/frontend/dist`.
- In **production** mode, a load balancer should send requests either to the frontend nginx container or the server container, depending on the requested path

### GraphIQL

Expand Down
23 changes: 19 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,28 @@ To get started, first clone this repo. Check out the detailed instructions for e
To get a local Server stack up and running quickly:

- clone this repository
- copy `.env-example` file from the server module to the project root and rename to `.env`
- fill out the environment variables in the `.env` file, follow the comment instructions
- run `$ docker-compose up`
- Clone this repository and cd into the repository root:
```console
git clone https://github.com/specklesystems/speckle-server.git
cd speckle-server
```
- Start dependencies (postgres and redis) by running:
```console
docker-compose -f docker-compose-deps.yml up -d
```
- You have 2 options for running the speckle server (frontend + backend):
- (useful for development) With local development tools (check the Readme.md file in the `frontend` and `server` packages)
- (useful for getting the server running without having local development tools) by starting them inside docker containers:
```console
docker-compose -f docker-compose-speckle.yml up -d
```

This gets you an empty server running on [localhost:3000](http://localhost:3000)

Note: the docker containers will automatically restart at startup. To shut them down, you can use `docker-compose -f [yml_file_name] down` command

For more details and options, check out our [Server Setup Docs](https://speckle.guide/dev/server-setup.html)

## Contributing

Please make sure you read the [contribution guidelines](CONTRIBUTING.md) for an overview of the best practices we try to follow.
Expand Down

0 comments on commit 02992c9

Please sign in to comment.