aicastell
aicastell

Reputation: 2402

Dockerfile to run a package revision (PR) server

The purpose is deploying a yocto PR server using a docker container. More info about PR server can be found in the following link:

To try doing that I wrote this "Dockerfile" to generate a docker image:

FROM ubuntu:16.04
MAINTAINER Yocto <[email protected]>

# Update, upgrade and install
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y gawk wget git git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat xterm curl parted python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping libsdl1.2-dev net-tools

# Set up locales
RUN apt-get -y install locales apt-utils sudo && dpkg-reconfigure locales && locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG en_US.utf8

# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Replace dash with bash
RUN rm /bin/sh && ln -s bash /bin/sh

# Yocto user management
RUN groupadd -g 1000 yocto && useradd -u 1000 -g 1000 -ms /bin/bash yocto && usermod -a -G sudo yocto && usermod -a -G users yocto
ENV HOME /home/yocto
USER yocto

# Download poky
RUN git clone --branch rocko git://git.yoctoproject.org/poky /home/yocto/poky

# Create some directories
RUN mkdir -p /home/yocto/build /home/yocto/prserv

# Make /home/yocto/poky the working directory
WORKDIR /home/yocto/poky

# Expose listen port
EXPOSE 8585

# Run PR-server
CMD /bin/sh -c " \
    source ./oe-init-build-env ../build \
    && bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585 \
"

Using previous Dockerfile I build a docker image:

$ docker build -t docker-prserver .
[...]
Successfully built 362f4599b1b6
Successfully tagged docker-prserver:latest

As you can see before, the process ends successfully. After that, I run a container:

$ docker run -ti docker-prserver
yocto@b3c9fd06d8af:~/poky$

The previous command creates a shell. I check if the process “bitbake-prserver” is running:

$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State 

As you can see, the “bitbake-prserver” process is not running (no listen port). However, if I log into the container and execute the CMD command:

yocto@b3c9fd06d8af:~/poky/build$ source ./oe-init-build-env ../build/ && bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585

Then it works fine:

yocto@b3c9fd06d8af:~$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address    State      
tcp        0      0 0.0.0.0:8585            0.0.0.0:*          LISTEN     

It’s supposed that CMD is executed when the container is instantiated, but this is not happening. What is the right way to write a Dockerfile to run a bitbake-prserv server listening on the exposed port?

Hope some of you have some experience on this and can provide any useful feedback.

Thanks a lot in advance! :)

Upvotes: 0

Views: 187

Answers (1)

aicastell
aicastell

Reputation: 2402

I found the right way to fix my issue. First I wrote this script:

$ cat start.sh 
#! /bin/sh

cd /home/yocto/poky
source ./oe-init-build-env ../build
bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585
tail -f /tmp/prserv.log

And after modified the Dockerfile adding this stuff:

ADD start.sh /home/yocto/start.sh
RUN chmod 755 /home/yocto/start.sh
RUN chown yocto.yocto /home/yocto/start.sh
...
CMD /home/yocto/start.sh

Now it works as expected. Hope this helps somebody else!

Upvotes: 1

Related Questions