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

Hybrid local development #4810

Open
foarsitter opened this issue Jan 27, 2024 · 6 comments
Open

Hybrid local development #4810

foarsitter opened this issue Jan 27, 2024 · 6 comments

Comments

@foarsitter
Copy link
Collaborator

foarsitter commented Jan 27, 2024

Running a single test inside a container gives me a little more overhead then I would like. Therefore I'm using python locally and leveraging docker for all the external services like redis and postgres. I'm calling it hybrid.

I would like to adjust the template for adding hybrid as an option alongside local & docker.

What is your opinion about this approach?

@JamesParrott
Copy link

JamesParrott commented Jan 29, 2024

Make a fork and lets have a look at it.

It would need launcher scripts instead of letting docker compose spin everything up. I wouldn't use it, but there's still value for users new to django in making a template for the exact example from the django docs introductory app, but with postgres, nginx and traefik etc. working out of the box, using containers. That would be a perfect opportnuity to trim out some of the hacks in cookiecutter-django too (like the non-standard directory structure, copying everything in the repo into the node container right at the start of the Django dockerfile meaning the docker cache is hardly ever useful, and the python script in a string inside a bash script, that waits for a postgres connection).

But for the core mission of cookiecutter-django, and promise it makes to help: "jump start production-ready Django projects quickly", containerising the django run time has the following advantages:

  • Currently local/production.yml is a great reference for what's running in your cookiecutter-django stack.

  • Containerising Django allows the env it's in to be easily reproduced for celery, or for the user's custom services that need to use Django.

  • Containerising makes the stack more portable and cloud agnostic (unlike running locally, it doesn't necessarily need a server. It could run on a container run time PAAS like fly.io)

  • One extra security layer - if there's a vulnerability in Django, attackers are straight into the host OS, not just the container under the non-root user django. I would not assume a container is bullet proof, but it does raise the cost to an attacker.

  • The docker network is a little nicer to work with than localhost ports, and avoids having to double check the ports of services running at OS level, against the firewall and network table.

  • Easily upgrade or switch Python versions.

Plus others that don't immediately spring to mind.

@foarsitter foarsitter changed the title Hybrid development Hybrid local development Jan 29, 2024
@foarsitter
Copy link
Collaborator Author

My proposal is to use a local interpreter for development instead of the containerized one. So the production environment wouldn't change.

Your bullets are valid points and should left untouched. The only change I'm proposing is to use a system interpreter so tests are running faster :)

@JamesParrott
Copy link

JamesParrott commented Jan 29, 2024

The tests will indeed run faster, which would be nice I agree. Is there a second route to running the tests directly in the repo, or can they be reorganised?

But the subset of tests that can run locally outside a container, will not definitively test any interaction with the container, which is what will actually be deployed. So it could lead to false confidence, or late discovery of bugs.

@foarsitter
Copy link
Collaborator Author

Is there a second route to running the tests directly in the repo, or can they be reorganised?

What are you thinking of?

In my thinking it is straightforward: an interpreter is juist interacting with services. Where those services are living isn't important as long as they available through the network. The docker layer gives me a performance penalty when I'm running tests, so I can better remove it and enjoy an improved DX.

Theoretically this can lead to false confidence or late discovery of bugs, especially when you are developing under windows or osx. But these issues will popup in the pipeline or on the staging/test environment.

@browniebroke
Copy link
Member

That's an approach I saw some colleagues use in a previous project, but I never been too bothered with the Docker overhead myself to use it, it's a price I don't mind paying for the benefit of reproducibility. The way we did it was to have both Docker and Hybrid side by side and each developer on project was free to choose the way they wanted. Was useful to keep Docker around in case of tricky bug where an env closer to prod was needed.

Question for you is how do you usually run Celery in this context? Do you start another process on your host machine or do you keep Celery containerized?

@browniebroke
Copy link
Member

That would be a perfect opportnuity to trim out some of the hacks in cookiecutter-django too (like the non-standard directory structure, copying everything in the repo into the node container right at the start of the Django dockerfile meaning the docker cache is hardly ever useful, and the python script in a string inside a bash script, that waits for a postgres connection).

@JamesParrott I think we have a few issues tracking some of these:

However, I don't see what you mean about "copying everything in the repo into the node container right at the start of the Django dockerfile meaning the docker cache is hardly ever useful", could you point us at the problem in a new issue please? It would be good to tackle that here, we don't need a fork 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants