Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #795 from open-craft/joaocabrita/ocim_in_docker
Browse files Browse the repository at this point in the history
feature: Added ability to run OCIM in a container.
  • Loading branch information
João Cabrita committed Jun 16, 2021
2 parents e8d8327 + 9460dcb commit 6a340f5
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 5 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frontend/node_modules/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ media/
# Generated scripts
bin/archived_cleanup.sh

# used for customizing docker compose
docker-compose.override.yml
15 changes: 15 additions & 0 deletions Dockerfile.ocim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.6

WORKDIR /usr/src/ocim

COPY requirements.txt ./
COPY requirements/ requirements/
RUN pip install -r requirements.txt

COPY Makefile \
package.json \
./
COPY frontend/ frontend/
COPY static/ static/

CMD ["make", "run.dev"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ run: clean migrations.check static ## Run Ocim in a production setting with conc
honcho start --concurrency "worker=$(WORKERS),worker_low_priority=$(WORKERS_LOW_PRIORITY)"

run.dev: clean migrations.check static_external ## Run the developmental server using `runserver_plus`.
honcho start -f Procfile.dev
python3 manage.py runserver 0.0.0.0:5000

shell: ## Start the power shell.
HUEY_QUEUE_NAME=opencraft_low_priority $(HONCHO_MANAGE) shell_plus
Expand Down
58 changes: 58 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Docker Compose file for the services needed by Ocim, for easy local development setup

version: "3.6"

services:

postgresql:
image: postgres:12.6-alpine
environment:
POSTGRES_USER: opencraft
POSTGRES_DB: opencraft
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_INITDB_ARGS: --encoding utf-8
volumes:
- /var/lib/postgresql/data
ports:
- "5432:5432"

redis:
image: postgres:12.6-alpine
image: redis:4
ports:
- "6379:6379"

ocim:
build:
context: .
dockerfile: Dockerfile.ocim
depends_on:
- postgresql
- redis
env_file: .env
environment:
ALLOWED_HOSTS: '["*"]'
DATABASE_URL: '${DATABASE_URL:-postgres://opencraft@postgresql/opencraft}'
REDIS_URL: '${REDIS_URL:-redis://redis:6379}'
ports:
- "127.0.0.1:5000:5000"
volumes:
- ./:/usr/src/ocim/

ocim-frontend:
build:
context: frontend/
depends_on:
- ocim
environment: {}
ports:
- "127.0.0.1:3000:3000"
tty: true
volumes:
- ./frontend:/usr/src/ocim-frontend/
- ./static:/usr/src/static

volumes: {}

networks:
default:
59 changes: 59 additions & 0 deletions documentation/development/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Docker

This describes how to create an environment for development using Docker.

**This is still experimental, using [Vagrant](../installation.md) is much better tested and supported!**

## Running OCIM in a docker container

First, set your `.env` file as you would normally:
```env
DEBUG=True
OPENSTACK_USER='username'
OPENSTACK_PASSWORD='password'
OPENSTACK_TENANT='tenant-name'
OPENSTACK_AUTH_URL='https://auth.cloud.ovh.net/v2.0'
OPENSTACK_REGION='BHS1'
OPENSTACK_SANDBOX_SSH_KEYNAME='keypair-name'
DEFAULT_INSTANCE_BASE_DOMAIN='example.com'
GANDI_API_KEY='api-key'
GITHUB_ACCESS_TOKEN='github-token'
SECRET_KEY='tests'
DEFAULT_INSTANCE_MYSQL_URL=...
DEFAULT_RABBITMQ_API_URL=...
DEFAULT_INSTANCE_RABBITMQ_URL=...
DEFAULT_MONGO_REPLICA_SET_USER=...
DEFAULT_MONGO_REPLICA_SET_PASSWORD=...
DEFAULT_MONGO_REPLICA_SET_NAME=...
DEFAULT_MONGO_REPLICA_SET_PRIMARY=...
DEFAULT_MONGO_REPLICA_SET_HOSTS=...
REDIS_URL=...
```

Start a one-off container for setup of the backend:
```sh
# --rm destroys the container at the end
docker-compose run --rm ocim bash

# then, inside the container...

# initialize datastores
make migrate
# create super user
make manage createsuperuser
# exit the container
exit
```

Then, start another one-off container for setting up the client-facing frontend:
```sh
docker-compose run --rm ocim-frontend bash -c 'npm run build-api-client && npm install'
```

Then, start OCIM:
```sh
docker-compose up
```

The OCIM UI should be available at http://localhost:5000 .
The registration UI should be available at http://localhost:3000 .
5 changes: 2 additions & 3 deletions documentation/installation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Installation
------------
# Installation

### Vagrant installation
## Vagrant installation

For development, we recommend using [Vagrant](https://www.vagrantup.com/)
to automatically provision a development environment in a virtual machine. This
Expand Down
2 changes: 2 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
node_modules/
19 changes: 19 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:11.15.0

# https://github.com/Automattic/node-canvas#compiling
RUN apt-get update \
&& apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev

WORKDIR /usr/src/ocim-frontend
COPY ./ /usr/src/ocim-frontend

# Move node_modules out of the source path
RUN npm install -g --unsafe-perm

CMD [ "npm", "start" ]
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ nav:
- howtos.md
- periodic_builds.md
- infrastructure.md
- "Development":
- "Docker": development/docker.md
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile --output-file=requirements/dev.txt requirements/dev.in
#
-e git+https://github.com/open-craft/django-angular.git@v1-with-django2-support#egg=django_angular
git+https://github.com/open-craft/django-angular.git@v1-with-django2-support#egg=django_angular
# via -r requirements/base.in
aioredis==1.3.1
# via channels-redis
Expand Down

0 comments on commit 6a340f5

Please sign in to comment.