Commit edd9eff1 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'issue/1' into 'master'

Issue #1: Create docker image with postgres extensions <postgis;dblink;pgcrypto>

See merge request !1
parents 19a88a27 7ad6c8e3
Pipeline #21616 passed with stages
in 1 minute and 2 seconds
variables:
image_version: '11.33.3'
DOCKER_URL: 'dockerregistry.c3sl.ufpr.br:5000/c3sl/monetdb-ci-service'
image_version: '10'
DOCKER_URL: 'dockerregistry.c3sl.ufpr.br:5000/c3sl/postgres-ext-ci-service'
stages:
- build
......
b0ac053952d9f0562909c26492eb31081262f0d1 11.21.11
cb4c89143a3e52064aa5a89f10fc05c400680afa 11.21.5
2b5d62d0a05379520f490406365aa4d1b2ad15bc 11.21.17
85c20775239951b06ae80ec1b448810502a778e0 11.21.19
############################################################
# Dockerfile to build MonetDB and R images
# Based on CentOS 7
############################################################
FROM centos:7
MAINTAINER Panagiotis Koutsourakis <panagiotis.koutsourakis@monetdbsolutions.com>
FROM postgres:10
#######################################################
# Expose ports
#######################################################
EXPOSE 50000
ENV POSTGIS_MAJOR 2.5
ENV POSTGIS_VERSION 2.5.2+dfsg-1~exp1.pgdg90+1
#######################################################
# Setup supervisord
#######################################################
# Install supervisor
RUN yum install -y python-setuptools
RUN easy_install supervisor
# Create a log dir for the supervisor
RUN mkdir -p /var/log/supervisor
# Copy the config
COPY configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN apt-get update \
&& apt-cache showpkg postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
&& apt-get install -y --no-install-recommends \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR=$POSTGIS_VERSION \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts=$POSTGIS_VERSION \
postgis=$POSTGIS_VERSION \
&& rm -rf /var/lib/apt/lists/*
#############################################################
# Enables repos, update system, install packages and clean up
#############################################################
RUN yum -y install epel-release numpy
# Update & upgrade
RUN yum update -y && \
yum upgrade -y
#############################################################
# MonetDB installation
#############################################################
# Create users and groups
RUN groupadd -g 5000 monetdb && \
useradd -u 5000 -g 5000 monetdb
# Enable MonetDB repo
RUN yum install -y https://www.monetdb.org/downloads/epel/MonetDB-release-epel.noarch.rpm
# Update & upgrade
RUN yum update -y && \
yum upgrade -y
ARG MonetDBVersion=11.33.3
# Install MonetDB server
RUN yum install -y MonetDB-$MonetDBVersion \
MonetDB-stream-$MonetDBVersion \
MonetDB-client-$MonetDBVersion \
MonetDB-SQL-server5-$MonetDBVersion \
MonetDB-SQL-server5-hugeint-$MonetDBVersion \
MonetDB5-server-$MonetDBVersion \
MonetDB5-server-hugeint-$MonetDBVersion
# Install MonetDB extensions
RUN yum install -y MonetDB-geom-MonetDB5-$MonetDBVersion \
MonetDB-R-$MonetDBVersion \
MonetDB-python2-$MonetDBVersion
# Clean up
RUN yum -y clean all
#######################################################
# Setup MonetDB
#######################################################
# Add helper scripts
COPY scripts/set-monetdb-password.sh /home/monetdb/set-monetdb-password.sh
RUN chmod +x /home/monetdb/set-monetdb-password.sh
# Add a monetdb config file to avoid prompts for username/password
# We will need this one to authenticate when running init-db.sh, as well
COPY configs/.monetdb /home/monetdb/.monetdb
# Copy the database init scripts
COPY scripts/init-db.sh /home/monetdb/init-db.sh
RUN chmod +x /home/monetdb/init-db.sh
# As of the Jun2016 release, we have to set the property listenaddr to any host
# because now it only listens to the localhost by default
RUN echo "listenaddr=0.0.0.0" >> /var/monetdb5/dbfarm/.merovingian_properties
# Init the db in a script to allow more than one process to run in the container
# We need two: one for monetdbd and one for mserver
# The script will init the database with using the unprivileged user monetdb
RUN su -c 'sh /home/monetdb/init-db.sh' monetdb
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
# CUSTOM
ENV MONETDB_NAME dbmonet
ENV MONETDB_USER dbmonet
ENV MONETDB_PASSWORD dbmonet
WORKDIR /home/monetdb
COPY script.sh /etc/script/script.sh
CMD ["/bin/bash", "/etc/script/script.sh"]
RUN mkdir -p /docker-entrypoint-initdb.d
COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh
monetdb-r-docker
===========================
[![Docker Hub](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/monetdb/monetdb-r-docker/)
# postgres-ext-ci-service
Docker container for [MonetDB with R](https://www.monetdb.org/content/embedded-r-monetdb). Based on CentOS 7.
Container postgres com as extensões: <postgis;pgcrypto;dblink> instaladas.
# Supported tags and respective Dockerfile links
* [`Aug2018`, `11.31.7`, `latest` (Dockerfile)](https://github.com/MonetDB/monetdb-r-docker/blob/aug2018/Dockerfile)
* [`Mar2018`, `11.29.3`, (Dockerfile)](https://github.com/MonetDB/monetdb-r-docker/blob/mar2018/Dockerfile)
## Getting Started
# Launching a MonetDB container
Pull the image from the registry:
docker pull dockerregistry.c3sl.ufpr.br:5000/c3sl/postgres-ext-ci-service
```
docker pull monetdb/monetdb-r-docker
```
## Built With
## Quick start
```
docker run -d -P -p 50000:50000 --name monetdb-r monetdb/monetdb-r-docker
```
The `-d` option will send the docker process to the background. The `-P` option will publish all exposed ports.
After that, you should be able to access MonetDB on the default port `50000`, with the default username/password: `monetdb/monetdb`.
Or you can run `docker exec -it monetdb-r mclient db` to open an [`mclient`](https://www.monetdb.org/Documentation/mclient-man-page) shell in the container.
## Production run
Before letting other users access the database-in-container, you should set a new password for the admin user `monetdb`:
```
docker exec -d monetdb-r /root/set-monetdb-password.sh <password>
```
# Advanced
## Multiple database servers per container
The MonetDB daemon [monetdbd](https://www.monetdb.org/Documentation/monetdbd-man-page) allows for multiple MonetDB database server processes to run on the same system and listed on the same port. While it is not advised to run more than one database server in the same Docker container, you can do that by creating a new database with the [monetdb](https://www.monetdb.org/Documentation/monetdb-man-page) command-line control tool. In this container, the database server is controller by the MonetDB daemon (`monetdbd`), both of which are started by `supervisord`.
For more information on how to use MonetDB, check out the [tutorial](https://www.monetdb.org/Documentation/UserGuide/Tutorial).
## Build your own
You can use the image as a base image when building your own version.
After pulling the image from the registry, run the command bellow to build and tag your own version.
```
docker build --rm -t <yourname>/monetdb-r-docker .
```
# Details
## Base image
The MonetDB image is based on the CentOS 7. We migrated from Fedora (latest).
## Software
The image includes the latest stable version of the software available for CentOS at build time:
* MonetDB server with hugeint support
* R module for embedded R support
* Python2 module for embedded Python support (since Dec2016 only)
* GEOS module
* GSL module
* Mclient - The native MonetDB client
* MonetDB ODBC driver
The default database on the image has R and Python2 integration enabled.
## Ports
MonetDB runs on port `50000` by default, which is exposed on the image.
* [Postgres](https://www.postgresql.org/about/news/1786/) - Image base for the project
user=monetdb
password=monetdb
[supervisord]
nodaemon=true
[program:monetdbd]
command=monetdbd start /var/monetdb5/dbfarm
autorestart=false
user=monetdb
redirect_stderr=true
stdout_logfile=/var/log/supervisor/monetdbd.log
priority=1
exitcodes=0
startsecs=0
#!/bin/sh
set -e
# Perform all actions as $POSTGRES_USER
export PGUSER="$POSTGRES_USER"
# Create the 'template_postgis' template db
"${psql[@]}" <<- 'EOSQL'
CREATE DATABASE template_postgis;
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
EOSQL
# Load PostGIS into both template_database and $POSTGRES_DB
for DB in template_postgis "$POSTGRES_DB"; do
echo "Loading PostGIS extensions into $DB"
"${psql[@]}" --dbname="$DB" <<-'EOSQL'
CREATE EXTENSION IF NOT EXISTS dblink;
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
EOSQL
done
\ No newline at end of file
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf &
# the first argument will the database name
condition=true
while $condition ; do
# it will create a database called monetdb
monetdb create $MONETDB_NAME
# $? is the result 0 for sucess 1 for err
try=$?
if [ $try == "0" ]
then
# the test has succeed
condition=false
else
# the test has failed will try again in 5s
sleep 5s
fi
done
monetdb release $MONETDB_NAME
# .monetdb will be read when mclient is called without user and password
echo "user=monetdb" > .monetdb
echo "password=monetdb" >> .monetdb
mclient -d $MONETDB_NAME -s "create user \"$MONETDB_USER\" with password '$MONETDB_PASSWORD' name 'ci' schema \"sys\"";
echo "user=$MONETDB_USER" > .monetdb
echo "password=$MONETDB_PASSWORD" >> .monetdb
wait
\ No newline at end of file
#!/bin/bash
chown -R monetdb:monetdb /var/monetdb5
if [ ! -d "/var/monetdb5/dbfarm" ]; then
monetdbd create /var/monetdb5/dbfarm
else
echo "Existing dbfarm found in '/var/monetdb5/dbfarm'"
fi
monetdbd start /var/monetdb5/dbfarm
sleep 5
if [ ! -d "/var/monetdb5/dbfarm/db" ]; then
monetdb create db && \
monetdb set embedr=true db && \
monetdb set embedpy=true db && \
monetdb release db
else
echo "Existing database found in '/var/monetdb5/dbfarm/db'"
fi
for i in {30..0}; do
echo 'Testing MonetDB connection ' $i
mclient -d db -s 'SELECT 1' &> /dev/null
if [ $? -ne 0 ] ; then
echo 'Waiting for MonetDB to start...'
sleep 1
else
echo 'MonetDB is running'
break
fi
done
if [ $i -eq 0 ]; then
echo >&2 'MonetDB startup failed'
exit 1
fi
mkdir -p /var/log/monetdb
chown -R monetdb:monetdb /var/log/monetdb
echo "Initialization done"
#!/bin/bash
dbname="db"
username="monetdb"
if [ -n "$1" ]; then
password=$1
echo "Setting new password for database '$dbname' and user '$username'."
echo -e "user=monetdb\npassword=monetdb" > .monetdb
mclient $dbname -s "ALTER USER SET PASSWORD '$password' USING OLD PASSWORD 'monetdb'";
rm -f .monetdb
else
echo "No password provided, aborting."
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment