Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Refactor demo Dockerfile

Roland Geider1e8d62f21cbf
diff --git a/extras/docker/demo/Dockerfile b/extras/docker/demo/Dockerfile
index 3e00664fa..60d5af0be 100644
--- a/extras/docker/demo/Dockerfile
+++ b/extras/docker/demo/Dockerfile
@@ -31,12 +31,22 @@ RUN apt update \
libwebp-dev \
libpq-dev \
rustc \
- cargo
+ cargo \
+ yarnpkg \
+ sassc
# Build the necessary python wheels
# Note that the --mount is a workaround for https://github.com/rust-lang/cargo/issues/8719
COPY requirements* ./
-RUN --mount=type=tmpfs,target=/root/.cargo pip3 wheel --no-cache-dir --wheel-dir /wheels -r requirements_docker.txt
+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/*
+
+COPY . /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
########
@@ -69,14 +79,14 @@ RUN a2dissite 000-default.conf \
# Configure cron
COPY ${DOCKER_DIR}/crontab /etc/cron.d/wger
COPY ${DOCKER_DIR}/venvwrapper /home/wger/venvwrapper
-COPY ${DOCKER_DIR}/entrypoint.sh /home/wger/entrypoint.sh
RUN chmod 0644 /etc/cron.d/wger \
- && chmod +x /home/wger/venvwrapper /home/wger/entrypoint.sh \
+ && chmod +x /home/wger/venvwrapper \
&& touch /var/log/cron.log
COPY --from=builder /wheels /wheels
COPY --chown=wger:www-data . /home/wger/src
+COPY --from=builder --chown=wger:wger /home/wger/src/wger/core/static/yarn /home/wger/src/wger/core/static/yarn
# Set up the application
RUN ln -s /home/wger/static/CACHE /var/www
@@ -84,29 +94,31 @@ USER wger
WORKDIR /home/wger/src
RUN python3 -m venv /home/wger/venv
+
+# Change permissions of some files and folders so the apache process
+# can access them.
+RUN mkdir -p ~/static/CACHE ~/media \
+ && ln -s /home/wger/static/CACHE /home/wger/src/CACHE \
+ && chmod g+w /home/wger/static/CACHE
+
RUN . /home/wger/venv/bin/activate \
&& pip install --upgrade pip \
&& pip install --no-cache /wheels/* \
&& pip install -e . \
&& wger create-settings --database-path /home/wger/db/database.sqlite \
- && wger bootstrap \
- && wger load-online-fixtures \
+ && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \
+ && echo STATIC_ROOT=\'/home/wger/static\' >> settings.py \
+ && wger bootstrap --no-process-static \
&& python3 manage.py sync-exercises \
- && python3 manage.py download-exercise-images
+ && wger load-online-fixtures \
+ && python3 manage.py download-exercise-images \
+ && python3 manage.py collectstatic --no-input
-# Change permissions of some files and folders so the apache process
-# can access them.
-RUN mkdir -p ~/static/CACHE ~/media \
- && ln -s /home/wger/static/CACHE /home/wger/src/CACHE \
- && chmod g+w /home/wger/static/CACHE \
- && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \
- && echo STATIC_ROOT=\'/home/wger/static\' >> settings.py
USER root
-RUN apt-get remove build-essential -y \
- && apt autoremove -y \
- && chown :www-data -R /home/wger/db \
+RUN chown :www-data -R /home/wger/db \
+ && chown www-data:www-data -R /home/wger/static \
&& chmod g+w /home/wger/db /home/wger/db/database.sqlite
-ENTRYPOINT ["/home/wger/entrypoint.sh"]
+CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
diff --git a/extras/docker/demo/entrypoint.sh b/extras/docker/demo/entrypoint.sh
deleted file mode 100644
index df5ae7465..000000000
--- a/extras/docker/demo/entrypoint.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-/home/wger/venvwrapper migrate
-
-if [ "${DOWNLOAD_IMGS}" = "TRUE" ]; then
- /home/wger/venvwrapper download-exercise-images
- chmod -R g+w ~wger/media
-fi
-
-/home/wger/venvwrapper collectstatic --no-input
-/home/wger/venvwrapper compress --force
-chown www-data:www-data -R /home/wger/static
-
-/usr/sbin/apache2ctl -D FOREGROUND
diff --git a/extras/docker/production/Dockerfile b/extras/docker/production/Dockerfile
index bb151ab57..39b36ad9b 100644
--- a/extras/docker/production/Dockerfile
+++ b/extras/docker/production/Dockerfile
@@ -37,7 +37,7 @@ RUN --mount=type=tmpfs,target=/root/.cargo \
&& pip3 install --break-system-packages --user --no-cache-dir /wheels/*
# Download and copy js and css files
-COPY --chown=wger:wger . /home/wger/src
+COPY . /home/wger/src
WORKDIR /home/wger/src
RUN ln -s /usr/bin/yarnpkg /usr/bin/yarn \
&& ln -s /usr/bin/sassc /usr/bin/sass \