From 402f9fe8e529a2e7a76861d57ba708e8addb546e Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Thu, 16 May 2019 14:09:03 -0400 Subject: [PATCH 1/2] Move database setup instructions to usage section --- README.md | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ec3dba48..443f3df6 100644 --- a/README.md +++ b/README.md @@ -108,39 +108,6 @@ npm run build # npm start # for developers ``` -Next we need to make migration. Run the following command: - -```bash -python manage.py migrate -``` - -Next we need to create a user who can login to the admin site. Run the following command: - - -```bash -python manage.py createsuperuser -``` - -Enter your desired username and press enter. - -```bash -Username: admin -``` - -You will then be prompted for your desired email address: - -```bash -Email address: admin@example.com -``` - -The final step is to enter your password. You will be asked to enter your password twice, the second time as a confirmation of the first. - -```bash -Password: ********** -Password (again): ********* -Superuser created successfully. -``` - ## Usage ### Start the development server @@ -165,6 +132,20 @@ docker exec doccano tools/create-admin.sh "admin" "admin@example.com" "password" **Option2: Running Django development server** +Before running, we need to make migration. Run the following command: + +```bash +python manage.py migrate +``` + +Next we need to create a user who can login to the admin site. Run the following command: + +```bash +python manage.py create_admin --noinput --username "admin" --email "admin@example.com" --password "password" +``` + +Finally, to start the server, run the following command: + ```bash python manage.py runserver ``` From 996d67ad5486f103ba1ff933e3849f6482b22cfb Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Thu, 16 May 2019 14:08:46 -0400 Subject: [PATCH 2/2] Add compose file for development setup --- README.md | 18 ++++++++++++++-- app/server/webpack.config.js | 10 ++++++++- docker-compose.yml | 42 ++++++++++++++++++++++++++++++++++++ tools/dev-django.sh | 33 ++++++++++++++++++++++++++++ tools/dev-webpack.sh | 18 ++++++++++++++++ 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yml create mode 100755 tools/dev-django.sh create mode 100755 tools/dev-webpack.sh diff --git a/README.md b/README.md index 443f3df6..93430988 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ git clone https://github.com/chakki-works/doccano.git cd doccano ``` -To install doccano, there are two options: +To install doccano, there are three options: -**Option1: Pull the Docker image** +**Option1: Pull the production Docker image** ```bash docker pull chakkiworks/doccano @@ -108,6 +108,12 @@ npm run build # npm start # for developers ``` +**Option3: Pull the development Docker-Compose images** + +```bash +docker-compose pull +``` + ## Usage ### Start the development server @@ -150,6 +156,14 @@ Finally, to start the server, run the following command: python manage.py runserver ``` +**Option3: Running the development Docker-Compose stack** + +We can use docker-compose to set up the webpack server, django server, database, etc. all in one command: + +```bash +docker-compose up +``` + Now, open a Web browser and go to . You should see the login screen: Login Form diff --git a/app/server/webpack.config.js b/app/server/webpack.config.js index 7477d93a..8f260bcc 100644 --- a/app/server/webpack.config.js +++ b/app/server/webpack.config.js @@ -4,6 +4,9 @@ const VueLoaderPlugin = require('vue-loader/lib/plugin') const devMode = process.env.DEBUG !== 'False'; const hotReload = process.env.HOT_RELOAD === '1'; +const webpackHost = process.env.WEBPACK_HOST || '127.0.0.1'; +const webpackPort = process.env.WEBPACK_PORT ? parseInt(process.env.WEBPACK_PORT, 10) : 8080; +const pollMillis = process.env.WEBPACK_POLL_MILLIS ? parseInt(process.env.WEBPACK_POLL_MILLIS, 10) : false; module.exports = { mode: devMode ? 'development' : 'production', @@ -27,16 +30,21 @@ module.exports = { 'download_text_classification': './static/js/download_text_classification.js', }, output: { - publicPath: hotReload ? 'http://localhost:8080/' : '', + publicPath: hotReload ? `http://127.0.0.1:${webpackPort}/` : '', path: __dirname + '/static/bundle', filename: '[name].js' }, devtool: devMode ? 'cheap-eval-source-map' : 'source-map', devServer: { + port: webpackPort, + host: webpackHost, hot: true, quiet: false, headers: { 'Access-Control-Allow-Origin': '*' } }, + watchOptions: { + poll: pollMillis, + }, module: { rules: [ { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..500e4239 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: "3" +services: + + django: + image: python:3.6 + volumes: + - .:/src + - venv:/src/venv + command: ["/src/tools/dev-django.sh", "0.0.0.0:8000"] + environment: + ADMIN_USERNAME: "admin" + ADMIN_PASSWORD: "password" + ADMIN_EMAIL: "admin@example.com" + DATABASE_URL: "postgres://doccano:doccano@postgres:5432/doccano?sslmode=disable" + ports: + - 8000:8000 + + webpack: + image: node:8 + volumes: + - .:/src + - node_modules:/src/app/server/node_modules + command: ["/src/tools/dev-webpack.sh"] + environment: + WEBPACK_HOST: "0.0.0.0" + WEBPACK_PORT: "8080" + WEBPACK_POLL_MILLIS: "1000" + ports: + - 8080:8080 + + postgres: + image: postgres:9.6 + environment: + POSTGRES_USER: "doccano" + POSTGRES_PASSWORD: "doccano" + POSTGRES_DB: "doccano" + ports: + - 5432:5432 + +volumes: + node_modules: + venv: diff --git a/tools/dev-django.sh b/tools/dev-django.sh new file mode 100755 index 00000000..a6d70df6 --- /dev/null +++ b/tools/dev-django.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -o errexit + +root="$(dirname "$0")/.." +app="${root}/app" +venv="${root}/venv" + +if [[ ! -f "${venv}/bin/python" ]]; then + echo "Creating virtualenv" + mkdir -p "${venv}" + python3 -m venv "${venv}" + "${venv}/bin/pip" install --upgrade pip setuptools +fi + +echo "Installing dependencies" +"${venv}/bin/pip" install -r "${root}/requirements.txt" + +echo "Initializing database" +"${venv}/bin/python" "${app}/manage.py" wait_for_db +"${venv}/bin/python" "${app}/manage.py" migrate + +if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMIN_EMAIL}" ]]; then + "${venv}/bin/python" "${app}/manage.py" create_admin \ + --username "${ADMIN_USERNAME}" \ + --password "${ADMIN_PASSWORD}" \ + --email "${ADMIN_EMAIL}" \ + --noinput \ + || true +fi + +echo "Starting django" +"${venv}/bin/python" -u "${app}/manage.py" runserver "$@" diff --git a/tools/dev-webpack.sh b/tools/dev-webpack.sh new file mode 100755 index 00000000..fea3cf3e --- /dev/null +++ b/tools/dev-webpack.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -o errexit + +root="$(dirname "$0")/.." +server="${root}/app/server" + +( + cd "${server}" + + if [[ ! -d node_modules/.bin ]]; then + echo "Installing dependencies" + npm install + fi + + echo "Starting webpack" + npm start +)