News for hackers. Stuff that matters.
Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @05:13PM (#18204762)
We're struggling using containers for our Python and Javascript applications. I think we're using venvs and node_modules and we oughtn't (or we shouldn't keep them in our project directory where they sometimes--but not always--get overwritten by source code volume mounts).
Re:Warp – self-contained, single binary applications by TheDong on Friday October 12, 2018 @06:24PM (#18205149)
It can be a little tricky to do things right here.

There are a few things of note:

1. The .dockerignore file can be used to prevent use of your `node_modules` folder during `docker build`, even if you have something like `COPY . .` in your Dockerfile.. This can let you create a new `node_modules` folder from your lockfile as part of the docker build process to create an image for testing/deployment.

2. You can maintain separate Dockerfiles and such for development and for release, so e.g. for development you might use volumes and not copy things in, but for release you wouldn't use volumes for source code.

I can't tell from what you said, but it seems like one of those two tips might be relevant.

It's okay to have a development setup which doesn't use containers and then use containers for deployment (so long as you have an integ or staging environment that uses containers) as well. It's quite reasonable to have a venv during development, but inside the docker image to not use a venv at all since things will already be reasonably isolated inside the container's fs.

Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @07:42PM (#18205468)
Thanks for the suggestions! I had to check, but we do both of those things. To make sure that node_modules aren't overwritten, we mount an empty named volume to the node_modules directory. I guess mounting the named volume directory somehow causes the node_modules directory from the base image to appear inside of the bind-mounted directory. We do the same thing for venvs as well.

We use venvs inside of the Docker container because we use pipenv and apparently pipenv's support for installing to the system is buggy and/or idiosyncratic.

Re:Warp – self-contained, single binary applications by TheDong on Friday October 12, 2018 @09:51PM (#18205935)
Named volumes are hacky to no end and you shouldn't be using them to make sure it's empty; you should be using `.dockerignore` or being careful about what you copy in.

The pipenv bit is probably more reasonable, and I'm afraid I haven't used it enough to be sure what rough edges are likely there.

Re:Warp – self-contained, single binary applications by devxpy on Saturday October 13, 2018 @03:22AM (#18206852)
I've been using shiv recently for my django deploys.

You might wanna check it out.

Here is a small readme I put together...

https://github.com/devxpy/shiv/blob/8d8298d21380dcf0b1970856...

Re:Warp – self-contained, single binary applications by dharmab on Friday October 12, 2018 @05:38PM (#18204898)
Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @05:49PM (#18204969)
Sorry if I'm a little dense; that doesn't seem like it solves any problems. It just says "use virtualenv and/or docker". I guess I was hoping for "how to manage dependencies in a localdev-friendly way for a Python/Docker app" or something.
Re:Warp – self-contained, single binary applications by VonGallifrey on Friday October 12, 2018 @06:44PM (#18205250)
Not sure if that helps, but here is what I do:

We just use a requirements.txt [1] for each service and run pip with the -r flag in the dockerfile. No Virtualenv in the container.

Most of the time we run these containers with docker-compose locally, but sometimes we want to run the service outside the container. For that we create a virtualenv outside the folder where we keep the source for the service. The reason for that is that we don't want to accidental copy the virtualenv in to the container. It wouldn't do much there but it would increase the container size.

You can do this easily with just "python3 -m venv", but there are some tools that help with that as well. I personally use pyenv-virtualenv [2] which just keeps all virtualenvs in ~/.pyenv/versions/<env>, but there is also conda [3] and virtualenvwrapper [4] which also store the virtualenvs in a central directory.

I am not sure if there really is any more to it.

[1]: https://pip.pypa.io/en/stable/user_guide/#requirements-files

[2]: https://github.com/pyenv/pyenv-virtualenv

[3]: https://conda.io/docs/user-guide/getting-started.html#managi...

[4]: https://virtualenvwrapper.readthedocs.io/en/latest/

Re:Warp – self-contained, single binary applications by dsnuh on Friday October 12, 2018 @05:59PM (#18205039)
I'm not sure if I understand correctly. Are you saying that you run venv commands as part of the build step for your containers (i.e. a RUN line in you Dockerfile) and then pip installing modules in another build step?
Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @07:36PM (#18205449)
No, we use pipenv instead of pip, and pipenv manages a venv. There are `--system` flags, but I guess support for installing things to the system is a little buggy or idiosyncratic or something so we use the venv behavior. I'm not sure why we tell pipenv to install the venv in the project directory though. We do the pipenv install as a RUN line in our Dockerfile. Does this answer your question?
Re:Warp – self-contained, single binary applications by dsnuh on Friday October 12, 2018 @07:45PM (#18205482)
Yeah, I think I have an understanding now. We use tagged Docker base images with the app dependencies baked in so you can just use a FROM your Dockerfile and know you have the dependencies in the image and you just add and run your app code.
Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @07:49PM (#18205500)
Yeah, we do the same thing. This seems to work pretty well, except right now we build these images out of band of our normal build process (if you change these base images, you're expected to kick off another CI job that builds/pushes new versions and updates the versions in the FROM statements in our production Dockerfiles (and our docker-compose.ymls). I'm not sure why we're doing this, since the build cache is actually pretty good at avoiding unnecessary base image builds.
Re:Warp – self-contained, single binary applications by dsnuh on Friday October 12, 2018 @09:02PM (#18205779)
That's how we do it also. You need to integrate a new process that is triggered on base image rebuild that redeploys your container with the new base image (which has security fixes, etc). This pipeline needs to start in Dev and be applied in all your environments, so that you know you are promoting a good base image once you get to production.

We use Kubernetes to trigger rolling restarts with new images when we release a change to the base image, and so far it's been painless, but a lot of work went into it. We use Gitlab, but any CI/CD should allow you to do it.

Re:Warp – self-contained, single binary applications by dharmab on Friday October 12, 2018 @06:25PM (#18205153)
Plop a requirements.txt file down in each repo. Use direnv or a similar tool to automatically manage virtualenvs on the local dev machines. In your container, don't use virtualenv; just add requirements.txt to the container and run pip install -r requirements.txt

See the linked code at the bottom of the page

Re:Warp – self-contained, single binary applications by dev_dull on Friday October 12, 2018 @06:34PM (#18205204)
There are so many places where this will never work. For example, if you're using openssl and you're system is missing the header files.
Re:Warp – self-contained, single binary applications by dharmab on Friday October 12, 2018 @06:44PM (#18205249)
Which is why I run and debug locally with an interactive container; installing the packages locally is just for my editor autocompletion.
Re:Warp – self-contained, single binary applications by dec0dedab0de on Friday October 12, 2018 @05:58PM (#18205033)
Have you tried pipenv? It creates a lock file that hashes all your dependencies so it makes sure you get the right one when you deploy.. And it automatically creates the virtualenv if its nog there when you install them.
Re:Warp – self-contained, single binary applications by weberc2 on Friday October 12, 2018 @07:46PM (#18205486)
We do use pipenv. I like the idea of it, but I think we ran into issues with where the pipenv lives. We used to use `--system`, but that seemed buggy and/or idiosyncratic, so we started using a venv and then we started using PIPENV_VENV_IN_PROJECT=true (for some reason) and now it's causing other issues. It seems unclear how it's supposed to be used with Docker containers, but maybe we're just overcomplicating things?