Skip to content

Commit 1a5b0d1

Browse files
committed
initial
1 parent a51c268 commit 1a5b0d1

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM debian:jessie
2+
3+
# Update distro
4+
RUN apt-get update -y && apt-get -y upgrade && apt-get -y dist-upgrade
5+
6+
# Install CouchDB from source
7+
RUN apt-get --no-install-recommends -y install \
8+
build-essential pkg-config erlang \
9+
libicu-dev libmozjs185-dev libcurl4-openssl-dev \
10+
wget curl ca-certificates \
11+
&& cd /usr/src \
12+
&& wget http://www-eu.apache.org/dist/couchdb/source/2.0.0/apache-couchdb-2.0.0.tar.gz \
13+
&& tar xfz apache-couchdb-2.0.0.tar.gz \
14+
&& cd apache-couchdb-2.0.0 \
15+
&& ./configure \
16+
&& make release \
17+
&& adduser --system \
18+
--shell /bin/bash \
19+
--group --gecos \
20+
"CouchDB Administrator" couchdb \
21+
&& cp -R ./rel/couchdb /home/couchdb \
22+
&& chown -R couchdb:couchdb /home/couchdb/couchdb \
23+
&& find /home/couchdb/couchdb -type d -exec chmod 0770 {} \; \
24+
&& chmod 0644 /home/couchdb/couchdb/etc/*
25+
26+
# grab gosu for easy step-down from root and tini for signal handling
27+
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
28+
&& curl -o /usr/local/bin/gosu -fSL "https://github.com/tianon/gosu/releases/download/1.7/gosu-$(dpkg --print-architecture)" \
29+
&& curl -o /usr/local/bin/gosu.asc -fSL "https://github.com/tianon/gosu/releases/download/1.7/gosu-$(dpkg --print-architecture).asc" \
30+
&& gpg --verify /usr/local/bin/gosu.asc \
31+
&& rm /usr/local/bin/gosu.asc \
32+
&& chmod +x /usr/local/bin/gosu \
33+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 \
34+
&& curl -o /usr/local/bin/tini -fSL "https://github.com/krallin/tini/releases/download/v0.14.0/tini" \
35+
&& curl -o /usr/local/bin/tini.asc -fSL "https://github.com/krallin/tini/releases/download/v0.14.0/tini.asc" \
36+
&& gpg --verify /usr/local/bin/tini.asc \
37+
&& rm /usr/local/bin/tini.asc \
38+
&& chmod +x /usr/local/bin/tini
39+
40+
# Add config files
41+
COPY local.ini /home/couchdb/couchdb/etc/local.d/
42+
COPY vm.args /home/couchdb/couchdb/etc/
43+
44+
COPY ./docker-entrypoint.sh /
45+
46+
# Setup directories and permissions
47+
RUN mkdir /home/couchdb/couchdb/data /home/couchdb/couchdb/etc/default.d \
48+
&& chown -R couchdb:couchdb /home/couchdb/couchdb/
49+
50+
WORKDIR /home/couchdb/couchdb
51+
52+
EXPOSE 5984 4369 9100-9200
53+
54+
VOLUME ["/home/couchdb/couchdb/data"]
55+
56+
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
57+
CMD ["/home/couchdb/couchdb/bin/couchdb"]

docker-entrypoint.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ "$1" = '/home/couchdb/couchdb/bin/couchdb' ]; then
6+
7+
# Use sname so that we can specify a short name, like those used by docker, instead of a host
8+
if [ ! -z "$NODENAME" ] && ! grep "couchdb@" /home/couchdb/couchdb/etc/vm.args; then
9+
# Cookie is needed so that the nodes can connect to each other using Erlang clustering
10+
if [ -z "$COUCHDB_COOKIE" ]; then
11+
echo "-sname couchdb@$NODENAME" >> /home/couchdb/couchdb/etc/vm.args
12+
else
13+
echo "-sname couchdb@$NODENAME -setcookie '$COUCHDB_COOKIE'" >> /home/couchdb/couchdb/etc/vm.args
14+
fi
15+
fi
16+
17+
if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ] && [ -z "$COUCHDB_SYNC_ADMINS_NODE" ]; then
18+
# Create admin
19+
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" > /home/couchdb/couchdb/etc/local.d/docker.ini
20+
chown couchdb:couchdb /home/couchdb/couchdb/etc/local.d/docker.ini
21+
fi
22+
23+
if [ "$COUCHDB_USER" ] && [ "$COUCHDB_HASHED_PASSWORD" ]; then
24+
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_HASHED_PASSWORD" > /home/couchdb/couchdb/etc/local.d/docker.ini
25+
chown couchdb:couchdb /home/couchdb/couchdb/etc/local.d/docker.ini
26+
fi
27+
28+
if [ "$COUCHDB_SECRET" ]; then
29+
# Set secret
30+
printf "[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" > /home/couchdb/couchdb/etc/local.d/secret.ini
31+
chown couchdb:couchdb /home/couchdb/couchdb/etc/local.d/secret.ini
32+
fi
33+
34+
exec gosu couchdb "$@"
35+
fi
36+
37+
exec "$@"

local.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; CouchDB Configuration Settings
2+
3+
; Custom settings should be made in this file. They will override settings
4+
; in default.ini, but unlike changes made to default.ini, this file won't be
5+
; overwritten on server upgrade.
6+
7+
[chttpd]
8+
bind_address = any
9+
10+
[httpd]
11+
bind_address = any

vm.args

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
2+
# use this file except in compliance with the License. You may obtain a copy of
3+
# the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations under
11+
# the License.
12+
13+
# Ensure that the Erlang VM listens on a known port
14+
-kernel inet_dist_listen_min 9100
15+
-kernel inet_dist_listen_max 9200
16+
17+
# Tell kernel and SASL not to log anything
18+
-kernel error_logger silent
19+
-sasl sasl_error_logger false
20+
21+
# Use kernel poll functionality if supported by emulator
22+
+K true
23+
24+
# Start a pool of asynchronous IO threads
25+
+A 16
26+
27+
# Comment this line out to enable the interactive Erlang shell on startup
28+
+Bd -noinput

0 commit comments

Comments
 (0)