diff --git a/docker-compose-deps.yml b/docker-compose-deps.yml new file mode 100644 index 0000000000..aaa1ec59b2 --- /dev/null +++ b/docker-compose-deps.yml @@ -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: diff --git a/docker-compose-speckle.yml b/docker-compose-speckle.yml new file mode 100644 index 0000000000..6162fb0d6c --- /dev/null +++ b/docker-compose-speckle.yml @@ -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" diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index cf7183ee44..0000000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,60 +0,0 @@ -version: "3" -services: - server: - build: - . - depends_on: - - database - - redis - ports: - - "3000:3000" - environment: - DEBUG: "speckle:*" - WAIT_HOSTS: database:5432, redis:6379 - env_file: - - .env - - database: - image: "postgres:13.1-alpine" # use the current alpine version for smaller image - environment: - POSTGRES_DB: - POSTGRES_USER: - POSTGRES_PASSWORD: - volumes: - # persist data even if container shuts down - - speckle-postgres-data:/var/lib/postgresql/data/ - ports: - - "5432:5432" - - pgadmin: - image: dpage/pgadmin4 - environment: - PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL} - PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD} - ports: - - "16543:80" - depends_on: - - database - - redis: - image: "redis:6.0-alpine" - ports: - - "6379:6379" # It is not neccesary to expose the reddis port if running the app with compose - volumes: - - redis_volume_data:/data - - redis_insight: - image: redislabs/redisinsight:latest - container_name: redis_insight - restart: always - depends_on: - - redis - ports: - - 8001:8001 - volumes: - - redis_insight_volume_data:/db - -volumes: - speckle-postgres-data: # named volumes can be managed easier using docker-compose - redis_volume_data: - redis_insight_volume_data: \ No newline at end of file diff --git a/packages/frontend/README.md b/packages/frontend/README.md index 805ae40c99..3dd92dc596 100644 --- a/packages/frontend/README.md +++ b/packages/frontend/README.md @@ -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 diff --git a/packages/server/.env-example b/packages/server/.env-example index b65d4fd031..679796308a 100644 --- a/packages/server/.env-example +++ b/packages/server/.env-example @@ -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 @@ -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 <-" @@ -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 diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index 46a55145eb..c3f1d30319 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -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 ./ diff --git a/packages/server/app.js b/packages/server/app.js index c8a21f4a19..2b16eeb8bd 100644 --- a/packages/server/app.js +++ b/packages/server/app.js @@ -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):' ) diff --git a/packages/server/readme.md b/packages/server/readme.md index 8ea63f2f16..76215dcd98 100644 --- a/packages/server/readme.md +++ b/packages/server/readme.md @@ -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: @@ -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 diff --git a/readme.md b/readme.md index 0734aeb7bc..2493093088 100644 --- a/readme.md +++ b/readme.md @@ -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.