From 8bb860a865df803ac992663454928e65b5b5036c Mon Sep 17 00:00:00 2001 From: Jfriedli Date: Sun, 21 Mar 2021 15:31:51 +0100 Subject: [PATCH] build css in an intermediate container --- .dockerignore | 2 -- .gitlab-ci.yml | 2 -- Dockerfile.production | 12 +++++++++++- main.py | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6f3416a..e2eb2a4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,4 @@ uploads node_modules static/dist static/.webassets-cache -*.js -*.json *.md \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dd34900..0369d3e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,8 +36,6 @@ tests:debian: stage: test before_script: - apt update - - apt install nodejs npm - - npm install --global postcss script: - apt-get -qqy update - apt-get -qqy install --no-install-recommends mat2 python3-flask python3-coverage python3-pip python3-setuptools diff --git a/Dockerfile.production b/Dockerfile.production index 7381f74..0855297 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -1,5 +1,11 @@ +# Build the needed css files in an intermediate container +FROM node:14-buster AS static_web_assets_build +WORKDIR /var/www/mat2-web +COPY . /var/www/mat2-web +RUN npm install \ + && npm install --global postcss \ + && npm run build:css # https://github.com/nginxinc/docker-nginx-unprivileged/blob/master/stable/buster/Dockerfile - From debian:buster-slim LABEL maintainer="Mat-Web Co-Maintainer " @@ -7,6 +13,7 @@ LABEL maintainer="Mat-Web Co-Maintainer " WORKDIR /var/www/mat2-web COPY . /var/www/mat2-web +COPY --from=static_web_assets_build /var/www/mat2-web/static/dist ./static/dist ENV MAT2_WEB_DOWNLOAD_FOLDER /app/upload @@ -38,6 +45,9 @@ RUN set -x \ && mkdir -p /var/cache/nginx \ && chown -R 101:0 /var/cache/nginx \ && chmod -R g+w /var/cache/nginx \ + && mkdir -p /var/www/mat2-web/static/.webassets-cache \ + && chown -R 101:0 /var/www/mat2-web/static/.webassets-cache \ + && chmod -R g+w /var/www/mat2-web/static/.webassets-cache \ && ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log \ && rm -rf /var/cache/apt/* /var/lib/apt/lists/* \ diff --git a/main.py b/main.py index 1fe0e62..0313a25 100644 --- a/main.py +++ b/main.py @@ -23,7 +23,7 @@ def create_app(test_config=None): # Non JS Frontend assets = Environment(app) - css = Bundle("src/main.css", output="dist/main.css", filters="postcss") + css = Bundle("src/main.css", output="dist/main.css") assets.register("css", css) css.build() app.jinja_loader = jinja2.ChoiceLoader([ # type: ignore