Skip to content

Commit dbc7613

Browse files
authored
Merge pull request #33 from matburt/docker_packaging
Docker packaging
2 parents 91de0aa + c91b169 commit dbc7613

8 files changed

Lines changed: 55 additions & 7 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ sdist: dist/$(NAME)-$(VERSION).tar.gz
3131
dist/$(NAME)-$(VERSION).tar.gz:
3232
$(DIST_PYTHON) setup.py sdist
3333

34+
image: dist
35+
docker build --rm=true -t $(IMAGE_NAME) -f ./packaging/docker/Dockerfile .
36+
3437
dev:
3538
pipenv install
3639

packaging/docker/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM centos:8
2+
3+
ADD https://github.com/krallin/tini/releases/download/v0.18.0/tini /bin/tini
4+
ADD packaging/docker/entrypoint.sh /bin/entrypoint
5+
ADD packaging/docker/receptor.conf /tmp/receptor.conf
6+
RUN yum install -y python36 python3-dateutil
7+
ADD dist/receptor-0.1.0-py2.py3-none-any.whl /tmp/receptor-0.1.0-py2.py3-none-any.whl
8+
RUN pip3 install /tmp/receptor-0.1.0-py2.py3-none-any.whl
9+
RUN mkdir -p /receptor && \
10+
chmod +x /bin/tini /bin/entrypoint && \
11+
rm -rf /var/cache/yum
12+
VOLUME /receptor
13+
ENV LANG=en_US.UTF-8
14+
ENV LANGUAGE=en_US:en
15+
ENV LC_ALL=en_US.UTF-8
16+
ENV HOME=/receptor
17+
EXPOSE 8888/tcp
18+
WORKDIR /receptor
19+
ENTRYPOINT ["entrypoint"]
20+
CMD ["receptor", "-c", "/receptor/receptor.conf", "node"]

packaging/docker/entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# In OpenShift, containers are run as a random high number uid
4+
# that doesn't exist in /etc/passwd, but Ansible module utils
5+
# require a named user. So if we're in OpenShift, we need to make
6+
# one before Ansible runs.
7+
if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then
8+
9+
cat << EOF > /tmp/passwd
10+
root:x:0:0:root:/root:/bin/bash
11+
receptor:x:`id -u`:`id -g`:,,,:/receptor:/bin/bash
12+
EOF
13+
14+
cat /tmp/passwd > /etc/passwd
15+
rm /tmp/passwd
16+
fi
17+
18+
if [ ! -f /receptor/receptor.conf ]; then
19+
cp /tmp/receptor.conf /receptor/receptor.conf
20+
fi
21+
22+
exec tini -- "${@}"

packaging/docker/receptor.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[default]
2+
data_dir=/receptor/data
3+
debug=True

receptor/__main__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import argparse
2-
import datetime
31
import logging
42
import logging.config
53
import sys
64

75
from .config import ReceptorConfig
8-
from .receptor import Receptor
96

107
logger = logging.getLogger(__name__)
118

receptor/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
}
3232

33+
3334
def py_class(class_spec):
3435
if class_spec not in SINGLETONS:
3536
module_name, class_name = class_spec.rsplit('.', 1)
@@ -256,8 +257,8 @@ def __init__(self, args=None):
256257
self.parse_options(args)
257258

258259
def add_config_option(self, section, key, cli=True, short_option='', long_option='',
259-
default_value=None, set_value=None, value_type=None, listof=None, subparse=True,
260-
hint=None):
260+
default_value=None, set_value=None, value_type=None, listof=None, subparse=True,
261+
hint=None):
261262

262263
config_entry = '%s_%s' % (section, key)
263264
if cli:
@@ -404,7 +405,7 @@ def _enforce_value_type(self, value, value_type):
404405
def go(self):
405406
if not self._parsed_args:
406407
raise ReceptorRuntimeError("there are no parsed args yet")
407-
elif not hasattr(self._parsed_args, 'subparser_name'):
408+
elif not hasattr(self._parsed_args, 'func'):
408409
raise ReceptorRuntimeError("you must specify a subcommand (%s)." % (", ".join(SUBCOMMAND_EXTRAS.keys()),))
409410
self._parsed_args.func(self)
410411

receptor/controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def connect_to_socket(socket_path):
1414
sock.connect(socket_path)
1515
return sock
1616

17+
1718
def send_directive(directive, recipient, payload, sock):
1819
if payload == '-':
1920
payload = sys.stdin.read()
@@ -28,6 +29,7 @@ def send_directive(directive, recipient, payload, sock):
2829

2930
return response
3031

32+
3133
# FIXME: the socket path is in the config, it shouldn't need to be passed as an arg here
3234
def mainloop(receptor, socket_path, loop=asyncio.get_event_loop()):
3335
config = receptor.config

receptor/receptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, config, node_id=None, router_cls=None,
2424
self.controller_connections = []
2525
self.base_path = os.path.join(self.config.default_data_dir, self.node_id)
2626
if not os.path.exists(self.base_path):
27-
os.mkdir(os.path.join(self.config.default_data_dir, self.node_id))
27+
os.makedirs(os.path.join(self.config.default_data_dir, self.node_id))
2828
self.connection_manifest_path = os.path.join(self.base_path, "connection_manifest")
2929
self.stop = False
3030

0 commit comments

Comments
 (0)