Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Download and compile js and css files during build

Roland Geidere0217866389c
diff --git a/extras/docker/base/Dockerfile b/extras/docker/base/Dockerfile
index 881591fd9..8692c2828 100644
--- a/extras/docker/base/Dockerfile
+++ b/extras/docker/base/Dockerfile
@@ -18,13 +18,11 @@ RUN apt update \
&& apt install --no-install-recommends -y \
adduser \
locales \
- yarnpkg \
python3-pip \
sqlite3 \
wget \
tzdata \
libpq5 \
- sassc \
&& locale-gen en_US.UTF-8
# Environmental variables
@@ -37,6 +35,5 @@ ENV PYTHONUNBUFFERED=1
# Add wger user
-RUN ln -s /usr/bin/yarnpkg /usr/bin/yarn
-RUN ln -s /usr/bin/sassc /usr/bin/sass
-RUN adduser wger --disabled-password --gecos ""
+RUN deluser ubuntu
+RUN adduser wger --uid 1000 --disabled-password --gecos ""
diff --git a/extras/docker/development/Dockerfile b/extras/docker/development/Dockerfile
index 5a7a84182..9055cb021 100644
--- a/extras/docker/development/Dockerfile
+++ b/extras/docker/development/Dockerfile
@@ -25,8 +25,9 @@ RUN apt update \
libwebp-dev \
libpq-dev \
rustc \
- cargo \
- && pip install --upgrade pip
+ yarnpkg \
+ sassc \
+ cargo
# Build the necessary python wheels
# Note that the --mount tmpfs is a workaround for https://github.com/rust-lang/cargo/issues/8719
@@ -35,6 +36,13 @@ RUN --mount=type=tmpfs,target=/root/.cargo \
pip3 wheel --no-cache-dir --wheel-dir /wheels -r requirements_docker.txt \
&& pip3 install --break-system-packages --user --no-cache-dir /wheels/*
+# Download and copy js and css files
+COPY --chown=wger:wger . /home/wger/src
+WORKDIR /home/wger/src
+RUN ln -s /usr/bin/yarnpkg /usr/bin/yarn \
+ && ln -s /usr/bin/sassc /usr/bin/sass \
+ && yarn install \
+ && yarn build:css:sass
########
@@ -52,6 +60,7 @@ EXPOSE 8000
WORKDIR /home/wger/src
COPY --chown=wger:wger . /home/wger/src
COPY --from=builder --chown=wger:wger /root/.local /home/wger/.local
+COPY --from=builder --chown=wger:wger /home/wger/src/wger/core/static/yarn /home/wger/src/wger/core/static/yarn
COPY ${DOCKER_DIR}/settings.py /home/wger/src
COPY ${DOCKER_DIR}/settings.py /tmp/
COPY ${DOCKER_DIR}/entrypoint.sh /home/wger/entrypoint.sh
diff --git a/extras/docker/development/entrypoint.sh b/extras/docker/development/entrypoint.sh
index 9a65bb6fc..b67c646c1 100644
--- a/extras/docker/development/entrypoint.sh
+++ b/extras/docker/development/entrypoint.sh
@@ -2,7 +2,7 @@
# Copy a settings file if nothing's found (e.g. when mounting a fresh checkout)
# This is a bit ugly, but it's needed since we use this image for development
-# and "production".
+# and production.
if [ ! -f /home/wger/src/settings.py ]; then
cp /tmp/settings.py /home/wger/src
fi
@@ -19,9 +19,16 @@ fi
# Bootstrap the application
# * Load the fixtures with exercises, ingredients, etc
# * Create an admin user
-# * Download JS and CSS files
-# * Compile custom bootstrap theme
-wger bootstrap
+# * (optionally) Download JS and CSS files
+# * (optionally) Compile custom bootstrap theme
+
+if [ "$YARN_PROCESS_STATIC" == "True" ]; then
+ yarn_static=""
+else
+ yarn_static="--no-process-static"
+fi
+
+wger bootstrap yarn_static
# Collect static files
if [ "$DJANGO_CLEAR_STATIC_FIRST" == "False" ]; then
diff --git a/wger/tasks.py b/wger/tasks.py
index 81669a12f..34752a852 100644
--- a/wger/tasks.py
+++ b/wger/tasks.py
@@ -34,7 +34,6 @@ import requests
from invoke import task
from tqdm import tqdm
-
logger = logging.getLogger(__name__)
FIXTURE_URL = 'https://github.com/wger-project/data/raw/master/fixtures/'
@@ -45,7 +44,7 @@ FIXTURE_URL = 'https://github.com/wger-project/data/raw/master/fixtures/'
'port': 'Port to use. Default: 8000',
'settings-path': 'Path to settings file (absolute path). Leave empty for default',
'extra-args': 'Additional arguments to pass to the builtin server. Pass as string: '
- '"--arg1 --arg2=value". Default: none',
+ '"--arg1 --arg2=value". Default: none',
}
)
def start(context, address='localhost', port=8000, settings_path=None, extra_args=''):
@@ -70,7 +69,7 @@ def start(context, address='localhost', port=8000, settings_path=None, extra_arg
'database-path': 'Path to sqlite database (absolute path). Leave empty for default',
}
)
-def bootstrap(context, settings_path=None, database_path=None):
+def bootstrap(context, settings_path=None, database_path=None, process_static=True):
"""
Performs all steps necessary to bootstrap the application
"""
@@ -92,8 +91,9 @@ def bootstrap(context, settings_path=None, database_path=None):
create_or_reset_admin(context, settings_path=settings_path)
# Download JS and CSS libraries
- context.run('yarn install')
- context.run('yarn build:css:sass')
+ if process_static:
+ context.run('yarn install')
+ context.run('yarn build:css:sass')
@task(