From f87ad48b7c19dfb2f19dfc0e4d3c0c57805235ee Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 12 Feb 2021 19:13:11 +0100 Subject: [PATCH] Create docker-compose devel environment --- examples/Dockerfile | 159 ++++++------------------------------ examples/README.md | 34 ++++++++ examples/docker-compose.yml | 17 ++++ examples/env.example | 2 +- examples/init_project.sh | 7 ++ examples/initial_project.sh | 19 ----- examples/requirements.txt | 53 ++++++++++++ 7 files changed, 139 insertions(+), 152 deletions(-) create mode 100644 examples/README.md create mode 100644 examples/docker-compose.yml create mode 100644 examples/init_project.sh delete mode 100644 examples/initial_project.sh create mode 100644 examples/requirements.txt diff --git a/examples/Dockerfile b/examples/Dockerfile index 71ce3e93..cabb9a50 100644 --- a/examples/Dockerfile +++ b/examples/Dockerfile @@ -1,136 +1,9 @@ -# -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# +FROM python:3.6 -FROM buildpack-deps:buster +RUN apt-get -y update +RUN pip3 install wheel -# ensure local python is preferred over distribution python -ENV PATH /usr/local/bin:$PATH - -# http://bugs.python.org/issue19846 -# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. -ENV LANG C.UTF-8 - -# extra dependencies (over what buildpack-deps already includes) -RUN apt-get update && apt-get install -y --no-install-recommends \ - libbluetooth-dev \ - tk-dev \ - && rm -rf /var/lib/apt/lists/* - -ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D -ENV PYTHON_VERSION 3.6.12 - -RUN set -ex \ - \ - && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ - && export GNUPGHOME="$(mktemp -d)" \ - && gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ - && gpg --batch --verify python.tar.xz.asc python.tar.xz \ - && { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \ - && rm -rf "$GNUPGHOME" python.tar.xz.asc \ - && mkdir -p /usr/src/python \ - && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ - && rm python.tar.xz \ - \ - && cd /usr/src/python \ - && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ - && ./configure \ - --build="$gnuArch" \ - --enable-loadable-sqlite-extensions \ - --enable-optimizations \ - --enable-option-checking=fatal \ - --enable-shared \ - --with-system-expat \ - --with-system-ffi \ - --without-ensurepip \ - && make -j "$(nproc)" \ -# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916 - PROFILE_TASK='-m test.regrtest --pgo \ - test_array \ - test_base64 \ - test_binascii \ - test_binhex \ - test_binop \ - test_bytes \ - test_c_locale_coercion \ - test_class \ - test_cmath \ - test_codecs \ - test_compile \ - test_complex \ - test_csv \ - test_decimal \ - test_dict \ - test_float \ - test_fstring \ - test_hashlib \ - test_io \ - test_iter \ - test_json \ - test_long \ - test_math \ - test_memoryview \ - test_pickle \ - test_re \ - test_set \ - test_slice \ - test_struct \ - test_threading \ - test_time \ - test_traceback \ - test_unicode \ - ' \ - && make install \ - && rm -rf /usr/src/python \ - \ - && find /usr/local -depth \ - \( \ - \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ - -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \ - -o \( -type f -a -name 'wininst-*.exe' \) \ - \) -exec rm -rf '{}' + \ - \ - && ldconfig \ - \ - && python3 --version - -# make some useful symlinks that are expected to exist -RUN cd /usr/local/bin \ - && ln -s idle3 idle \ - && ln -s pydoc3 pydoc \ - && ln -s python3 python \ - && ln -s python3-config python-config - -# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" -ENV PYTHON_PIP_VERSION 21.0 -# https://github.com/pypa/get-pip -ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/8cc88aca7d9775fce279e8b84ef163cf1d3e8a2e/get-pip.py -ENV PYTHON_GET_PIP_SHA256 ffb67da2e976f48dd29714fc64812d1ac419eb7d48079737166dd95640d1debd - -RUN set -ex; \ - \ - wget -O get-pip.py "$PYTHON_GET_PIP_URL"; \ - echo "$PYTHON_GET_PIP_SHA256 *get-pip.py" | sha256sum --check --strict -; \ - \ - python get-pip.py \ - --disable-pip-version-check \ - --no-cache-dir \ - "pip==$PYTHON_PIP_VERSION" \ - ; \ - pip --version; \ - \ - find /usr/local -depth \ - \( \ - \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ - -o \ - \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ - \) -exec rm -rf '{}' +; \ - rm -f get-pip.py - -RUN apt-get -y update +RUN apt-get -y install python3-dev RUN apt-get install -y bind9utils ca-certificates gettext libcrack2-dev libxml2-dev\ libxslt1-dev ssh-client wget xvfb zlib1g-dev git iceweasel dnsutils postgresql-contrib\ @@ -143,4 +16,26 @@ RUN useradd orchestra --shell /bin/bash && \ mkhomedir_helper orchestra && \ adduser orchestra sudo -CMD ["python3"] +# RUN echo 'EXPORT $PATH="$PATH:/home/orchestra/.local/bin/"' > /home/orchestra/.bashrc +# RUN git clone https://github.com/ribaguifi/django-orchestra.git +# RUN orchestra-admin startproject panel +# RUN python3 panel/manage.py migrate +# RUN python3 panel/manage.py runserver + +# install wkhtmltox +RUN apt-get install -y xfonts-75dpi +RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb -O /tmp/wkhtmltox.deb +RUN dpkg -i /tmp/wkhtmltox.deb + +RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz +RUN tar -xf /tmp/geckodriver.tar.gz -C /usr/local/bin/ + +# install orchestra requirements +RUN pip3 install --upgrade pip + +# TODO(@slamora): requirements.txt duplicates ../totaL_requirements.txt +# Docker compose security policy forbiddes access to parent folders +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +EXPOSE 8000 diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..0e3b3465 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,34 @@ +# orchestra environment based on docker-compose + +Docker compose environment to develop django-orchestra. + +**NOTE**: On web container, volume `/code` contains the source code of the host. + +1. Build (or rebuild if any change done) the containers: +``` +cd examples/ +docker-compose build +``` + +2. Start the containers: +``` +docker-compose up +``` + +3. Run a bash on `web` container: +``` +docker-compose run web bash +``` + +4. Run on the web docker container the first time: +``` +pip3 install -e /code +su - orchestra +bash /code/examples/init_project.sh +``` + +5. Run tests or do whatever you need: +``` +cd panel +python manage.py test --noinput orchestra.contrib.lists.tests.functional_tests.tests.AdminListTest.test_add +``` diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml new file mode 100644 index 00000000..a64bb11c --- /dev/null +++ b/examples/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' +services: + web: + build: . + ports: + - 8000:8000 + volumes: + - ..:/code + + postgres: + image: postgres + ports: + - 5432:5432 + environment: + POSTGRES_DB: orchestra + POSTGRES_USER: orchestra + POSTGRES_PASSWORD: orchestra diff --git a/examples/env.example b/examples/env.example index 4804bf6a..634da757 100644 --- a/examples/env.example +++ b/examples/env.example @@ -1,5 +1,5 @@ SECRET_KEY=zrhnooq6)sb+0+xb)(o0rvbf5)a(vc8ncv&1&kng@3i_pmx3oy DEBUG=True ALLOWED_HOSTS=.localhost,127.0.0.1 -DATABASE_URL=postgres://orchestra:orchestra@127.0.0.1:5432/orchestra +DATABASE_URL=postgres://orchestra:orchestra@postgres:5432/orchestra STATIC_ROOT=PATH_TO_STATIC_ROOT diff --git a/examples/init_project.sh b/examples/init_project.sh new file mode 100644 index 00000000..61df4a40 --- /dev/null +++ b/examples/init_project.sh @@ -0,0 +1,7 @@ +psql -U orchestra -h postgres < /code/examples/createdb.sql + +cd ~ +django-admin.py startproject panel --template="/code/orchestra/conf/ribaguifi_template" +cp /code/examples/env.example panel/.env + +# python3 panel/manage.py migrate diff --git a/examples/initial_project.sh b/examples/initial_project.sh deleted file mode 100644 index 2f15a60b..00000000 --- a/examples/initial_project.sh +++ /dev/null @@ -1,19 +0,0 @@ -wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb -sudo dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb -wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz -sudo tar zxf geckodriver-v0.24.0-linux64.tar.gz -C /usr/local/bin/ - -sudo /etc/init.d/postgresql start - -sudo su - postgres -c 'psql -U postgres < /home/orchestra/examples/createdb.sql' - -git clone https://github.com/ribaguifi/django-orchestra -cd django-orchestra -git checkout dev/github-actions -sudo pip3 install --upgrade pip -sudo pip3 install -r total_requirements.txt -sudo pip3 install -e . - -django-admin.py startproject panel --template="orchestra/conf/ribaguifi_template" -cp examples/env.example panel/.env -python3 panel/manage.py migrate diff --git a/examples/requirements.txt b/examples/requirements.txt new file mode 100644 index 00000000..f2413e17 --- /dev/null +++ b/examples/requirements.txt @@ -0,0 +1,53 @@ +Django==1.10.5 +django-fluent-dashboard==0.6.1 +django-admin-tools==0.8.0 +django-extensions==1.7.4 +django-celery==3.1.17 +djangorestframework==3.4.7 +django-celery-email +django-debug-toolbar +django-cors-headers +django-countries +django-filter==0.15.2 +django-flat-theme +django-fluent-dashboard +django-iban +django-localflavor +django-multiselectfield +django-nose==1.4.4 +django-reversion +django-transaction-signals +celery==3.1.23 +kombu==3.0.35 +billiard==3.3.0.23 +Markdown==2.4 +ecdsa==0.11 +Pygments==1.6 +jsonfield==0.9.22 +python_dateutil +requests +phonenumbers +amqp==1.4.9 +anyjson +pytz +cracklib +lxml==3.3.5 +selenium +xvfbwrapper +freezegun==1.1.0 +coverage +flake8 +sqlparse +pyinotify +PyMySQL +dj_database_url==0.5.0 +psycopg2 +python-decouple +https://github.com/glic3rinu/passlib/archive/master.zip +paramiko +mysqlclient +pycrypto==2.6.1 +pygobject +six +nose +-e git+https://github.com/ribaguifi/orchestra-orm.git#egg=orchestra-orm