From 9014e6c5dfab7eaa1740ac2f8dfd969253382866 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 16 Jul 2020 20:42:05 +0200 Subject: [PATCH] Some improvement to development Dockerfile Don't use a virtualenv insise the Dockerfile, not actually needed --- .github/workflows/linter.yml | 2 +- README.rst | 6 +- extras/docker/apache/Dockerfile | 9 ++- extras/docker/base/Dockerfile | 1 + extras/docker/base/README.md | 2 +- extras/docker/development-fedora/Dockerfile | 66 --------------- extras/docker/development-fedora/README.md | 64 --------------- extras/docker/development-venv/Dockerfile | 90 +++++++++++++++++++++ extras/docker/development/Dockerfile | 37 ++++----- extras/docker/development/README.md | 20 ++--- 10 files changed, 126 insertions(+), 171 deletions(-) delete mode 100644 extras/docker/development-fedora/Dockerfile delete mode 100644 extras/docker/development-fedora/README.md create mode 100644 extras/docker/development-venv/Dockerfile diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ff3434115..f51e54b24 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -48,7 +48,7 @@ jobs: - name: Lint Code Base uses: docker://github/super-linter:v2.2.2 env: - # Note: pythong was removed from validation because there seemed to + # Note: python was removed from validation because there seemed to # be a problem with custom pylintrc files. If this bug is solved, # python linting can be activated again (obviously!) VALIDATE_PYTHON: false diff --git a/README.rst b/README.rst index d0978af63..7ba473fe6 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -docker run -ti -v /path/to/this/checkout:/home/wger/src --name wger.devel --publish 8000:8000 wger/develThank you for downloading wger Workout Manager. wger (ˈvɛɡɐ) is a free, open source web +Thank you for downloading wger Workout Manager. wger (ˈvɛɡɐ) is a free, open source web application that manages your exercises and personal workouts, weight and diet plans. It can also be used as a simple gym management utility, providing different administrative roles (trainer, manager, etc.). It offers a REST API as well, for @@ -25,8 +25,8 @@ parameters. Docker ------ -Useful to just try it out. Check the documentatio on how to use docker for -development:: +Useful to just try it out. Check the documentation on how to use the wger/devel +docker image for development:: docker run -ti --name wger.apache --publish 8000:80 wger/apache diff --git a/extras/docker/apache/Dockerfile b/extras/docker/apache/Dockerfile index 71b451238..af0abf790 100644 --- a/extras/docker/apache/Dockerfile +++ b/extras/docker/apache/Dockerfile @@ -25,19 +25,19 @@ RUN apt-get update \ build-essential \ python3-dev \ python3-pip \ + python3-wheel \ git \ && rm -rf /var/lib/apt/lists/* # Set up the application COPY . . -RUN pip3 install wheel \ - && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt +RUN pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt ######## # Final ######## -FROM wger/base:1.9 +FROM wger/base:2.0-dev LABEL maintainer="Roland Geider " ARG DOCKER_DIR=./extras/docker/apache @@ -77,14 +77,15 @@ RUN chmod 0644 /etc/cron.d/wger \ && chmod +x /home/wger/venvwrapper /home/wger/entrypoint.sh \ && touch /var/log/cron.log -COPY --chown=wger:www-data . /home/wger/src COPY --from=builder /usr/src/app/wheels /wheels +#COPY --chown=wger:www-data . /home/wger/src # Set up the application RUN ln -s /home/wger/static/CACHE /var/www USER wger WORKDIR /home/wger/src +RUN git clone https://github.com/wger-project/wger.git RUN python3 -m venv /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ diff --git a/extras/docker/base/Dockerfile b/extras/docker/base/Dockerfile index 921a513f7..14671e7d9 100644 --- a/extras/docker/base/Dockerfile +++ b/extras/docker/base/Dockerfile @@ -21,6 +21,7 @@ RUN apt-get update \ nodejs \ npm \ python3-venv \ + python3-pip \ vim \ tmux \ sqlite3 \ diff --git a/extras/docker/base/README.md b/extras/docker/base/README.md index 9693f06a7..cf491d330 100644 --- a/extras/docker/base/README.md +++ b/extras/docker/base/README.md @@ -3,7 +3,7 @@ Development image for wger - Base image This is the base image for some of the other wger images and offers no functionality, it's only use is to provide some common dependencies. -If you want to develop, try either ``wger/devel`` oder ``wger/devel-fedora``. +If you want to develop, try ``wger/devel``. Contact diff --git a/extras/docker/development-fedora/Dockerfile b/extras/docker/development-fedora/Dockerfile deleted file mode 100644 index 719403355..000000000 --- a/extras/docker/development-fedora/Dockerfile +++ /dev/null @@ -1,66 +0,0 @@ -# -# Docker image for wger development on a fedora base image -# -# Please consult the documentation for usage -# docker build -t wger/devel-fedora . -# docker run -ti --name wger.devel-fedora --publish 8000:8000 wger/devel-fedora -# (in docker) source ~/venv/bin/activate -# (in docker) python manage.py runserver 0.0.0.0:8000 -# -# -FROM fedora:25 -LABEL maintainer="Roland Geider " - -# Install dependencies -RUN dnf update;\ - dnf install -y python3-devel python-virtualenv \ - nodejs npm libjpeg-turbo-devel zlib-devel git \ - tmux redhat-rpm-config gcc python-imaging - -# Set locale to UTF8, otherwise problems with the encoding can occur, e.g. -# when using the invoke/wger commands and bower -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - -# Add wger user -RUN adduser wger -RUN echo "wger ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/wger -EXPOSE 8000 - - -# Set up the application -USER wger -RUN git clone https://github.com/wger-project/wger.git /home/wger/src - -WORKDIR /home/wger/src -RUN virtualenv --python python3 /home/wger/venv -RUN . /home/wger/venv/bin/activate \ - && pip install --upgrade pip \ - && pip install -r requirements_devel.txt \ - && python setup.py develop \ - && wger create_settings \ - --settings-path /home/wger/src/settings.py \ - --database-path /home/wger/db/database.sqlite \ - && wger bootstrap \ - --settings-path /home/wger/src/settings.py \ - --no-start-server - -# Install node modules for JS linting and download the exercise images -# -# Note: it seems there are problems with node and docker, so it's necessary -# to delete the node_modules folder and install everything again -# -> https://github.com/npm/npm/issues/9863 -# -> https://github.com/npm/npm/issues/13306 -RUN cd wger \ - && rm -r node_modules \ - && npm install bower \ - && npm install \ - && cd .. \ - && mkdir ~/media \ - && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \ - && . /home/wger/venv/bin/activate \ - && python manage.py download-exercise-images - - -CMD ["/bin/bash"] diff --git a/extras/docker/development-fedora/README.md b/extras/docker/development-fedora/README.md deleted file mode 100644 index 235967ebb..000000000 --- a/extras/docker/development-fedora/README.md +++ /dev/null @@ -1,64 +0,0 @@ -Development image for wger - Fedora based -========================================= -Thank you for downloading wger Workout Manager. wger (ˈvɛɡɐ) is a free, open -source web application that manages your exercises and personal workouts, weight -and diet plans. It can also be used as a simple gym management utility, providing -different administrative roles (trainer, manager, etc.). It offers a REST API -as well, for easy integration with other projects and tools. - -It is written with python/django and uses jQuery and some D3js for charts. - -Installation ------------- - -This docker image contains an instance of the application running with django's -development server using a sqlite database. It can be used to quickly setup a -development instance (vim and tmux are already installed): - -```docker run -ti --name wger.devel-fedora --publish 8000:8000 wger/devel-fedora``` - -Then, *within the docker image*, activate the virtualenv - -```source ~/venv/bin/activate``` - -and start the development server - -```python manage.py runserver 0.0.0.0:8000``` - -Then just open and log in as: **admin**, password **admin** - - -Contact -------- - -Feel free to contact us if you found this useful or if there was something that -didn't behave as you expected. We can't fix what we don't know about, so please -report liberally. If you're not sure if something is a bug or not, feel free to -file a bug anyway. - -* gitter: -* twitter: -* mailing list: / wger@googlegroups.com, no registration needed -* issue tracker: - -Sources -------- - -All the code and the content is freely available: - -* Main repository: - -Licence -------- - -The application is licenced under the Affero GNU General Public License 3 or -later (AGPL 3+). - -The initial exercise and ingredient data is licensed additionally under one of -the Creative Commons licenses, see the individual exercises for more details. - -The documentation is released under a CC-BY-SA either version 4 of the License, -or (at your option) any later version. - -Some images where taken from Wikipedia, see the SOURCES file in their respective -folders for more details. diff --git a/extras/docker/development-venv/Dockerfile b/extras/docker/development-venv/Dockerfile new file mode 100644 index 000000000..b91c10eb1 --- /dev/null +++ b/extras/docker/development-venv/Dockerfile @@ -0,0 +1,90 @@ +# +# Docker image for wger development: +# +# This image uses a virtual environment, which is not necessary in a docker +# image and is more or less intented to check that the installation instructions +# for a local develoment are up-to-date +# +# Please consult the documentation for usage +# +# Note: you MUST build this image from the projec's root! +# docker build -f extras/docker/development/Dockerfile --tag wger/devel . +# +# Run the container: +# docker run -ti --publish 8000:8000 --name wger.devel wger/devel +# (in docker) source ~/venv/bin/activate +# (in docker) python manage.py download-exercise-images (optional, may take some time) +# (in docker) python manage.py runserver 0.0.0.0:8000 +# +# Alternatively, you can bind the local checkout into the container: +# docker run -ti -v /path/to/this/checkout:/home/wger/src --name wger.devel --publish 8000:8000 wger/devel +# +# +# To stop the container: +# sudo docker container stop wger.devel +# +# To start developing again +# sudo docker container start --attach wger.devel +# + +########## +# Builder +########## +FROM ubuntu:20.04 as builder + +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + build-essential \ + python3-dev \ + python3-pip \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Set up the application +COPY . . +RUN pip3 install wheel \ + && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt + + +######## +# Final +######## +FROM wger/base:2.0-dev +LABEL maintainer="Roland Geider " +ARG DOCKER_DIR=./extras/docker/development +EXPOSE 8000 + +# Set locale to UTF8, otherwise problems with the encoding can occur, e.g. +# when using the invoke/wger commands and bower +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + + +# Set up the application +USER wger +COPY --chown=wger:wger . /home/wger/src +COPY --from=builder /usr/src/app/wheels /wheels +#RUN git clone https://github.com/wger-project/wger.git /home/wger/src + +WORKDIR /home/wger/src +RUN python3 -m venv /home/wger/venv +RUN . /home/wger/venv/bin/activate \ + && pip install --upgrade pip \ + && pip install --no-cache /wheels/* \ + && python setup.py develop \ + && npm install \ + && npm install bower \ + && wger create_settings \ + --settings-path /home/wger/src/settings.py \ + --database-path /home/wger/db/database.sqlite \ + && wger bootstrap \ + --settings-path /home/wger/src/settings.py \ + --no-start-server + +# Download the exercise images +RUN mkdir ~/media \ + && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py + +CMD ["/bin/bash"] diff --git a/extras/docker/development/Dockerfile b/extras/docker/development/Dockerfile index e13f2f11d..2b1e6e785 100644 --- a/extras/docker/development/Dockerfile +++ b/extras/docker/development/Dockerfile @@ -7,14 +7,10 @@ # docker build -f extras/docker/development/Dockerfile --tag wger/devel . # # Run the container: -# docker run -ti --publish 8000:8000 --name wger.devel wger/devel -# (in docker) source ~/venv/bin/activate -# (in docker) python manage.py download-exercise-images (optional, may take some time) -# (in docker) python manage.py runserver 0.0.0.0:8000 -# -# Alternatively, you can bind the local checkout into the container: # docker run -ti -v /path/to/this/checkout:/home/wger/src --name wger.devel --publish 8000:8000 wger/devel # +# (in docker) python3 manage.py download-exercise-images (optional, may take some time) +# (in docker) python3 manage.py runserver 0.0.0.0:8000 # # To stop the container: # sudo docker container stop wger.devel @@ -33,21 +29,21 @@ RUN apt-get update \ build-essential \ python3-dev \ python3-pip \ + python3-wheel \ git \ && rm -rf /var/lib/apt/lists/* -# Set up the application -COPY . . -RUN pip3 install wheel \ - && pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt +# Build the necessary python wheels +COPY requirements* ./ +RUN pip3 wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements_devel.txt + ######## # Final ######## -FROM wger/base:1.9 +FROM wger/base:2.0-dev LABEL maintainer="Roland Geider " -ARG DOCKER_DIR=./extras/docker/development EXPOSE 8000 # Set locale to UTF8, otherwise problems with the encoding can occur, e.g. @@ -59,20 +55,17 @@ ENV LC_ALL en_US.UTF-8 # Set up the application -USER wger COPY --chown=wger:wger . /home/wger/src COPY --from=builder /usr/src/app/wheels /wheels -#RUN git clone https://github.com/wger-project/wger.git /home/wger/src - WORKDIR /home/wger/src -RUN python3 -m venv /home/wger/venv -RUN . /home/wger/venv/bin/activate \ - && pip install --upgrade pip \ - && pip install --no-cache /wheels/* \ - && python setup.py develop \ +RUN pip3 install --no-cache /wheels/* \ + && python3 setup.py develop \ && npm install \ - && npm install bower \ - && wger create_settings \ + && npm install bower + +USER wger +WORKDIR /home/wger/src +RUN wger create_settings \ --settings-path /home/wger/src/settings.py \ --database-path /home/wger/db/database.sqlite \ && wger bootstrap \ diff --git a/extras/docker/development/README.md b/extras/docker/development/README.md index 2b5e4dfe5..bea96ca12 100644 --- a/extras/docker/development/README.md +++ b/extras/docker/development/README.md @@ -13,17 +13,21 @@ Installation This docker image contains an instance of the application running with django's development server using a sqlite database. It can be used to quickly setup a -development instance (vim and tmux are already installed): +development instance (vim and tmux are already installed):: -```docker run -ti --name wger.devel --publish 8000:8000 wger/devel``` + docker run -ti \ + -v /path/to/your/wger/checkout:/home/wger/src \ + --name wger.devel \ + --publish 8000:8000 wger/devel \ -Then, within the docker image, activate the virtualenv +On the first run you might want to download the exercise images (might take +some time): -```source ~/venv/bin/activate``` +```python3 manage.py download-exercise-images``` -and start the development server +To start the development server -```python manage.py runserver 0.0.0.0:8000``` +```python3 manage.py runserver 0.0.0.0:8000``` Then just open and log in as: **admin**, password **admin** @@ -35,10 +39,6 @@ To start developing again: ```sudo docker container start --attach wger.devel``` -You can also keep the code outside and just bind it into the container: - -```docker run -ti -v /path/to/local/project/checkout:/home/wger/src --name wger.devel --publish 8000:8000 wger/devel``` - Building --------