Commit 16aa72da authored by Roberto Rosario's avatar Roberto Rosario
Browse files

Add support for install Ubuntu and Python packages during container creation.

parent 4efe54e1
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -42,12 +42,16 @@ apt-get install -y --no-install-recommends \

apt-get clean autoclean && \

apt-get autoremove -y && \
apt-get autoremove --purge -y && \

rm -rf /var/lib/apt/lists/* && \

rm -f /var/cache/apt/archives/*.deb

# Install apt-get-install
ADD https://raw.githubusercontent.com/guilhem/apt-get-install/master/apt-get-install /usr/bin/
RUN chmod +x /usr/bin/apt-get-install

ENV MAYAN_INSTALL_DIR=/usr/local/lib/python2.7/dist-packages/mayan
ENV MAYAN_MEDIA=/usr/local/lib/python2.7/dist-packages/mayan/media

@@ -97,6 +101,7 @@ RUN chown -R www-data:www-data $MAYAN_INSTALL_DIR
RUN touch $MAYAN_MEDIA/__init__.py
RUN mkdir $MAYAN_MEDIA/settings
RUN touch $MAYAN_MEDIA/settings/__init__.py
RUN mkdir $MAYAN_MEDIA/pip_installs

# Setup Mayan EDMS settings file overrides
COPY etc/mayan/media/settings/base.py $MAYAN_INSTALL_DIR/media/settings/base.py
+50 −0
Original line number Diff line number Diff line
@@ -383,6 +383,56 @@ Replace the IP address `172.18.0.1` with the IP address of the Docker host used

## Customizing the image

### Simple method

If you just need to add a few Ubuntu or Python packages to your installation,
you can use the following environment variables::

**`MAYAN_APT_INSTALLS`**

Specifies a list of Ubuntu .deb packages to be installed via APT when the
container is first created. The installed packages are not lost when the image
is stopped. Example: To install the Tesseract OCR language packs for German
and Spanish add the following in your `docker start` command line:

```console
-e MAYAN_APT_INSTALLS="tesseract-ocr-deu tesseract-ocr-spa"
```

**`MAYAN_PIP_INSTALLS`**

Specifies a list of Python packages to be installed via `pip`. Packages will be
downloaded from the Python Package Index (https://pypi.python.org) by default.
If you need to use local packages, copy them to the folder `/pip_installs` in
the `mayan_data` volume and specify their full path in the environment variable.
Example: To install Werkzeug fromt the web and your local Python package, copy
you local Python package before running a new container with:

```console
$ sudo cp my_package.whl /var/lib/docker/volumes/mayan_data/_data/pip_installs/
```

If the folder `pip_installs` doesn't exists because you are upgrading from a
previous version you can create it with:

```console
$ sudo mkdir /var/lib/docker/volumes/mayan_data/_data/pip_installs/
```

Then specify `Werkzeug` and you local package's path in the environment variable.
The path to the local package will be `/var/lib/mayan/pip_installs` because is
where the `mayan_data` volume is mounted:


```console
-e MAYAN_PIP_INSTALLS="Werkzeug /var/lib/mayan/pip_installs/my_package.whl"
```

### Advanced method

Use this method when you need to change more things in the default image than
just Ubuntu or Python packages.

As an example, let's create a new image that adds German OCR support.

Create a file name `Dockerfile`. This will create a new local image of Mayan EDMS that builds on top of the official image. This is how Docker works, by layering images. Create a new file called `Dockerfile.local` with the following content:
+15 −0
Original line number Diff line number Diff line
@@ -20,7 +20,22 @@ start() {
    exec /usr/bin/supervisord -nc /etc/supervisor/supervisord.conf
}

apt_installs() {
    if [ "${MAYAN_APT_INSTALLS}" ]; then
        apt-get-install $MAYAN_APT_INSTALLS
    fi
}

pip_installs() {
    if [ "${MAYAN_PIP_INSTALLS}" ]; then
        pip install $MAYAN_PIP_INSTALLS
    fi
}

if [ "$1" = 'mayan' ]; then
    apt_installs || true
    pip_installs || true

    # Check if this is a new install, otherwise try to upgrade the existing
    # installation on subsequent starts
    if [ ! -f $INSTALL_FLAG ]; then