diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..7ae9d5cf28 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.appveyor +.circleci +.dockerignore +.github +.travis +contrib +docs +examples +integration_tests +utils diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..d541046e0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM ubuntu:16.04 +# This Dockerfile should follow the Travis configuration process +# available here: https://github.com/opendatacube/datacube-core/blob/develop/.travis.yml + +# First add the NextGIS repo +RUN apt-get update && apt-get install -y --no-install-recommends \ + python-software-properties \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +RUN add-apt-repository ppa:nextgis/ppa + +# And now install apt dependencies, including a few of the heavy Python projects +RUN apt-get update && apt-get install -y --no-install-recommends \ + gdal-bin libgdal-dev libgdal20 libudunits2-0 \ + python3 python3-gdal python3-setuptools python3-dev python3-numpy python3-netcdf4 \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Install psychopg2 as a special case, to quiet the warning message +RUN pip3 install --no-cache --no-binary :all: psycopg2 + +# Get the code, and put it in /code +ENV APPDIR=/code +RUN mkdir -p $APPDIR +COPY . $APPDIR +WORKDIR $APPDIR + +# Set the locale, this is required for some of the Python packages +ENV LC_ALL C.UTF-8 + +# Install dependencies +RUN pip3 install '.[test,analytics,celery,s3]' --upgrade +RUN pip3 install ./tests/drivers/fail_drivers --no-deps --upgrade + +# Install ODC +RUN python3 setup.py develop + +# Set up an entrypoint that drops environment variables into the config file +RUN cp /code/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD ["datacube","--help"] diff --git a/README.rst b/README.rst index 3343f71a82..1bb7b7d2f3 100644 --- a/README.rst +++ b/README.rst @@ -61,14 +61,70 @@ Developer setup 5. **(or)** Run all tests, including integration tests. -``./check-code.sh integration_tests`` + ``./check-code.sh integration_tests`` + + - Assumes a password-less Postgres database running on localhost called -- Assumes a password-less Postgres database running on localhost called ``agdcintegration`` - Otherwise copy ``integration_tests/agdcintegration.conf`` to ``~/.datacube_integration.conf`` and edit to customise. +Docker +====== + +Docker for OpenDataCube is in the early stages of development, and more documentation and examples of how +to use it will be forthcoming soon. For now, you can build and run this Docker image from +this repository as documented below. + +Example Usage +~~~~~~~~~~~~~ +There are a number of environment variables in use that can be used to configure the OpenDataCube. +Some of these are built into the application itself, and others are specific to Docker, and will +be used to create a configuration file when the container is launched. + +You can build the image with a command like this: + +``docker build --tag opendatacube:local .`` + +And it can then be run with this command: + +``docker run --rm opendatacube:local`` + +If you don't need to build (and you shouldn't) then you can run it from a pre-built image with: + +``docker run --rm opendatacube/datacube-core`` + +An example of starting a container with environment variables is as follows: + +.. code-block:: bash + + docker run \ + --rm \ + -e DATACUBE_CONFIG_PATH=/opt/custom-config.conf \ + -e DB_DATABASE=mycube \ + -e DB_HOSTNAME=localhost \ + -e DB_USERNAME=postgres \ + -e DB_PASSWORD=secretpassword \ + -e DB_PORT=5432 \ + opendatacube/datacube-core + + +This wont actually do anything, in order to make it work, you need an environment with Postgres, at least, and some scripts to index and possible ingest data. + +Environment Variables +~~~~~~~~~~~~~~~~~~~~~ +Most of the below environment variables should be self explanatory, and none are required (although +it is recommended that you set them). + +- ``DATACUBE_CONFIG_PATH`` - the path for the config file for writing (also used by ODC for reading) +- ``DB_DATABASE`` - the name of the postgres database +- ``DB_HOSTNAME`` - the hostname of the postgres database +- ``DB_USERNAME`` - the username of the postgres database +- ``DB_PASSWORD`` - the password to used for the postgres database +- ``DB_PORT`` - the port that the postgres database is exposed on + + .. |Build Status| image:: https://travis-ci.org/opendatacube/datacube-core.svg?branch=develop :target: https://travis-ci.org/opendatacube/datacube-core .. |Coverage Status| image:: https://coveralls.io/repos/opendatacube/datacube-core/badge.svg?branch=develop&service=github diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000000..84d4876da7 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +set -e + +# usage: file_env VAR [DEFAULT] +# ie: file_env 'XYZ_DB_PASSWORD' 'example' +# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of +# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) +# Copied from: https://github.com/docker-library/postgres/blob/master/10/docker-entrypoint.sh +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +# First set up the CONF_FILE environment variable +file_env 'DATACUBE_CONFIG_PATH' +if [ "$DATACUBE_CONFIG_PATH" ]; then + export CONF_FILE="$DATACUBE_CONFIG_PATH" +else + export CONF_FILE="$HOME/.datacube.conf" +fi + +# Build Config file +echo "[datacube]" > $CONF_FILE + +file_env 'DB_DATABASE' +if [ "$DB_DATABASE" ]; then + echo "db_database: $DB_DATABASE" >> $CONF_FILE +else + echo >&2 + echo >&2 'Warning: missing DB_DATABASE environment variable' + echo >&2 '*** Using "datacube" as fallback. ***' + echo >&2 + echo "db_database: datacube" >> $CONF_FILE +fi + +file_env 'DB_HOSTNAME' +if [ "$DB_HOSTNAME" ]; then + echo "db_hostname: $DB_HOSTNAME" >> $CONF_FILE +fi + +file_env 'DB_USERNAME' +if [ "$DB_USERNAME" ]; then + echo "db_username: $DB_USERNAME" >> $CONF_FILE +fi + +file_env 'DB_PASSWORD' +if [ "$DB_PASSWORD" ]; then + echo "db_password: $DB_PASSWORD" >> $CONF_FILE +fi + +file_env 'DB_PORT' +if [ "$DB_PORT" ]; then + echo "db_port: $DB_PORT" >> $CONF_FILE +fi + +exec "$@" diff --git a/docs/about/whats_new.rst b/docs/about/whats_new.rst index 2d989da8af..6ffb6c36e0 100644 --- a/docs/about/whats_new.rst +++ b/docs/about/whats_new.rst @@ -47,6 +47,8 @@ Next release - Added documentation about :ref:`bit-masking`. + - Added Dockerfile to enable with automated builds for a reference Docker image. + .. _#298: https://github.com/opendatacube/datacube-core/pull/298 .. _config docs: https://datacube-core.readthedocs.io/en/latest/ops/config.html#runtime-config-doc