You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by kl...@apache.org on 2015/08/28 13:30:42 UTC

[3/6] couchdb-docker git commit: 2.0: fix build, user master

2.0: fix build, user master


Project: http://git-wip-us.apache.org/repos/asf/couchdb-docker/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-docker/commit/c4525b13
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-docker/tree/c4525b13
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-docker/diff/c4525b13

Branch: refs/heads/master
Commit: c4525b13475d3fd7ad6e153c7a08352fe31b9ef2
Parents: 44e5dd9
Author: klaemo <kl...@fastmail.fm>
Authored: Fri Aug 21 16:54:45 2015 +0200
Committer: klaemo <kl...@fastmail.fm>
Committed: Fri Aug 21 16:54:45 2015 +0200

----------------------------------------------------------------------
 2.0-dev/Dockerfile |  21 ++--
 2.0-dev/run.py     | 298 ------------------------------------------------
 README.md          |  22 +++-
 3 files changed, 25 insertions(+), 316 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-docker/blob/c4525b13/2.0-dev/Dockerfile
----------------------------------------------------------------------
diff --git a/2.0-dev/Dockerfile b/2.0-dev/Dockerfile
index f4c338a..5f3e661 100644
--- a/2.0-dev/Dockerfile
+++ b/2.0-dev/Dockerfile
@@ -36,26 +36,21 @@ RUN dpkg -i esl-erlang_18.0-1~debian~wheezy_amd64.deb
 RUN git clone https://github.com/rebar/rebar /usr/src/rebar \
  && (cd /usr/src/rebar ; make && mv rebar /usr/local/bin/)
 
- RUN cd /usr/src \
-   && git clone https://git-wip-us.apache.org/repos/asf/couchdb.git \
-   && cd couchdb \
-   && git checkout developer-preview-2.0
+RUN cd /usr/src \
+  && git clone https://git-wip-us.apache.org/repos/asf/couchdb.git \
+  && cd couchdb \
+  && git checkout master
 
 RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
   && echo 'deb https://deb.nodesource.com/node wheezy main' > /etc/apt/sources.list.d/nodesource.list \
   && echo 'deb-src https://deb.nodesource.com/node wheezy main' >> /etc/apt/sources.list.d/nodesource.list \
-  && apt-get update -y && apt-get install -y nodejs
+  && apt-get update -y && apt-get install -y nodejs \
+  && npm install -g npm && npm install -g grunt-cli
 
-RUN cd /usr/src/couchdb \
-  && npm install -g npm \
-  && npm install -g grunt-cli \
-  && ./configure --disable-docs && make
+RUN cd /usr/src/couchdb && ./configure --disable-docs && make
 
 # permissions
-RUN rm -rf /usr/src/couchdb/dev/run
-COPY ./run.py /usr/src/couchdb/dev/run
-RUN chmod +x /usr/src/couchdb/dev/run
-RUN chown -R couchdb:couchdb /usr/src/couchdb
+RUN chmod +x /usr/src/couchdb/dev/run && chown -R couchdb:couchdb /usr/src/couchdb
 
 USER couchdb
 

