Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile to build a portable testing environment #324

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# A Dockerfile to build a development environment for
#
# MM MMMMM
# MM MMMMMMM MMM
# MMMM MMMMMMMMM MMMMM MMMMMMMMMM
# MM MMMMMMMMM MMM MM MMMMMMMMMMMMMMM
# MMMMMM M MMMMMMMMMM MM MMMMMMMMMMMMMMMMMM
# MM M MMMMMMMMM MMMMMMMMMMMMMMMMMMMM
# MM MMM M MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
# MMMMMMMMMMMMM MMMM MMMMMMMMMMMMMMMMMMMMMMMMM
# MMMMMMMMMMMMMM MMM MMMM MMMMMMMMMMMMMMMMMMMMMMMM
# MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
# MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
# MMMMMMMMMMMMM MMMMMMMMMMMMMMMM MMMMMMMMMMMMMMM MMMMMMMM
# M MMMM MM MMMMMMMM MMMMM MMMMMMMMMMMMMMM MM
# MMM MM MM MMM MMMM MMMMMMMMM MM
# MM M MMMMM MMMMMM MMMMMMMMMM MM
# MMM MMMMMM MMMM M MMMMMMMMMMMM MM
# MMM MM M MM MM MMMMMMMMMMMMM
# MMM MM M MM MM MMMMMMMMMMMMMMM
# MM MM M MM MM MMMMMMMMMMMMMM
# MMM MM MM MMM MMMM MMMMMMMMMMMM
# MMM MMM MMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM MM MMM MMMMMMMMMM
# MMM MMM MMMMMMMMMMMMMMMMMMMM MMMMMMMMM MMMMMMMMM MMMM MMM MMMMMMMMMM
# MMM MMM MMMMMM MMM MMM MMM MMM MMM MMMMMMMMM MMMMMMM
# MMM MMM MMMMMMMMM MMM MMM MMMMMMMMM MMM MMM MM MMMMMM MMMM
# MMM MMM MMMMMMMMMMMMMMMMMMMM MMMMMMMMM MM MMM MM MMM MMMM
# MMM MM MMM MMM MMMMMM MMM MMM MMMMMMMM MM MMM MMMM
# MMMMMMMM MMM MMMMMMMMMMMMM MMM MMMMMMMMM MM MMM MM MMM MMMM
# MMMMMMMM MMM MMMMMMMMMMMMM MMM MMMMMMMMM MM MMM MM MMM MMMM
#
#
# To build run the following from the root of the libreant directory:
#
# docker build -t libreant-box .
#
# To start the container and operate inside it run:
#
# docker run --rm -ti libreant-box
#
# or, having managed to install libreant in a virtualenv on the local
# development directory:
#
# docker run --rm -v $PWD:/libreant -ti libreant-box
#
# The last will mount the local directory onto the /libreant directory into the
# container, allowing to test editis inside it.
#
FROM debian:stretch

RUN apt-get update && apt-get install -y \
systemd wget gnupg apt-transport-https \
python2.7 gcc python2.7-dev python-virtualenv
# Add ES gpg key for their repository
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch|tee /tmp/ES.key|\
gpg -|grep -q "46095ACC8548582C1A2699A9D27D666CD88E42B4" &&\
cat /tmp/ES.key|apt-key add -
RUN echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" |\
tee -a /etc/apt/sources.list.d/elastic-6.x.list
RUN apt-get update && apt-get install -y \
# install ES version 6 and python2 requirements
openjdk-8-jre-headless elasticsearch
# Copy libreant directory to /libreant into the container
ADD . /libreant
WORKDIR /libreant
# Coping the SysVint script to appropriate directory
RUN mv libreantd /etc/init.d/
# Installing libreant
RUN virtualenv -p $(which python2) ve && ./ve/bin/pip install -e . &&\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a virtualenv if we are on an ephemeral container? There won't be any conflict with other python packages version since there will be only libreant installed.

# Installing fsdb ;)
./ve/bin/pip install Fsdb
RUN mkdir /fdsb-store

EXPOSE 5000

ENTRYPOINT service elasticsearch start && service libreantd start && bash -i
31 changes: 31 additions & 0 deletions libreantd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
start_libreant_daemon(){
if [ -f /libreant/ve/bin/libreant ];
then
/libreant/ve/bin/libreant --fsdb-path /fsdb-store &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just inline this command /libreant/ve/bin/libreant --fsdb-path /fsdb-store & (which by the way doesn't create a daemon) in Dockerfile RUN section?
I don't see when/why stop will ever be called

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a Dockerfile each RUN is a separate container. The changes made by each RUN are saved in a temporary container during the build and, if the build is successful, such temporary containers are then discarded. If you invoke a

RUN /libreant/ve/bin/libreant --fsdb-path /fsdb-store &

the following RUN will not have any libreant service up. This is why I wrote the daemon and put in the ENTRYPOINT the service libreantd start.
I'd be more comfortable with a systemd unit but AFAIK it (still) does not work (^)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I just meant .ENTRYPOINT
ENTRYPOINT /libreant/ve/bin/libreant --fsdb-path /fsdb-store & && bash -i

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we could do it but I liked the idea of having a service to start|stop|restart libreant 😄

fi
}

stop_libreant_daemon(){
pkill libreant
}

case "$1" in
start)
echo "Starting libreant"
start_libreant_daemon
;;
stop)
echo "Stopping libreant"
stop_libreant_daemon
;;
restart)
echo "Stopping libreant" &&\
stop_libreant_daemon &&\
echo "Starting libreant" &&\
start_libreant_daemon
;;
*)
echo "Usage: $0 (start|stop|restart)" >&2
exit 1
;;
esac