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

Improve development experience with Docker #5966

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

victornoel
Copy link
Contributor

@victornoel victornoel commented Sep 24, 2018

This should close #5987 too

@victornoel victornoel force-pushed the improve-docker-experience branch 2 times, most recently from 371574f to bd030d5 Compare September 26, 2018 09:45
@victornoel
Copy link
Contributor Author

@xiaohanyu I see you initially contributed this docker intregration, could it be possible to get a review maybe? Thanks :)

@xiaohanyu
Copy link
Contributor

sure, will do that at this weekend, busy at daily work...

@victornoel
Copy link
Contributor Author

@xiaohanyu have you had the time to check it out? :)

@victornoel victornoel force-pushed the improve-docker-experience branch 2 times, most recently from 1edf7ac to 2d17fb6 Compare October 1, 2018 10:16
@victornoel
Copy link
Contributor Author

@kakoni I have updated the PR to reflect what we discussed in #5802:

  • now the docker image watch both python and frontend code (so no need for extra dev-server except if desired by the dev)
  • the image is built directly by docker-compose.

@codecov-io
Copy link

codecov-io commented Oct 1, 2018

Codecov Report

Merging #5966 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5966   +/-   ##
=======================================
  Coverage   77.33%   77.33%           
=======================================
  Files          67       67           
  Lines        9578     9578           
=======================================
  Hits         7407     7407           
  Misses       2171     2171

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a5ca35...12065ec. Read the comment docs.

@victornoel
Copy link
Contributor Author

@mistercrunch I think this PR solves some of the problems people are having with the dev docker image and also improve the experience a bit, do you think I could get a review in order for it to get merged? thanks!


# Add a normal user
RUN useradd --user-group --create-home --shell /bin/bash work

Copy link
Contributor

Choose a reason for hiding this comment

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

I've read a lot docs about docker practice and it seems not good to run programs inside docker as root, so I create a new work user.

However, I think if we focus these docker files on development, then it's OK.

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 didn't know, if you have some documentation on that I would be interested.

I removed it because it's a pain to manage a user stuffs in docker :)

Copy link
Contributor

Choose a reason for hiding this comment

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

https://medium.com/@mccode/processes-in-containers-should-not-run-as-root-2feae3f0df3b

See some articles like this.

