Skip to content

Commit

Permalink
Run docker under current user
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhen Li committed Jun 23, 2019
1 parent f815eaa commit e2983c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions boltkit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def handle_input(value, neo4j):
"Both of the folder paths should be absolute paths. "
"When starting a cluster, sub-folders for each cluster are expected. "
"Otherwise new sub-folders will be auto-created inside the given host folder.")
@click.option("--user", type=int,
help="Specify the user to run Neo4j docker container.")
@click.option("--env", multiple=True,
help="Extra environment variables to the neo4j docker container. "
"Use this to pass customized configurations to neo4j. "
Expand Down
17 changes: 12 additions & 5 deletions boltkit/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"dbms.memory.heap.initial_size": "300m",
"dbms.memory.heap.max_size": "500m",
"dbms.transaction.bookmark_ready_timeout": "5s",
"dbms.backup.enabled": "false"}
"dbms.backup.enabled": "false",
"dbms.connectors.default_listen_address": "::",
}

DEFAULT_WAIT_TIMEOUT = 120 # 2 mins

Expand All @@ -59,7 +61,7 @@ class Neo4jMachine:

ready = 0

def __init__(self, name, service_name, image, auth, bolt_port, http_port, volume, env, **config):
def __init__(self, name, service_name, image, auth, bolt_port, http_port, volume, env, user, **config):
self.name = name
self.service_name = service_name
self.fq_name = "{}.{}".format(self.name, self.service_name)
Expand Down Expand Up @@ -93,6 +95,7 @@ def __init__(self, name, service_name, image, auth, bolt_port, http_port, volume
source, target = s.split(":")
volumes[source] = {'bind': target, 'mode': 'rw'}


def create_container(img):
return self.docker.containers.create(img,
detach=True,
Expand All @@ -101,7 +104,8 @@ def create_container(img):
name=self.fq_name,
network=self.service_name,
ports=ports,
volumes=volumes)
volumes=volumes,
user=user)

try:
self.container = create_container(self.image)
Expand Down Expand Up @@ -340,7 +344,7 @@ def find_and_stop(cls, service_name):
class Neo4jStandaloneService(Neo4jService):
default_image = "neo4j:latest"

def __init__(self, name=None, bolt_port=None, http_port=None, volume=None, env=None, **parameters):
def __init__(self, name=None, bolt_port=None, http_port=None, volume=None, env=None, user=None, **parameters):
super().__init__(name, **parameters)
machine = Neo4jMachine(
"z",
Expand All @@ -351,6 +355,7 @@ def __init__(self, name=None, bolt_port=None, http_port=None, volume=None, env=N
http_port=http_port or self.default_http_port,
volume=volume or {},
env=env or {},
user=user,
)
self.routers[machine.fq_name] = machine
self.machines.append(machine)
Expand All @@ -375,7 +380,7 @@ def _port_range(cls, base_port, count):
return range(base_port, base_port + count)

def __init__(self, name=None, bolt_port=None, http_port=None, n_cores=None, n_replicas=None, volume=None, env=None,
**parameters):
user=None, **parameters):
super().__init__(name, n_cores=n_cores, n_replicas=n_replicas, **parameters)
if not "enterprise" in self.image:
raise ValueError("Enterprise neo4j docker image is required for cluster")
Expand Down Expand Up @@ -411,6 +416,7 @@ def __init__(self, name=None, bolt_port=None, http_port=None, n_cores=None, n_re
http_port=core_http_port_range[i],
volume=["{}:{}".format(path.join(s.split(":")[0], core_names[i]), s.split(":")[1]) for s in volume],
env=env,
user=user,
**{
"causal_clustering.initial_discovery_members": ",".join(core_addresses),
"causal_clustering.minimum_core_cluster_size_at_formation": self.n_cores,
Expand Down Expand Up @@ -441,6 +447,7 @@ def __init__(self, name=None, bolt_port=None, http_port=None, n_cores=None, n_re
http_port=replica_http_port_range[i],
volume=["{}:{}".format(path.join(s.split(":")[0], replica_names[i]), s.split(":")[1]) for s in volume],
env=env,
user=user,
**{
"causal_clustering.initial_discovery_members": ",".join(core_addresses),
"dbms.connector.bolt.advertised_address": "localhost:{}".format(replica_bolt_port_range[i]),
Expand Down

0 comments on commit e2983c8

Please sign in to comment.