http://git-wip-us.apache.org/repos/asf/couchdb-docker/blob/c4525b13/2.0-dev/run.py
----------------------------------------------------------------------
diff --git a/2.0-dev/run.py b/2.0-dev/run.py
deleted file mode 100644
index fa485b4..0000000
--- a/2.0-dev/run.py
+++ /dev/null
@@ -1,298 +0,0 @@
-#!/usr/bin/env python
-#
-# 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.
-
-import atexit
-import contextlib as ctx
-import glob
-import httplib
-import optparse as op
-import os
-import re
-import select
-import subprocess as sp
-import sys
-import time
-import traceback
-import urllib
-import uuid
-
-from pbkdf2 import pbkdf2_hex
-
-# clipped down from e.g. '0x594fc30efe7746318d7d79684a15cfd0L'
-COMMON_SALT = hex(uuid.uuid4().int)[2:-1]
-
-USAGE = "%prog [options] [command to run...]"
-DEV_PATH = os.path.dirname(os.path.abspath(__file__))
-COUCHDB = os.path.dirname(DEV_PATH)
-
-DEFAULT_N = 3
-PROCESSES = []
-
-
-def init_log_dir():
-    logdir = os.path.join(DEV_PATH, "logs")
-    if not os.path.exists(logdir):
-        os.makedirs(logdir)
-
-
-def init_beams():
-    # Including this for people that forget to run
-    # make dev.
-    for fname in glob.glob(os.path.join(DEV_PATH, "*.erl")):
-        cmd = [
-            "erlc",
-            "-o", DEV_PATH + os.sep,
-            fname
-        ]
-        sp.check_call(cmd)
-
-
-def hack_default_ini(opts, node, args, contents):
-    # Replace log file
-    logfile = os.path.join(DEV_PATH, "logs", "%s.log" % node)
-    repl = "file = %s" % logfile
-    contents = re.sub("(?m)^file.*$", repl, contents)
-
-    # Replace couchjs command
-    couchjs = os.path.join(COUCHDB, "src", "couch", "priv", "couchjs")
-    mainjs = os.path.join(COUCHDB, "share", "server", "main.js")
-    coffeejs = os.path.join(COUCHDB, "share", "server", "main-coffee.js")
-
-    repl = "javascript = %s %s" % (couchjs, mainjs)
-    contents = re.sub("(?m)^javascript.*$", repl, contents)
-
-    repl = "coffeescript = %s %s" % (couchjs, coffeejs)
-    contents = re.sub("(?m)^coffeescript.*$", repl, contents)
-
-    return contents
-
-
-def hashify(pwd, salt=COMMON_SALT):
-    """
-    Implements password hasshing according to:
-      - https://issues.apache.org/jira/browse/COUCHDB-1060
-      - https://issues.apache.org/jira/secure/attachment/12492631/0001-Integrate-PBKDF2.patch
-
-    This test uses 'candeira:candeira'
-
-    >>> hashify(candeira)
-    -pbkdf2-99eb34d97cdaa581e6ba7b5386e112c265c5c670,d1d2d4d8909c82c81b6c8184429a0739,10
-    """
-    iterations = 10
-    keylen = 20
-    derived_key = pbkdf2_hex(pwd, salt, iterations, keylen)
-    return "-pbkdf2-%s,%s,%s" % (derived_key, salt, iterations)
-
-def hack_local_ini(opts, node, args, contents):
-    # make sure all three nodes have the same secret
-    secret_line = "secret = %s\n" % COMMON_SALT
-    previous_line = "; require_valid_user = false\n"
-    contents = contents.replace(previous_line, previous_line + secret_line)
-    # if --admin user:password on invocation, make sure all three nodes
-    # have the same hashed password
-    if opts.admin is None:
-        return contents
-    usr, pwd = opts.admin.split(":", 1)
-    return contents + "\n%s = %s" % (usr, hashify(pwd))
-
-
-def write_config(opts, node, args):
-    etc_src = os.path.join(COUCHDB, "rel", "overlay", "etc")
-    etc_tgt = os.path.join(DEV_PATH, "lib", node, "etc")
-    if not os.path.exists(etc_tgt):
-        os.makedirs(etc_tgt)
-
-    etc_files = glob.glob(os.path.join(etc_src, "*"))
-    for fname in etc_files:
-        base = os.path.basename(fname)
-        tgt = os.path.join(etc_tgt, base)
-        with open(fname) as handle:
-            contents = handle.read()
-        for key in args:
-            contents = re.sub("{{%s}}" % key, args[key], contents)
-        if base == "default.ini":
-            contents = hack_default_ini(opts, node, args, contents)
-        elif base == "local.ini":
-            contents = hack_local_ini(opts, node, args, contents)
-        with open(tgt, "w") as handle:
-            handle.write(contents)
-
-
-def write_configs(opts):
-    datadir = os.path.join(DEV_PATH, "data")
-    if not os.path.exists(datadir):
-        os.makedirs(datadir)
-    for i in range(1, N+1):
-        node = "node%d" % i
-        args = {
-            "prefix": COUCHDB,
-            "package_author_name": "The Apache Software Foundation",
-            "data_dir": os.path.join(DEV_PATH, "lib", node, "data"),
-            "view_index_dir": os.path.join(DEV_PATH, "lib", node, "data"),
-            "node_name": "-name %s@127.0.0.1" % node,
-            "cluster_port": str((10000 * i) + 5984),
-            "backend_port" : str((10000 * i) + 5986)
-        }
-        if not os.path.exists(args["data_dir"]):
-            os.makedirs(args["data_dir"])
-        write_config(opts, node, args)
-
-
-def all_nodes_alive(n):
-    for i in range(1, n+1):
-        url = "http://127.0.0.1:{0}/".format(local_port(i))
-        while True:
-            try:
-                with ctx.closing(urllib.urlopen(url)) as resp:
-                    pass
-            except IOError:
-                time.sleep(0.25)
-                continue
-            break
-    return True
-
-
-def local_port(n):
-    return 10000 * n + 5986
-
-
-def node_port(n):
-    return 10000 * n + 5984
-
-
-def boot_node(node):
-    apps = os.path.join(COUCHDB, "src")
-    env = os.environ.copy()
-    env["ERL_LIBS"] = os.pathsep.join([apps])
-    cmd = [
-        "erl",
-        "-args_file", os.path.join(DEV_PATH, "lib", node, "etc", "vm.args"),
-        "-config", os.path.join(COUCHDB, "rel", "files", "sys"),
-        "-couch_ini",
-            os.path.join(DEV_PATH, "lib", node, "etc", "default.ini"),
-            os.path.join(DEV_PATH, "lib", node, "etc", "local.ini"),
-        "-reltool_config", os.path.join(COUCHDB, "rel", "reltool.config"),
-        "-parent_pid", str(os.getpid()),
-        "-pa", DEV_PATH,
-        "-pa", os.path.join(COUCHDB, "src", "*"),
-        "-s", "boot_node"
-    ]
-    logfname = os.path.join(DEV_PATH, "logs", "%s.log" % node)
-    log = open(logfname, "w")
-    return sp.Popen(
-            cmd,
-            stdin=sp.PIPE,
-            stdout=log,
-            stderr=sp.STDOUT,
-            env=env)
-
-
-def connect_nodes(host, port):
-    global N
-    for i in range(1, N+1):
-        body = "{}"
-        conn = httplib.HTTPConnection(host, port)
-        conn.request("PUT", "/nodes/node%d@127.0.0.1" % i, body)
-        resp = conn.getresponse()
-        if resp.status not in (200, 201, 202, 409):
-            print resp.reason
-            exit(1)
-
-
-def kill_processes():
-    global PROCESSES
-    for p in PROCESSES:
-        if p.returncode is None:
-            p.kill()
-
-
-def boot_nodes():
-    global N, PROCESSES
-    for i in range(1, N+1):
-        p = boot_node("node%d" % i)
-        PROCESSES.append(p)
-
-    for i in range(30):
-        if all_nodes_alive(N):
-            print "Cluster is up, go to http://127.0.0.1:15984/_utils"
-            break
-        time.sleep(1)
-    time.sleep(1)
-
-
-def reboot_nodes():
-    kill_processes()
-    boot_nodes()
-
-
-def run_command(cmd):
-    p = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sys.stderr)
-    while True:
-        line = p.stdout.readline()
-        if not line:
-            break
-        try:
-            eval(line)
-        except:
-            traceback.print_exc()
-            exit(1)
-    p.wait()
-    exit(p.returncode)
-
-
-def wait_for_procs():
-    global PROCESSES
-    while True:
-        for p in PROCESSES:
-            if p.returncode is not None:
-                exit(1)
-        time.sleep(2)
-
-
-def options():
-    return [
-        op.make_option("-a", "--admin", metavar="USER:PASS", default=None,
-            help="Add an admin account to the development cluster"),
-        op.make_option("-n", "--nodes", metavar="N", default=DEFAULT_N,
-            type="int", help="Number of development nodes to be spun up")
-    ]
-
-
-def main():
-    parser = op.OptionParser(usage=USAGE, option_list=options())
-    opts, args = parser.parse_args()
-
-    global N
-    N = opts.nodes
-
-    init_log_dir()
-    init_beams()
-    write_configs(opts)
-
-    atexit.register(kill_processes)
-
-    boot_nodes()
-    connect_nodes("127.0.0.1", 15986)
-
-    if len(args):
-        run_command(" ".join(args))
-    else:
-        wait_for_procs()
-
-
-if __name__ == "__main__":
-    try:
-        main()
-    except KeyboardInterrupt:
-        pass

