From ed43cd55aca2e5225b8d114e773b6af35eec86a8 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Sat, 1 Sep 2018 11:21:04 +0100 Subject: [PATCH] Add multi-stage docker build for production w/ node & python --- .../compose/production/django/Dockerfile | 21 +++++++++++++++++-- {{cookiecutter.project_slug}}/gulpfile.js | 14 +++++++++++++ {{cookiecutter.project_slug}}/package.json | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile index 68d72327f..cf4f3503f 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile @@ -1,3 +1,14 @@ +{% if cookiecutter.js_task_runner == 'Gulp' -%} +FROM node:8-alpine as client-builder + +WORKDIR /app +COPY ./package.json /app +RUN npm install && npm cache clean --force +COPY . /app +RUN npm run build + +# Python build stage +{%- endif %} FROM python:3.6-alpine ENV PYTHONUNBUFFERED 1 @@ -28,7 +39,8 @@ COPY ./compose/production/django/start /start RUN sed -i 's/\r//' /start RUN chmod +x /start RUN chown django /start -{% if cookiecutter.use_celery == "y" %} + +{%- if cookiecutter.use_celery == "y" %} COPY ./compose/production/django/celery/worker/start /start-celeryworker RUN sed -i 's/\r//' /start-celeryworker RUN chmod +x /start-celeryworker @@ -42,8 +54,13 @@ RUN chown django /start-celerybeat COPY ./compose/production/django/celery/flower/start /start-flower RUN sed -i 's/\r//' /start-flower RUN chmod +x /start-flower -{% endif %} +{%- endif %} + +{%- if cookiecutter.js_task_runner == 'Gulp' %} +COPY --from=client-builder /app /app +{% else %} COPY . /app +{%- endif %} RUN chown -R django /app diff --git a/{{cookiecutter.project_slug}}/gulpfile.js b/{{cookiecutter.project_slug}}/gulpfile.js index 0e87da6ea..d2fd36d18 100644 --- a/{{cookiecutter.project_slug}}/gulpfile.js +++ b/{{cookiecutter.project_slug}}/gulpfile.js @@ -137,6 +137,20 @@ gulp.task('watch', function() { }); +// Build task +gulp.task('build', + [ + 'styles', + 'scripts', + {%- if cookiecutter.custom_bootstrap_compilation == 'y' %} + 'vendor-scripts', + {%- endif %} + 'imgCompression' + ], + function () { + console.log('Build complete!') +}); + // Default task gulp.task('default', function() { runSequence( diff --git a/{{cookiecutter.project_slug}}/package.json b/{{cookiecutter.project_slug}}/package.json index ae3db052c..4ee7df4d7 100644 --- a/{{cookiecutter.project_slug}}/package.json +++ b/{{cookiecutter.project_slug}}/package.json @@ -34,7 +34,8 @@ }, "scripts": { {% if cookiecutter.js_task_runner == 'Gulp' -%} - "dev": "gulp" + "dev": "gulp", + "build": "gulp build" {%- endif %} } }