However, I think for development purpose, it's OK to simplify things.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, it's likely that people would want to use this docker image for production, why not keeping a user account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mistercrunch I think it would be safer to use an image based on the pypi package for production use (as in the https://hub.docker.com/r/amancevice/superset/ image) but who knows what people want to do: I will put the user back then!

Copy link
Contributor

Choose a reason for hiding this comment

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

@mistercrunch @victornoel Would it make sense to create two docker images/docker files? One aimed for production and another one for development.

Copy link
Contributor Author

@victornoel victornoel Oct 11, 2018

Choose a reason for hiding this comment

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

@kakoni if we do that, the advantage is that we could simply remove all the content with superset from the image and just provide the dev environment needed for it… but in that case, wouldn't it be easier to just use something like virtualenv? ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can provide two docker images? one for development and one for production?

RUN apt-get update -y \
&& apt-get install -y build-essential libssl-dev \
libffi-dev python3-dev libsasl2-dev libldap2-dev \
vim less postgresql-client redis-tools
Copy link
Contributor

Choose a reason for hiding this comment

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

I put a separate RUN apt-get install -y vim less postgresql-client redis-tools because all vim less postgresql-client redis-tools are convenient tools for development, these are not necessary for production, while other packages like build-essential libssl-dev are needed for superset to run.

I think it's OK to merge here for development purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I will separate them again to make things clearer and fix the broken comment links.

contrib/docker/Dockerfile Show resolved Hide resolved
volumes:
postgres:
external: false
redis:
external: false
superset-node-modules:
frontend-dist:
Copy link
Contributor

Choose a reason for hiding this comment

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

So after you rename to frontend-dist, where's frontend-dist volume? it will be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to remove it, it is not needed anymore

.dockerignore Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@xiaohanyu
Copy link
Contributor

Hi, @victornoel

Sorry for my late response...busy work.

I've checked your code and I think the code looks good to me. I've also left some comments, just for your reference.

Thanks.

@xiaohanyu
Copy link
Contributor

@mistercrunch vote up for this PR

@victornoel
Copy link
Contributor Author

@xiaohanyu thanks a lot for the feedbacks, I updated the PR to take your comments into account.

@mistercrunch just one open question is: should superset db upgrade and/or superset init be run everytime superset is started? For example for when schemas change, or there are migrations of the db?

@mistercrunch
Copy link
Member

These two commands only need to run when upgrading Superset.

@victornoel
Copy link
Contributor Author

@mistercrunch @xiaohanyu I'm having trouble with the current state of the image: for a reason I don't understand, running it started to show me lots of errors such as:

superset_1  | 2018-10-11 13:35:49,625:ERROR:flask_appbuilder.security.sqla.manager:Creation of Permission View Error: (sqlite3.IntegrityError) UNIQUE constraint failed: ab_permission_view.permission_id, ab_permission_view.view_menu_id [SQL: 'INSERT INTO ab_permission_view (permission_id, view_menu_id) VALUES (?, ?)'] [parameters: (6, 19)] (Background on this error at: http://sqlalche.me/e/gkpj)
superset_1  | 2018-10-11 13:35:49,641:ERROR:flask_appbuilder.security.sqla.manager:Add Permission to Role Error: Can't flush None value found in collection Role.permissions

Or problem connecting to AMQP:

[2018-10-11 13:46:07,595: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.

I'm not sure if something changed in the config or something like that for this to happen…

@victornoel
Copy link
Contributor Author

Also @mistercrunch is sync-backend in assets meant to be run during image build? Because I ran it and I noticed that the content of the file is not the same one that is currently committed… that seems strange to me.

@SuJiKiNen
Copy link

@mistercrunch @xiaohanyu I'm having trouble with the current state of the image: for a reason I don't understand, running it started to show me lots of errors such as:

superset_1  | 2018-10-11 13:35:49,625:ERROR:flask_appbuilder.security.sqla.manager:Creation of Permission View Error: (sqlite3.IntegrityError) UNIQUE constraint failed: ab_permission_view.permission_id, ab_permission_view.view_menu_id [SQL: 'INSERT INTO ab_permission_view (permission_id, view_menu_id) VALUES (?, ?)'] [parameters: (6, 19)] (Background on this error at: http://sqlalche.me/e/gkpj)
superset_1  | 2018-10-11 13:35:49,641:ERROR:flask_appbuilder.security.sqla.manager:Add Permission to Role Error: Can't flush None value found in collection Role.permissions

That means the db already exists,it concerns the .dockerignore file, you built your local sqlite.db into the image.

a better approach is just converting .gitignore file to .dockeriginore file.

this PR need more refinement.

@victornoel
Copy link
Contributor Author

@SuJiKiNen thanks for the feedback. But there is no sqlite db anywhere in the codebase, I never used that feature. Everything has been working without problem until a few days when this error started to appear. I noticed other opened issues about it (#5987), so I wonder if it's not a problem that was introduced lately in master…

For the record, the instructions in this PR to run superset are:

  • build image
  • start reddis/postgres containers and run the initialisation within the superset container (create admin, run superset db upgrade, run superset init)
  • start superset container (and that's when the problem appears).

I will update the dockerignore file nevertheless to not include the things declared in gitignore :)

@victornoel
Copy link
Contributor Author

@SuJiKiNen I found the problem, my bad, there was a mistake with the volume where the configuration was mounted so it was using sqlite instead of posgres. You comment helped me realise that :)

@victornoel
Copy link
Contributor Author

@SuJiKiNen @mistercrunch @xiaohanyu I pushed the latest fixes to the PR. It works well now.

- Improve Docker image
  - smaller
  - faster to build
  - deterministict dependencies (see apache#5958)
- Rework process to simplify setting things up
  - updated documentation
  - less commands to type
  - no files to move and modify
  - optional loading of samples
- Still working in standalone mode (without volumes for superset)
@victornoel
Copy link
Contributor Author

@mistercrunch @xiaohanyu @SuJiKiNen I've updated this PR with respect to latest master.

@oliviermichaelis
Copy link
Contributor

I tested the docker image with SUPERSET_ENV=production as well as SUPERSET_ENV=development for the last couple of days and it worked flawlessly for me. The build times were shorter and the image size was significantly smaller. Thanks!

Copy link

@KartikTaskhuman KartikTaskhuman left a comment

Choose a reason for hiding this comment

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

@mistercrunch
Copy link
Member

This looks great, merging!

@mistercrunch mistercrunch merged commit 02aa3c6 into apache:master Nov 27, 2018
@victornoel victornoel deleted the improve-docker-experience branch November 27, 2018 19:24
@victornoel
Copy link
Contributor Author

yay!

@kakoni
Copy link
Contributor

kakoni commented Nov 27, 2018

Excellent! Thanks @victornoel !

@mwcm
Copy link

mwcm commented Nov 27, 2018

thank you @victornoel 👍

@emacip
Copy link
Contributor

emacip commented Dec 19, 2018

Sorry, @victornoel did you deleted the docker-build.sh?
I just following the https://superset.incubator.apache.org/installation.html# fails because the file does not exist anymore.

@victornoel
Copy link
Contributor Author

@emacip it seems this documentation is not up to date

@victornoel
Copy link
Contributor Author

@victornoel
Copy link
Contributor Author

if you find problems, just tell me here and I will try to fix them :)

@emacip
Copy link
Contributor

emacip commented Dec 19, 2018

thanks

bipinsoniguavus pushed a commit to ThalesGroup/incubator-superset that referenced this pull request Dec 26, 2018
- Improve Docker image
  - smaller
  - faster to build
  - deterministict dependencies (see apache#5958)
- Rework process to simplify setting things up
  - updated documentation
  - less commands to type
  - no files to move and modify
  - optional loading of samples
- Still working in standalone mode (without volumes for superset)
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed testing Docker image
10 participants