http://git-wip-us.apache.org/repos/asf/couchdb-docker/blob/c4525b13/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 8d094ef..e6d1147 100644
--- a/README.md
+++ b/README.md
@@ -49,11 +49,23 @@ Available on the docker registry as [klaemo/couchdb:2.0-dev](https://index.docke
 
 ```bash
 # expose the cluster to the world
-[sudo] docker run -i -t -p 15984:15984 -p 25984:25984 -p 35984:35984 --name couchdb klaemo/couchdb:2.0-dev
-
-curl http://localhost:15984
-curl http://localhost:25984
-curl http://localhost:35984
+[sudo] docker run -p 15984:15984 -p 25984:25984 -p 35984:35984 klaemo/couchdb:2.0-dev
+
+[ * ] Setup environment ... ok
+[ * ] Ensure CouchDB is built ... ok
+[ * ] Prepare configuration files ... ok
+[ * ] Start node node1 ... ok
+[ * ] Start node node2 ... ok
+[ * ] Start node node3 ... ok
+[ * ] Check node at http://127.0.0.1:15984/ ... failed: [Errno socket error] [Errno 111] Connection refused
+[ * ] Check node at http://127.0.0.1:25984/ ... ok
+[ * ] Check node at http://127.0.0.1:35984/ ... ok
+[ * ] Check node at http://127.0.0.1:15984/ ... ok
+[ * ] Running cluster setup ... ok
+[ * ] Developers cluster is set up at http://127.0.0.1:15984.
+Admin username: root
+Password: 37l7YDQJ
+Time to hack! ...
 ```
 
 ...or you can pass arguments to the binary