Configuration
Services
Coherence supports any application that can be containerized and which serves HTTP traffic. Here are some common examples. Be sure to review the documentation on database seeding and loading data from database snopshots, which apply to all Coherence applications.
Redwood.js
See a full example repo here. The Dockerfile
s are optional - we will build your app with nixpacks if you do not provide them.
api:
type: backend
url_path: "/api"
prod:
dockerfile: Dockerfile.api
command: ["yarn", "rw", "serve", "api"]
dev:
command: ["yarn", "rw", "dev", "api"]
local_packages: ["node_modules"]
system:
cpu: 2
memory: 2G
health_check: "/graphql/health"
resources:
- name: db1
engine: postgres
version: 13
type: database
web:
type: frontend
assets_path: "web/dist"
prod:
dockerfile: Dockerfile.web
command: ["yarn", "rw", "serve", "web"]
dev:
command: ["yarn", "rw", "dev", "web", "--fwd=\"--allowed-hosts all\""]
build: ["yarn", "rw", "build", "web"]
local_packages: ["node_modules"]
system:
cpu: 2
memory: 2G
React Exmaple
See a full example repo here.
frontend:
type: frontend
assets_path: dist
local_packages: ["node_modules"]
install: ["yarn", "install"]
build: ["yarn", "build"]
dev: ["yarn", "dev"]
Django Example
See a full example repo (this repo includes a react frontend and a django backend) here. A few other things you'd want to do:
- Install dj-database-url package to easily get the right database configuration. You can add this to your
requirements.txt
file. - Make sure to use
COHERENCE_DEV
environment variable to set theDEBUG
value in your settings. - Add the
COHERENCE_ENVIRONMENT_DOMAIN
andCOHERENCE_CUSTOM_DOMAIN
to theALLOWED_HOSTS
settings to prevent CORS issues. - You can configure the
prod
command to use another python WSGI server like gunicorn as well by changing the command in theyaml
configuration below.
See the Environment Variables docs for more info on the variables mentioned above.
server:
type: backend
repo_path: backend
migration: ["python", "manage.py", "migrate"]
dev: ["python", "manage.py", "runserver", "0.0.0.0:$PORT"]
prod: ["python", "manage.py", "collectstatic", "&&", "python", "manage.py", "runserver", "0.0.0.0:$PORT"]
resources:
- name: db1
engine: postgres
version: 13
type: database
- name: redis
engine: redis
version: 4
type: cache
Rails Example
You need to make sure to either collect static assets in your docker build, or include in the prod
command below...
server:
type: backend
repo_path: backend
migration: ["rails", "server:migrate"]
dev: ["rails", "server", "-p", "$PORT"]
prod: ["rails", "server", "-e", "production", "-p", "$PORT"]
system:
memory: 2G
cpu: 1
resources:
- name: db1
engine: mysql
version: 8.0
type: database
- name: redis
engine: redis
version: 4
type: cache
flask example
flask is a popular python web framework. This is a simple example, assuming your app does not need a database and that your app.py
file runs the flask server on the PORT
environment variable provided by Coherence when it is run via python
. You can configure the dev
or prod
commands to use flask run
or another python WSGI server like gunicorn as well by changing the commands in the yaml
configuration below.
You can also add a database and cache easily, see the other examples on this page including the redwood
and Rails
examples above for syntax, nothing special needs to be done for flask
itself, aside from listening to the appropriate variables to configure your database connections, e.g. DATABASE_URL
.
backend:
type: "backend"
dev: ["python", "app.py"]
prod: ["python", "app.py"]
Next.js Example
There are 2 common configurations used for Next.js. One is static export where your site ends up as single page app served from a CDN. The other (more common) configuration is where you run a server process and this configuration supports functionality such as server-side rendering, API routes, and database-backed services. See more in the Next docs.
For running a server process, use the backend
service type on Coherence. See a full example repo here.
backend:
type: backend
local_packages: ["node_modules"]
dev: ["npm", "run", "dev"]
prod: ["npm", "run", "start"]
For deploying a single page app, use a frontend
service type.
frontend:
type: frontend
local_packages: ["node_modules"]
dev: ["npm", "run", "dev"]
build: ["npm", "run", "export"]