Browse Source

Merge pull request #1088 from doccano/enhancement/dockerfile

Dockerfile supports doccano v1.x
pull/1092/head
Hiroki Nakayama 4 years ago
committed by GitHub
parent
commit
362df6373a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 60 additions and 85 deletions
  1. 6
      .dockerignore
  2. 8
      .travis.yml
  3. 84
      Dockerfile
  4. 9
      app/app/settings.py
  5. 11
      app/app/urls.py
  6. 2
      app/requirements.txt
  7. 7
      frontend/assets/README.md
  8. BIN
      frontend/assets/feature1.png
  9. BIN
      frontend/assets/feature2.png
  10. BIN
      frontend/assets/feature3.png
  11. BIN
      frontend/assets/ner_demo.png
  12. 2
      frontend/assets/style/app.styl
  13. 1
      frontend/assets/style/variables.styl
  14. BIN
      frontend/assets/vbanner.jpg
  15. 8
      frontend/components/organisms/layout/FeatureCards.vue
  16. 4
      frontend/components/organisms/layout/TheBottomBanner.vue
  17. 2
      frontend/components/organisms/layout/TheTopBanner.vue
  18. 1
      frontend/nuxt.config.js

6
.dockerignore

@ -1,5 +1,6 @@
*
!app/
!frontend/
!tests/
!tools/
!.coveragerc
@ -18,3 +19,8 @@ app/**/staticfiles/
app/**/venv/
app/**/__pycache__/
tests/**/__pycache__/
frontend/.nuxt/
frontend/coverage/
frontend/dist/
frontend/node_modules/

8
.travis.yml

@ -5,9 +5,9 @@ python:
env:
- DATABASE=sqlite
- DATABASE=postgres
- DATABASE=mssql
- DATABASE=mysql
# - DATABASE=postgres
# - DATABASE=mssql
# - DATABASE=mysql
services:
- docker
@ -33,7 +33,7 @@ install:
- pip install --no-cache-dir mkdocs==1.1 mkdocs-material==4.6.3
script:
- docker build --target=builder --tag=doccano-test .
- docker build --target=runtime --tag=doccano-test .
- >
if [[ "${DATABASE}" != "sqlite" ]]; then
docker run --network doccano -e DATABASE_URL="${DATABASE_URL}" -it doccano-test sh -c 'app/manage.py wait_for_db && app/manage.py migrate && app/manage.py test api.tests server.tests'

84
Dockerfile

@ -1,61 +1,49 @@
ARG PYTHON_VERSION="3.6"
FROM python:${PYTHON_VERSION}-stretch AS builder
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG NODE_VERSION="8.x"
# hadolint ignore=DL3008
RUN curl -sL "https://deb.nodesource.com/setup_${NODE_VERSION}" | bash - \
&& apt-get install --no-install-recommends -y \
nodejs
ARG HADOLINT_VERSION=v1.17.1
RUN curl -fsSL "https://github.com/hadolint/hadolint/releases/download/${HADOLINT_VERSION}/hadolint-Linux-$(uname -m)" -o /usr/local/bin/hadolint \
&& chmod +x /usr/local/bin/hadolint
COPY tools/install-mssql.sh /doccano/tools/install-mssql.sh
RUN /doccano/tools/install-mssql.sh --dev
COPY app/server/static/package*.json /doccano/app/server/static/
WORKDIR /doccano/app/server/static
RUN npm ci
COPY requirements.txt /
RUN pip install --no-cache-dir -r /requirements.txt \
ARG PYTHON_VERSION="3.8.6"
ARG NODE_VERSION="13.7"
FROM node:${NODE_VERSION}-alpine AS frontend-builder
COPY frontend/ /frontend/
WORKDIR /frontend
ENV PUBLIC_PATH="/static/_nuxt/"
# hadolint ignore=DL3018
RUN apk add -U --no-cache git python3 make g++ \
&& yarn install \
&& yarn build \
&& apk del --no-cache git make g++
FROM python:${PYTHON_VERSION}-slim-buster AS backend-builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
netcat=1.10-41.1 \
libpq-dev=11.9-0+deb10u1 \
unixodbc-dev=2.3.6-0.1 \
g++=4:8.3.0-1 \
&& apt-get clean
COPY /app/requirements.txt /
# hadolint ignore=DL3013
RUN pip install --no-cache-dir -U pip \
&& pip install --no-cache-dir -r /requirements.txt \
&& pip wheel --no-cache-dir -r /requirements.txt -w /deps
COPY Dockerfile /
RUN hadolint /Dockerfile
COPY . /doccano
WORKDIR /doccano
RUN tools/ci.sh
FROM builder AS cleaner
WORKDIR /doccano/app/server/static
RUN SOURCE_MAP=False DEBUG=False npm run build \
&& rm -rf components pages node_modules .*rc package*.json webpack.config.js
WORKDIR /doccano
RUN python app/manage.py collectstatic --noinput
FROM python:${PYTHON_VERSION}-slim-stretch AS runtime
COPY --from=builder /doccano/tools/install-mssql.sh /doccano/tools/install-mssql.sh
RUN /doccano/tools/install-mssql.sh
FROM python:${PYTHON_VERSION}-slim-buster AS runtime
RUN useradd -ms /bin/sh doccano
RUN mkdir /data \
&& chown doccano:doccano /data
COPY --from=builder /deps /deps
COPY --from=backend-builder /deps /deps
# hadolint ignore=DL3013
RUN pip install --no-cache-dir /deps/*.whl
RUN pip install --no-cache-dir -U pip \
&& pip install --no-cache-dir /deps/*.whl
COPY --from=cleaner --chown=doccano:doccano /doccano /doccano
COPY --chown=doccano:doccano . /doccano
WORKDIR /doccano
COPY --from=frontend-builder /frontend/dist /doccano/app/client/dist
RUN python app/manage.py collectstatic --noinput
VOLUME /data
ENV DATABASE_URL="sqlite:////data/doccano.db"

9
app/app/settings.py

@ -92,7 +92,7 @@ ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [path.join(BASE_DIR, 'server/templates'), path.join(BASE_DIR, 'authentification/templates')],
'DIRS': [path.join(BASE_DIR, 'client/dist')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@ -118,12 +118,7 @@ STATIC_URL = '/static/'
STATIC_ROOT = path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
static_path
for static_path in (
path.join(BASE_DIR, 'server', 'static', 'assets'),
path.join(BASE_DIR, 'server', 'static', 'static'),
)
if path.isdir(static_path)
path.join(BASE_DIR, 'client/dist/static'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

11
app/app/urls.py

@ -15,12 +15,11 @@ Including another URLconf
"""
from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth.views import PasswordResetView, LogoutView
from django.urls import path, include, re_path
from django.contrib.auth.views import TemplateView
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from server.views import LoginView
# TODO: adds AnnotationList and AnnotationDetail endpoint.
schema_view = get_schema_view(
@ -34,16 +33,12 @@ schema_view = get_schema_view(
)
urlpatterns = [
path('', include('authentification.urls')),
path('', include('server.urls')),
path('admin/', admin.site.urls),
path('social/', include('social_django.urls')),
path('login/', LoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(), name='logout'),
path('password_reset/', PasswordResetView.as_view(), name='password_reset'),
path('api-auth/', include('rest_framework.urls')),
path('v1/', include('api.urls')),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path('', TemplateView.as_view(template_name='index.html')),
]
if 'cloud_browser' in settings.INSTALLED_APPS:

2
app/requirements.txt

@ -26,7 +26,7 @@ furl==2.0.0
gunicorn==19.9.0
lockfile==0.12.2
model-mommy==1.6.0
psycopg2-binary==2.7.7
psycopg2-binary==2.8.6
pyexcel==0.5.14
pyexcel-xlsx==0.5.7
python-dateutil==2.7.3

7
frontend/assets/README.md

@ -1,7 +0,0 @@
# ASSETS
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).

BIN
frontend/assets/feature1.png

Before After
Width: 952  |  Height: 366  |  Size: 12 KiB

BIN
frontend/assets/feature2.png

Before After
Width: 723  |  Height: 467  |  Size: 2.1 KiB

BIN
frontend/assets/feature3.png

Before After
Width: 687  |  Height: 413  |  Size: 46 KiB

BIN
frontend/assets/ner_demo.png

Before After
Width: 1582  |  Height: 711  |  Size: 172 KiB

2
frontend/assets/style/app.styl

@ -1,2 +0,0 @@
// Import Vuetify styling
@require '~vuetify/src/stylus/app.styl'

1
frontend/assets/style/variables.styl

@ -1 +0,0 @@
@require '~vuetify/src/stylus/settings/_variables.styl'

BIN
frontend/assets/vbanner.jpg

Before After
Width: 1920  |  Height: 1080  |  Size: 316 KiB

8
frontend/components/organisms/layout/FeatureCards.vue

@ -23,7 +23,7 @@
md4
>
<feature-card
:image-src="item.imageSrc"
:image-src="require(`~/assets/${item.imageSrc}`)"
:title="item.title"
:text="item.text"
/>
@ -47,17 +47,17 @@ export default {
return {
featureCards: [
{
imageSrc: '/images/feature3.png',
imageSrc: 'feature3.png',
title: this.$t('home.featuresTitle1'),
text: this.$t('home.featuresText1')
},
{
imageSrc: '/images/feature2.png',
imageSrc: 'feature2.png',
title: this.$t('home.featuresTitle2'),
text: this.$t('home.featuresText2')
},
{
imageSrc: '/images/feature1.png',
imageSrc: 'feature1.png',
title: this.$t('home.featuresTitle3'),
text: this.$t('home.featuresText3')
}

4
frontend/components/organisms/layout/TheBottomBanner.vue

@ -1,7 +1,7 @@
<template>
<section>
<v-parallax
src="/images/vbanner.jpg"
:src="require(`~/assets/vbanner.jpg`)"
height="400"
dark
>
@ -17,7 +17,7 @@
md7
>
<v-img
src="/images/ner_demo.png"
:src="require(`~/assets/ner_demo.png`)"
max-height="380"
contain
class="ma-5"

2
frontend/components/organisms/layout/TheTopBanner.vue

@ -1,7 +1,7 @@
<template>
<section>
<v-parallax
src="/images/vbanner.jpg"
:src="require(`~/assets/vbanner.jpg`)"
height="400"
dark
>

1
frontend/nuxt.config.js

@ -124,6 +124,7 @@ export default {
/*
** You can extend webpack config here
*/
publicPath: process.env.PUBLIC_PATH || '/_nuxt/',
extend(config, ctx) {
config.module.rules.push({
test: /\.(txt|csv|conll|jsonl)$/i,

Loading…
Cancel
Save