This is an automated email from the ASF dual-hosted git repository.

wohali pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-docker.git

commit b2734247ac8df0c0f1d51f3ba5464db60fef8e13
Author: Adam Kocoloski <kocol...@apache.org>
AuthorDate: Mon Jan 15 20:41:08 2018 -0500

    Introduce developer-friendly Dockerfile
    
    This dev image configuration is modeled after the 2.1.1 Dockerfile with
    a few modifications useful for day-to-day development:
    
    * The Dockerfile builds from git rather than the official source
      releases. The build is configurable using the following build_args:
    
      clone_url (default: https://gitbox.apache.org/repos/asf/couchdb.git)
      checkout_branch (default: master)
      configure_options (default: <blank>)
    
      The configure_options are passed directly to ./configure and can be
      used to e.g. --disable-docs or --disable-fauxton:
    
      docker build --build-arg checkout_branch=my-cool-feature dev/
    
    * We take advantage of multi-stage builds [1] to create a series of
      layers that optimize build time without inflating the final image
      size. In normal development the layers that install runtime and
      build dependencies will be cached, and the build will start by
      updating and configuring the existing git clone.
    
    This work includes the changes proposed in #50 and #57.
---
 dev/Dockerfile           | 136 +++++++++++++++++++++++++++++++++++++++++++++++
 dev/docker-entrypoint.sh |  74 ++++++++++++++++++++++++++
 dev/local.ini            |  11 ++++
 dev/vm.args              |  28 ++++++++++
 4 files changed, 249 insertions(+)

diff --git a/dev/Dockerfile b/dev/Dockerfile
new file mode 100644
index 0000000..336ab80
--- /dev/null
+++ b/dev/Dockerfile
@@ -0,0 +1,136 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# Base layer containing dependencies needed at runtime. This layer will be
+# cached after the initial build.
+FROM debian:jessie AS runtime
+
+LABEL maintainer="CouchDB Developers <d...@couchdb.apache.org>"
+
+# Add CouchDB user account
+RUN groupadd -r couchdb && useradd -d /opt/couchdb -g couchdb couchdb
+
+RUN apt-get update -y && apt-get install -y --no-install-recommends \
+    ca-certificates \
+    libicu52 \
+    libmozjs185-1.0 \
+    openssl \
+  && rm -rf /var/lib/apt/lists/*
+
+# grab gosu for easy step-down from root and tini for signal handling
+# see https://github.com/apache/couchdb-docker/pull/28#discussion_r141112407
+ENV GOSU_VERSION 1.10
+ENV TINI_VERSION 0.16.1
+RUN set -ex; \
+       \
+       apt-get update; \
+       apt-get install -y --no-install-recommends wget; \
+       rm -rf /var/lib/apt/lists/*; \
+       \
+       dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
+       \
+# install gosu
+       wget -O /usr/local/bin/gosu 
"https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-$dpkgArch";;
 \
+       wget -O /usr/local/bin/gosu.asc 
"https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc";;
 \
+       export GNUPGHOME="$(mktemp -d)"; \
+       gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 
B42F6819007F00F88E364FD4036A9C25BF357DD4; \
+       gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
+       rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
+       chmod +x /usr/local/bin/gosu; \
+       gosu nobody true; \
+       \
+# install tini
+       wget -O /usr/local/bin/tini 
"https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$dpkgArch";;
 \
+       wget -O /usr/local/bin/tini.asc 
"https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$dpkgArch.asc";;
 \
+       export GNUPGHOME="$(mktemp -d)"; \
+       gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 
595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7; \
+       gpg --batch --verify /usr/local/bin/tini.asc /usr/local/bin/tini; \
+       rm -r "$GNUPGHOME" /usr/local/bin/tini.asc; \
+       chmod +x /usr/local/bin/tini; \
+       tini --version; \
+       \
+       apt-get purge -y --auto-remove wget
+
+# Dependencies only needed during build time. This layer will also be cached
+# unless for each clone_url.
+FROM runtime AS build_dependencies
+
+RUN apt-get update -y && apt-get install -y --no-install-recommends \
+    apt-transport-https \
+    gcc \
+    g++ \
+    curl \
+    erlang-nox \
+    erlang-reltool \
+    erlang-dev \
+    git \
+    libcurl4-openssl-dev \
+    libicu-dev \
+    libmozjs185-dev \
+    make \
+    python \
+    python-sphinx \
+    python-sphinx-rtd-theme \
+    texinfo \
+    texlive-base \
+    texlive-fonts-extra \
+    texlive-fonts-recommended \
+    texlive-latex-extra
+
+# Node is special
+RUN set -ex; \
+    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add 
-; \
+    echo 'deb https://deb.nodesource.com/node_6.x jessie main' > 
/etc/apt/sources.list.d/nodesource.list; \
+    echo 'deb-src https://deb.nodesource.com/node_6.x jessie main' >> 
/etc/apt/sources.list.d/nodesource.list; \
+    apt-get update -y && apt-get install -y nodejs; \
+    npm install -g grunt-cli
+
+
+# Clone CouchDB source code including all dependencies
+ARG clone_url=https://gitbox.apache.org/repos/asf/couchdb.git
+RUN git clone $clone_url /usr/src/couchdb
+WORKDIR /usr/src/couchdb
+RUN ./configure
+
+# This layer performs the actual build of a relocatable, self-contained
+# release of CouchDB. It pulls down the latest changes from the remote
+# origin (because the layer above will be cached) and switches to the
+# branch specified in the build_arg (defaults to master)
+FROM build_dependencies AS build
+
+ARG checkout_branch=master
+ARG configure_options
+
+WORKDIR /usr/src/couchdb/
+RUN git fetch origin \
+    && git checkout $checkout_branch \
+    && ./configure $configure_options \
+    && make release
+
+# This results in a single layer image (or at least skips the build stuff?)
+FROM runtime
+COPY --from=build /usr/src/couchdb/rel/couchdb /opt/
+
+# Add configuration
+COPY local.ini /opt/couchdb/etc/default.d/
+COPY vm.args /opt/couchdb/etc/
+COPY docker-entrypoint.sh /
+
+# Setup directories and permissions
+RUN chown -R couchdb:couchdb /opt/couchdb/etc/default.d/ 
/opt/couchdb/etc/vm.args
+
+WORKDIR /opt/couchdb
+EXPOSE 5984 4369 9100
+VOLUME ["/opt/couchdb/data"]
+
+ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
+CMD ["/opt/couchdb/bin/couchdb"]
diff --git a/dev/docker-entrypoint.sh b/dev/docker-entrypoint.sh
new file mode 100755
index 0000000..dda823d
--- /dev/null
+++ b/dev/docker-entrypoint.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+set -e
+
+# first arg is `-something` or `+something`
+if [ "${1#-}" != "$1" ] || [ "${1#+}" != "$1" ]; then
+       set -- /opt/couchdb/bin/couchdb "$@"
+fi
+
+# first arg is the bare word `couchdb`
+if [ "$1" = 'couchdb' ]; then
+       shift
+       set -- /opt/couchdb/bin/couchdb "$@"
+fi
+
+if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
+       # we need to set the permissions here because docker mounts volumes as 
root
+       chown -R couchdb:couchdb /opt/couchdb
+
+       chmod -R 0770 /opt/couchdb/data
+
+       chmod 664 /opt/couchdb/etc/*.ini
+       chmod 664 /opt/couchdb/etc/local.d/*.ini
+       chmod 775 /opt/couchdb/etc/*.d
+
+       if [ ! -z "$NODENAME" ] && ! grep "couchdb@" /opt/couchdb/etc/vm.args; 
then
+               echo "-name couchdb@$NODENAME" >> /opt/couchdb/etc/vm.args
+       fi
+
+       if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
+               # Create admin
+               printf "[admins]\n%s = %s\n" "$COUCHDB_USER" 
"$COUCHDB_PASSWORD" > /opt/couchdb/etc/local.d/docker.ini
+               chown couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini
+       fi
+
+       if [ "$COUCHDB_SECRET" ]; then
+               # Set secret
+               printf "[couch_httpd_auth]\nsecret = %s\n" "$COUCHDB_SECRET" >> 
/opt/couchdb/etc/local.d/docker.ini
+               chown couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini
+       fi
+
+       # if we don't find an [admins] section followed by a non-comment, 
display a warning
+       if ! grep -Pzoqr '\[admins\]\n[^;]\w+' /opt/couchdb/etc/local.d/*.ini; 
then
+               # The - option suppresses leading tabs but *not* spaces. :)
+               cat >&2 <<-'EOWARN'
+                       ****************************************************
+                       WARNING: CouchDB is running in Admin Party mode.
+                                This will allow anyone with access to the
+                                CouchDB port to access your database. In
+                                Docker's default configuration, this is
+                                effectively any other container on the same
+                                system.
+                                Use "-e COUCHDB_USER=admin -e 
COUCHDB_PASSWORD=password"
+                                to set it in "docker run".
+                       ****************************************************
+               EOWARN
+       fi
+
+
+       exec gosu couchdb "$@"
+fi
+
+exec "$@"
diff --git a/dev/local.ini b/dev/local.ini
new file mode 100644
index 0000000..c1bac9e
--- /dev/null
+++ b/dev/local.ini
@@ -0,0 +1,11 @@
+; CouchDB Configuration Settings
+
+; Custom settings should be made in this file. They will override settings
+; in default.ini, but unlike changes made to default.ini, this file won't be
+; overwritten on server upgrade.
+
+[chttpd]
+bind_address = any
+
+[httpd]
+bind_address = any
diff --git a/dev/vm.args b/dev/vm.args
new file mode 100644
index 0000000..0425756
--- /dev/null
+++ b/dev/vm.args
@@ -0,0 +1,28 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# Ensure that the Erlang VM listens on a known port
+-kernel inet_dist_listen_min 9100
+-kernel inet_dist_listen_max 9100
+
+# Tell kernel and SASL not to log anything
+-kernel error_logger silent
+-sasl sasl_error_logger false
+
+# Use kernel poll functionality if supported by emulator
++K true
+
+# Start a pool of asynchronous IO threads
++A 16
+
+# Comment this line out to enable the interactive Erlang shell on startup
++Bd -noinput

-- 
To stop receiving notification emails like this one, please contact
woh...@apache.org.

Reply via email to