Launching a demonized collector

I am trying to make the simplest possible master image of a buildbot start that runs the buildbot start commands in the ENTRYPOINT/CMD Dockerfile .
I tried using many combinations of dumb-init , gosu and exec , but without success.
The situation is as follows:

  • When I try to start deamonized buildroot using the docker run -d -v $local/vol/bldbot/master:/var/lib/buildbot buildbot-master-test , the container starts successfully, but it terminates abruptly. The log is as follows:

    [timestamp] [-] The log is open.
    [timestamp] [-] twistd 16.0.0 (/ usr / bin / python 2.7.12), launch.
    [timestamp] [-] reactor class: twisted.internet.epollreactor.EPollReactor.
    [timestamp] [-] Running BuildMaster - buildbot.version: 0.9.2
    [timestamp] [-] Downloading configuration from '/var/lib/buildbot/master.cfg'
    [timestamp] [-] Setting up the database with the URL "sqlite: /state.sqlite"
    [timestamp] [-] setting the database log mode to 'wal'
    [timestamp] [-] housekeeping for master 1 c8aa8b0d5ca3: / var / lib / buildbot
    [timestamp] [-] adding 1 new changes, deleting 0
    [timestamp] [-] adding 1 new builders, removing 0
    [timestamp] [-] adding 2 new schedulers, removing 0
    [timestamp] [-] The web server is not configured on this host
    [timestamp] [-] adding 1 new employees, removing 0
    [timestamp] [-] PBServerFactory since 9989
    [timestamp] [-] Starting the factory
    [timestamp] [-] BuildMaster is working

  • When I launch the container interactively using the docker run --rm -it -v $local/vol/bldbot/master:/var/lib/buildbot buildbot-master-test /bin/sh and then run the buildbot start command Everything works like a spell.

I have already studied the contents of the official image of the original docker buildbot, i.e. buildbot/buildbot-master . I see that the authors decided to use the exec twistd -ny $B/buildbot.tac in start_buildbot.sh , rather than their own buildbot start .

So, the question is how to compile ENTRYPOINT/CMD instructions in a Docker file that just runs buildbot start .


APPENDIX 1

Dockerfile content

 FROM alpine:3.4 ENV BASE_DIR=/var/lib/buildbot SRC_DIR=/usr/src/buildbot COPY start $SRC_DIR/ RUN \ echo @testing http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \ echo @community http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \ apk add --no-cache \ python \ py-pip \ py-twisted \ py-cffi \ py-cryptography@community \ py-service_identity@community \ py-sqlalchemy@community \ gosu@testing \ dumb-init@community \ py-jinja2 \ tar \ curl && \ # install pip dependencies pip install --upgrade pip setuptools && \ pip install "buildbot" && \ rm -r /root/.cache WORKDIR $BASE_DIR RUN \ adduser -D -s /bin/sh bldbotmaster && \ chown bldbotmaster:bldbotmaster . VOLUME $BASE_DIR CMD ["dumb-init", "/usr/src/buildbot/start","buildbot","master"] 

APPENDIX 2

start script content

 #!/bin/sh set -e BASE_DIR=/var/lib/buildbot if [[ "$1" = 'buildbot' && "$2" = 'master' ]]; then if [ -z "$(ls -A "$BASE_DIR/master.cfg" 2> /dev/null)" ]; then gosu bldbotmaster buildbot create-master -r $BASE_DIR gosu bldbotmaster cp $BASE_DIR/master.cfg.sample $BASE_DIR/master.cfg fi exec gosu bldbotmaster buildbot start $BASE_DIR fi exec " $@ " 
+5
source share
2 answers

Buildbot bootstraps are based on Twisted .tac files that are expected to be launched using twistd -y buildbot.tac . buildbot start script is actually just a handy wrapper around twistd. It actually launches twistd and then monitors the logs to confirm that buildbot has started successfully. There is no added value beyond this log viewer, so it is not necessary to run buildbot with the launch of buildbot. You can simply run it with twistd -y buildbot.tac .

As you pointed out, the official docker image starts with buildbot with twistd -ny buildbot.tac If you look at the twistd help, -y means that the Twisted daemon will run the .tac file, and -n means that it will not demonize. This is due to the fact that the docker monitors the process by itself and does not want its entry point to be demonized.

The buildbot start command also has the --nodaemon parameter, which is really just 'exec'ing to twistd -ny . So, for your dockerfile you can also use twistd -ny or buildbot start --nodaemon , this will work the same.

Another specific Docker is that buildbot.tac is different. He configured twistd logs to output to stdout instead of output to twisted.log. This is because docker design requires logs to be in standard mode so you can configure any fancy cloud navigator regardless of application technology.

+1
source

I examined the docker and buildbot link again and found one of them.
There is a note with ngnix example

Do not pass the service x start command to a separate container. For example, this command tries to start the nginx service.

$ docker run -d -p 80:80 my_image service nginx start

This allows you to start the nginx service inside the container. However, in this case, the paradigm of the disconnected container is not fulfilled, the root process ( service nginx start ) is returned, and the disconnected container stops as planned. As a result, the nginx service starts, but cannot be used. Instead, to start a process such as the nginx web server, follow these steps:

$ docker run -d -p 80:80 my_image nginx -g 'daemon off;'

On the other hand, there is an option

The --nodaemon parameter tells Buildbot to skip the demon. The process will begin in the foreground. It will return to the command line only after it stops.

Both of the above routes give

 exec gosu bldbotmaster buildbot start --nodaemon $BASE_DIR 

in the start script line, which solves at least a sharp termination phenomenon.

0
source

Source: https://habr.com/ru/post/1261776/


All Articles