Skip to content

Commit

Permalink
Merge pull request #76 from gjedlicska/containers_kickstart
Browse files Browse the repository at this point in the history
Specle Server 2.0 dev deployment
  • Loading branch information
didimitrie authored Jan 29, 2021
2 parents 2458bbc + 0cdde3a commit cd4e065
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 61 deletions.
9 changes: 2 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
**/dist
test-queries
.editorconfig
.gitignore
.git
Contributing.md
ISSUE_TEMPLATE.md
lerna.json
LICENSE
package-lock.json
package.json
**/.env
.env.example
.eslintrc.json
.mocharc.js
readme.md
.env
readme.md
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:12.20.1-alpine3.12@sha256:42998ae4420998ff3255fc2d6884e882bd32f06d45b057f4b042e33bf48a1240 as build
FROM node:14.15.4-alpine3.12@sha256:55bf28ea11b18fd914e1242835ea3299ec76f5a034e8c6e42b2ede70064e338c as node

FROM node as build
# Having multiple steps in builder doesn't increase the final image size
# So having verbose steps for readability and caching should be the target

Expand Down Expand Up @@ -28,7 +30,7 @@ COPY packages/frontend frontend
WORKDIR /opt/frontend
RUN npm run build

FROM node:12.20.1-alpine3.12@sha256:42998ae4420998ff3255fc2d6884e882bd32f06d45b057f4b042e33bf48a1240
FROM node as runtime

RUN apk add --no-cache tini=0.19.0-r0

Expand All @@ -52,4 +54,4 @@ COPY --chown=node packages/server /home/node/server
# Init for containers https://github.com/krallin/tini
ENTRYPOINT [ "/sbin/tini", "--" ]

CMD ["node", "bin/www"]
CMD ["node", "bin/www"]
59 changes: 59 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: "3"
services:
server:
build:
.
depends_on:
- database
- redis
ports:
- "3000:3000"
environment:
DEBUG: "speckle:*"
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:
52 changes: 34 additions & 18 deletions packages/server/.env-example
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
#########################################################vvv
###########################################################
# Basics
# The following env vars are expected to exist.
# Fill them in here, or make sure you provide them via
# your deployment environment.
#########################################################vvv
############################################################
PORT=3000
POSTGRES_URL="postgres://localhost/speckle2"
# for `docker-compose up` use "redis://redis"
REDIS_URL="redis://localhost:6379"

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

#########################################################vvv
############################################################
# Postgres Database
# the connection uri is build up from these variables
############################################################
# only include the address, the protocoll `postgres://` is provided.
# for local development a sensible default is "localhost"
# if the app is ran via `docker-compose up`, it has to be the name of the service.
# this defaults to "database"
POSTGRES_URL="-> FILL IN <-"
# this overrides the default root user in the postgres instance
POSTGRES_USER="-> FILL IN <-"
# this sets the root user password in the postgres instance
POSTGRES_PASSWORD="-> FILL IN <-"
# this overrides the default database name in postgres
POSTGRES_DB="-> FILL IN <-"

############################################################
# Emails
# Optional.
#########################################################vvv
SMTP_HOST="-> FILL IN <-"
SMTP_PORT=587
SMPT_USERNAME="-> FILL IN <-"
SMPT_PASSWORD="-> FILL IN <-"
############################################################
# SMTP_HOST="-> FILL IN <-"
# SMTP_PORT=587
# SMPT_USERNAME="-> FILL IN <-"
# SMPT_PASSWORD="-> FILL IN <-"

#########################################################vvv
############################################################
# Auth strategies
# At least one needs to be enabled!
#########################################################vvv
############################################################
STRATEGY_LOCAL=true

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

Expand All @@ -34,16 +51,15 @@ STRATEGY_LOCAL=true
# GOOGLE_CLIENT_SECRET="-> FILL IN <-"


#########################################################vvv
############################################################
# Tracing & co.
#########################################################vvv
############################################################
# SENTRY_DSN="-> FILL IN <-"
TELEMETRY=true

#########################################################vvv
############################################################
# Local dev environments
# If your frontend is served in dev from somewhere else,
# this is going to help out :)
#########################################################vvv
# FRONTEND_PORT=8081

############################################################
# FRONTEND_PORT=8081
2 changes: 1 addition & 1 deletion packages/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ exports.startHttp = async ( app ) => {
app.use( Sentry.Handlers.errorHandler( ) )

server.on( 'listening', ( ) => {
debug( 'speckle:startup' )( `🚀 My name is Spockle Server, and I'm running at ${server.address().port}` )
debug( 'speckle:startup' )( `🚀 My name is Speckle Server, and I'm running at ${server.address().port}` )
} )

server.listen( port )
Expand Down
17 changes: 14 additions & 3 deletions packages/server/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,35 @@ function walk( dir ) {

let migrationDirs = walk( './modules' )

// this is for readability, many users struggle to set the postgres connection uri
// in the env variables. This way its a bit easier to understand, also backward compatible.
let env = process.env
let connectionUri
if ( env.POSTGRES_USER && env.POSTGRES_PASSWORD ) {
connectionUri = `postgres://${env.POSTGRES_USER}:${env.POSTGRES_PASSWORD}` +
`@${env.POSTGRES_URL}/${env.POSTGRES_DB}`
} else {
connectionUri = env.POSTGRES_URL
}

module.exports = {
test: {
client: 'pg',
connection: 'postgres://localhost/speckle2_test',
connection: connectionUri || 'postgres://localhost/speckle2_test',
migrations: {
directory: migrationDirs
},
},
development: {
client: 'pg',
connection: process.env.POSTGRES_URL || 'postgres://localhost/speckle2_dev',
connection: connectionUri || 'postgres://localhost/speckle2_dev',
migrations: {
directory: migrationDirs
},
},
production: {
client: 'pg',
connection: process.env.POSTGRES_URL,
connection: connectionUri,
migrations: {
directory: migrationDirs
}
Expand Down
43 changes: 15 additions & 28 deletions packages/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"passport-github2": "^0.1.12",
"passport-google-oauth2": "^0.2.0",
"passport-google-oauth20": "^2.0.0",
"pg": "^7.18.2",
"pg": "^8.5.1",
"pg-query-stream": "^3.4.2",
"redis": "^3.0.2",
"zxcvbn": "^4.4.2"
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ The viewer is a [threejs](https://threejs.org/) extension that allows you to dis

To get started, first clone this repo. Check out the detailed instructions for each module in their respective folder (see links above).

## Bootsrap local Speckle Server

> prerequisites: [Docker](https://docs.docker.com/get-docker/) and [docker-compose](https://docs.docker.com/compose/install/)
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`

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

## 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 cd4e065

Please sign in to comment.