├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml └── docker-entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | # Based off of https://github.com/docker-library/postgres/blob/master/9.4/Dockerfile 2 | FROM debian:wheezy 3 | MAINTAINER Heap Analytics https://heapanalytics.com 4 | 5 | # add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added 6 | RUN groupadd -r postgres && useradd -r -g postgres postgres 7 | 8 | # grab gosu for easy step-down from root 9 | RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 10 | RUN apt-get update \ 11 | && apt-get install -y curl \ 12 | && rm -rf /var/lib/apt/lists/* \ 13 | && curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \ 14 | && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \ 15 | && gpg --verify /usr/local/bin/gosu.asc \ 16 | && rm /usr/local/bin/gosu.asc \ 17 | && chmod +x /usr/local/bin/gosu 18 | 19 | # make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default 20 | RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ 21 | && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 22 | ENV LANG en_US.utf8 23 | 24 | RUN mkdir /docker-entrypoint-initdb.d 25 | 26 | # Install CitusDB 4.1 27 | RUN curl -o /tmp/citus.deb -SL https://packages.citusdata.com/readline-6.0/citusdb-4.0.1-1.amd64.deb && \ 28 | curl -o /tmp/citus-contrib.deb -SL https://packages.citusdata.com/contrib/citusdb-contrib-4.0.1-1.amd64.deb && \ 29 | dpkg --install /tmp/citus.deb && \ 30 | dpkg --install /tmp/citus-contrib.deb && \ 31 | rm /tmp/citus*.deb 32 | 33 | ENV PG_MAJOR 9.4 34 | ENV CITUS_MAJOR 4.0 35 | 36 | ENV PGUSER postgres 37 | ENV PATH /opt/citusdb/$CITUS_MAJOR/bin:$PATH 38 | ENV PGDATA /data 39 | VOLUME /data 40 | VOLUME /etc/citus 41 | 42 | COPY docker-entrypoint.sh / 43 | 44 | ENTRYPOINT ["/docker-entrypoint.sh"] 45 | 46 | EXPOSE 5432 47 | CMD ["postgres"] 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Heap 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # citus-docker 2 | 3 | Dockerfile for [CitusDB](https://www.citusdata.com), sharded scalable postgresql database. 4 | 5 | ## How to use this image 6 | 7 | The image is based off of the [official postgres image](https://registry.hub.docker.com/_/postgres/) and supports the same options. When used with the provided `docker-compose` configuration, a [`workerlist-gen` container](https://hub.docker.com/r/citusdata/workerlist-gen/) is responsible for updating the worker list file and signalling the master node to reload changes. 8 | 9 | ### Testing the image 10 | 11 | The image defined in this repo can be tested using [docker compose](https://docs.docker.com/compose/). 12 | 13 | To launch a minimal Citus cluster (one master and one worker): `docker-compose -p citus up`. The `-p` flag specifies a custom project name (defaults to current working directory's name, which is often unsightly). 14 | 15 | To bring the worker count up to three: `docker-compose -p citus scale worker=3` 16 | 17 | For an example for setting up a distributed table and on how to run queries on it, 18 | see [Querying Raw Data — CitusDB Documentation](https://www.citusdata.com/documentation/citusdb-documentation/examples/time_querying_raw_data.html). 19 | 20 | These commands should be run from inside your Docker instance: 21 | 22 | ```bash 23 | docker exec -it citus_master bash 24 | apt-get update; apt-get install -y wget 25 | wget http://examples.citusdata.com/github_archive/github_events-2015-01-01-{0..5}.csv.gz 26 | gzip -d github_events-2015-01-01-*.gz 27 | psql 28 | 29 | # See the CitusDB guide (linked above) for remaining steps 30 | ``` 31 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | master: 5 | container_name: 'citus_master' 6 | build: . 7 | ports: ['5432:5432'] 8 | labels: ['com.citusdata.role=Master'] 9 | worker: 10 | build: . 11 | labels: ['com.citusdata.role=Worker'] 12 | config: 13 | container_name: 'citus_config' 14 | image: 'citusdata/workerlist-gen:0.9.0' 15 | volumes: ['/var/run/docker.sock:/tmp/docker.sock'] 16 | volumes_from: ['master'] 17 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # constants 5 | workerlist=pg_worker_list.conf 6 | citusconfdir=/etc/citus 7 | externalworkerlist="$citusconfdir/$workerlist" 8 | 9 | if [ "$1" = 'postgres' ]; then 10 | chown -R postgres "$PGDATA" 11 | 12 | if [ -z "$(ls -A "$PGDATA")" ]; then 13 | gosu postgres initdb 14 | touch "$externalworkerlist" 15 | chown postgres:postgres "$externalworkerlist" 16 | gosu postgres ln -sf "$externalworkerlist" "$PGDATA/$workerlist" 17 | 18 | sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf 19 | 20 | # check password first so we can ouptut the warning before postgres 21 | # messes it up 22 | if [ "$POSTGRES_PASSWORD" ]; then 23 | pass="PASSWORD '$POSTGRES_PASSWORD'" 24 | authMethod=md5 25 | else 26 | # The - option suppresses leading tabs but *not* spaces. :) 27 | cat >&2 <<-'EOWARN' 28 | **************************************************** 29 | WARNING: No password has been set for the database. 30 | This will allow anyone with access to the 31 | Postgres port to access your database. In 32 | Docker's default configuration, this is 33 | effectively any other container on the same 34 | system. 35 | 36 | Use "-e POSTGRES_PASSWORD=password" to set 37 | it in "docker run". 38 | **************************************************** 39 | EOWARN 40 | 41 | pass= 42 | authMethod=trust 43 | fi 44 | 45 | : ${POSTGRES_USER:=postgres} 46 | : ${POSTGRES_DB:=$POSTGRES_USER} 47 | 48 | if [ "$POSTGRES_DB" != 'postgres' ]; then 49 | gosu postgres postgres --single -jE <<-EOSQL 50 | CREATE DATABASE "$POSTGRES_DB" ; 51 | EOSQL 52 | echo 53 | fi 54 | 55 | if [ "$POSTGRES_USER" = 'postgres' ]; then 56 | op='ALTER' 57 | else 58 | op='CREATE' 59 | fi 60 | 61 | gosu postgres postgres --single -jE <<-EOSQL 62 | $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; 63 | EOSQL 64 | echo 65 | 66 | { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf 67 | 68 | if [ -d /docker-entrypoint-initdb.d ]; then 69 | for f in /docker-entrypoint-initdb.d/*.sh; do 70 | [ -f "$f" ] && . "$f" 71 | done 72 | fi 73 | fi 74 | 75 | exec gosu postgres "$@" 76 | fi 77 | 78 | exec "$@" 79 | --------------------------------------------------------------------------------