2. Deploy a CubicWeb application

2.1. Deployment with uwsgi

uWSGI is often used to deploy CubicWeb applications.

Short version is install uwsgi:

apt install uwsgi

Deploy a configuration file for your application /etc/uwsgi/apps-enabled/example.ini. Don’t forget to replace example with the instance name to deploy:

master = true
http =
env = CW_INSTANCE=example
module = cubicweb.pyramid:wsgi_application()
processes = 2
threads = 8
plugins = http,python3
auto-procname = true
lazy-apps = true
log-master = true
disable-logging = true

You can run it manualliy with:

uwsgi --ini /etc/uwsgi/apps-enabled/example.ini

2.1.1. Apache configuration

It is possible to use apache (for example) as proxy in front of uwsgi.

For this to work you have to activate the following apache modules :

  • rewrite
  • proxy
  • http_proxy

The command on Debian based systems for that is

a2enmod rewrite http_proxy proxy
/etc/init.d/apache2 restart

For an apache redirection of a site accessible via http://localhost/demo while cubicweb is actually running on port 8080::

ProxyPreserveHost On
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/demo
RewriteRule ^/demo$ /demo/
RewriteRule ^/demo/(.*)$1 [L,P]

and we will configure the base-url in the all-in-one.conf of the instance::

base-url = http://localhost/demo

2.2. Deployment with SaltStack

To deploy with SaltStack one can refer themselves to the cubicweb-formula.

2.3. Deployment with Docker

To deploy in a docker container cluster, you should use our docker image. The source code is also in the forge. For a standard cube with no apt dependencies, the following dockerfile is fine:

FROM logilab/cubicweb:3.29
USER root
COPY . /src
RUN pip install -e /src
USER cubicweb
RUN docker-cubicweb-helper create-instance

To run your instance, don’t forget the port redirection and change the image name:

docker run --rm -it -p 8080:8080 example:latest

If you need to customize the variables in the files all-in-one.conf or sources, you should pass them as environnement variables. For example, the database name is read from CW_DB_NAME. The admin password is read from CW_PASSWORD. Also if the database is on the host, it has to be accessible from the container:

docker run --rm -it -p 8080:8080 --env-file ./.env -v /var/run/postgresql:/var/run/postgresql example:latest

If your instance needs a scheduler, it has to be run in a separate container from the same image:

docker run --rm -it --env-file ./.env -v /var/run/postgresql:/var/run/postgresql example:latest cubicweb-ctl scheduler instance

Don’t forget to change the image name example:latest and the instance name name.

2.4. Deployment with Kubernetes

To deploy in a Kubernetes cluster, you can take inspiration from the deploy instructions included in the fresh cube. It includes nginx to serve static files, one container for the application and one for the scheduler and also an initContainer to automatically upgrade the database in case of new version.