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

301 docker #318

Merged
merged 4 commits into from
Jan 24, 2019
Merged

301 docker #318

merged 4 commits into from
Jan 24, 2019

Conversation

jpigree
Copy link
Contributor

@jpigree jpigree commented May 19, 2018

Adds Dockerfile from which you can create a Jarvis Docker image from the currently checked out Jarvis code.
I faced multiple issues mainly because in container distribution have many differences from the host ones (systemd, dbus, ...).

A Makefile is also here to document how to build the Dockerfile and run the image.

As a side note, I refactored a bit the setup.sh to pass more cleanly the Python version used.

Dockerfile Outdated
notification-daemon \
sudo \
xorg

Choose a reason for hiding this comment

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

Remove apt cache after installing depndencies as mentioned in dockerfile best practices (https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run)

RUN apt-get update && \
    apt-get -y install \
            dbus-x11 \
            libdbus-1-dev \
            libespeak1 \
            libnotify-cil-dev \
            notification-daemon \
            sudo \
            xorg  && \
     rm -rf /var/lib/apt/lists/*

Dockerfile Outdated
sudo \
xorg

RUN pip3 install virtualenv

Choose a reason for hiding this comment

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

Use pip without cache:

RUN pip3 install --no-cache-dir virtualenv

Dockerfile Outdated
COPY . /app
WORKDIR /app

RUN sudo /bin/bash ./docker.sh
Copy link

@gucharbon gucharbon Sep 3, 2018

Choose a reason for hiding this comment

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

Why use sudo ? Are you not still root user at this point ?
In any way, best pratice is to reduce number of docker layers. Lines 20 to 24 could be added in single layer.

RUN  /bin/bash ./docker.sh && \
    useradd -Um jarvis && \
    echo "jarvis  ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
    chown -R jarvis /app 

After writing this I realize that you add a line into /etc/sudoers so you're definetely root at this point

Dockerfile Outdated
RUN chown -R jarvis /app
USER jarvis

RUN sudo /bin/bash ./setup.sh --python3

Choose a reason for hiding this comment

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

It may not be worth the effort, but I think that if you create a docker image for jarvis, it should not use the setup.sh script since environment is well controlled compared to bare metal machine.

Instead, iI suggest you install deps in Dockerfile, and provide several Dockerfiles if you wish to support several distributions (which may not be necessary). This way you will reduce drastically image size (no virtualenv and no cache when installing with apt or pip, remove archives when installing phantomjs, etc..).

@jpigree
Copy link
Contributor Author

jpigree commented Sep 10, 2018

Hi @gucharbon, thank you for your review. I am working on the fixes you asked. I just have issues making the image work again (I rebased on top of the mainline). I will keep you updated.

Dockerfile Outdated
@@ -0,0 +1,58 @@
FROM python:3.6.5-jessie

env DEBIAN_FRONTEND noninteractive

Choose a reason for hiding this comment

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

Docker linters do not recognize env if it's in lower case most of the time. If you can just change to
ENV DEBIAN_FRONTEND="noninteractive"
it would be more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @gucharbon, thank you for your review. I am working on the fixes you asked. I just have issues making the image work again (I rebased on top of the mainline). I will keep you updated.

I mentioned two little things that could still be changed, but you did a really nice job with this new Dockerfile !

But in any case I'm not reviewer or maintainer of this project, so even if I review it you will still need approval of a maintainer :)

Thanks even more for the review. But how can you be assigned as a reviewer of this PR if you are not a maintainer/reviewer of the project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh Okay, I missread the Github interface. It just says that you reviewed my PR but you are not assigned.

Choose a reason for hiding this comment

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

Yep, just Killing some time :)

RUN wget -qO - https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar xjf - && \
ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

COPY . /app

Choose a reason for hiding this comment

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

I'm not sure if this will set recursively, but you can set ownership during copy:
COPY --chown=jarvis:jarvis . /app

A big advantage is that since docker layers are read only, when copying first and then setting permission, you add twice the size of the content you copy. We noticed that when building image with pretty large content (>1GB) and when modifying ownership in another layer it added 1 GB in the image size. See https://medium.com/@lmakarov/the-backlash-of-chmod-chown-mv-in-your-dockerfile-f12fe08c0b55 and moby/moby#34263 (comment)

@gucharbon
Copy link

Hi @gucharbon, thank you for your review. I am working on the fixes you asked. I just have issues making the image work again (I rebased on top of the mainline). I will keep you updated.

I mentioned two little things that could still be changed, but you did a really nice job with this new Dockerfile !

But in any case I'm not reviewer or maintainer of this project, so even if I review it you will still need approval of a maintainer :)

Dockerfile Outdated
libdbus-1-dev \
libdbus-glib-1-dev \

Choose a reason for hiding this comment

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

You start from python image with version 3.6.5 installed but this line install python3.5 as dependency. You could start from debian instead of python if you do not want to have several python installed (increase size for nothing). You can check that with
apt install --dry-run libdbus-glib-1-dev

Dockerfile Outdated
notification-daemon \
python3-dbus \

Choose a reason for hiding this comment

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

Like before, either build libraries which need python from source or use debian base image instead of python. This will install python3 as debian still uses python3.5 instead of python3.6 by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. I did not realize this. Thanks. This should decrease the image size.

Dockerfile Outdated
notification-daemon \
python3-dbus \
python-dbus \
Copy link

@gucharbon gucharbon Sep 12, 2018

Choose a reason for hiding this comment

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

Remove this line, it will install python2, I don't think you need it if you are using python3.
The same goes for python-notify2 . You can install python3-notify2 instead.
I don't know how you can handle pyhton-imdbpy though, maybe with pip

@StefanosChaliasos
Copy link
Collaborator

@jpigree When you are ready please update the README and publish the image to docker hub. It would be great if you could maintain the image.

@pnhofmann
Copy link
Collaborator

So - what's the progress?

Noticed some dependencies (chromedriver, python3-dbus, build-essential, phantomjs) are obsolete by now (refere #336).

I don't really understand why sudo is configured. Can't think of any Jarvis-functionality, which requires root.

But furthermore, this Dockerfile looks ready for me.

@aditisrinivas97
Copy link

@pnhofmann sudo needs to be configured because the setup.sh file uses it on line 70. If its not configured, you get the following error message :

./setup.sh: line 70: sudo: command not found

@pnhofmann
Copy link
Collaborator

Setup.sh isn't used for Docker.

At last in the latest version of this Dockerfile - sudo looks like leftover from first version which did call setup. Especially since the added sudo-line is removed with 'sed' 2 lines below.

@aditisrinivas97
Copy link

Right! It's in the first version. Thanks!

@jpigree
Copy link
Contributor Author

jpigree commented Jan 21, 2019

Hi. @StefanosChaliasos I just saw your comment today. Sorry. It has been a long time.
Are you still interested into putting this in dockerhub? If I do it myself, this means I will create (and own) the Dockerhub organization "Jarvis" then create the repository for the Docker image. I think this would be unwise as I am not even a contributor of the project yet. This is my first contribution and I don't even use Jarvis for now. What I can do is do all the setup work then hand it over a collaborator/admin of this repository.

@pnhofmann this PR was done in May 2018. I just looked at the history, a lot of commits have been merged since so it needs to be fully retested and adjusted. I will also look at the sudo matter. Give me a few days to rework this.

Hope it will be merged soon afterwards. Don't want to redo the same work again and again. :)

@StefanosChaliasos
Copy link
Collaborator

@jpigree Hello, please create a Dockerfile for the last commit on master branch. We remove most of the dependencies so it's must be simpler.

- Create a Dockerfile which builds a Jarvis container
- Reworked the setup.sh script in order to be able to choose Python
version with flags
Removed unused dependencies and simplified greatly the Dockerfile.
@jpigree
Copy link
Contributor Author

jpigree commented Jan 23, 2019

I updated the Dockerfile. However, from what I see,

@StefanosChaliasos Jarvis does not require the service X anymore?
If so, I will remove the X socket mount in the Makefile command "run_docker".
Then we should be good. We can merge it. For Dockerhub, somebody wants to be owner? I think it will be best to have multiple owners.

@StefanosChaliasos
Copy link
Collaborator

@jpigree you can push it on Dockerhub

@StefanosChaliasos StefanosChaliasos merged commit 1d67bb4 into sukeesh:master Jan 24, 2019
@jpigree jpigree deleted the 301-Docker branch January 24, 2019 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants