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

Quick Start Full Bench Support Deployment #858

Closed
1ubuntuuser opened this issue Jul 22, 2022 · 19 comments
Closed

Quick Start Full Bench Support Deployment #858

1ubuntuuser opened this issue Jul 22, 2022 · 19 comments

Comments

@1ubuntuuser
Copy link

Is your feature request related to a problem? Please describe.
Not all frappe bench commands work. Currently, the production deployment requires apps to be built into docker images. This slows down the setup and means you can't quickly experiment with different apps in pre-production environment.

Describe the solution you'd like
A halfway point between full static deployment with multiple containers and the development containers stack to be used for testing out different apps and small scale deployments. Once you are happy with your apps and setup, you can choose to build the static frappe docker stack for performance and scale.

Describe alternatives you've considered

  • Running all in one container
  • repeatably rebuilding and deploying the server image for testing apps

Additional context
I'm happy for this to be shot down as a dumb idea. The performance of the development stack might be terrible. I don't know. My use case is I am building a system that initially will only need to support 20-40 users. I want to be able to interatively improve the interface/apps and at some point I want to the option to change over to the static production version to support hopefully many thousands of users. #811 See conversation on this here.

I don't mind the bloated size. It's big, but my alternative to erpnext was a mashup with 5 different apps.

Requirments

  • Very few steps to deployment
  • Documented migration of database and sites
  • Bench command support

##Thoughts, suggestions, ideas?

@1ubuntuuser
Copy link
Author

I can see in V14 modules (Healthcare, Non-profit etc.) are moving to separate apps. The ability to install these apps on the fly will be important I think.
frappe/erpnext#29151

@revant
Copy link
Collaborator

revant commented Jul 22, 2022

I'm not doing this (That means no one else will). You're free to send PR.

What I already do is build staging images just like production images.

  1. I clone custom_frappe_docker as container_images (use .gitlab-ci.yml instead of github actions)
  2. Sometimes this repo has 20+ apps in dockerfile and clone-script for some people!
  3. on build of latest image, I add one job stage to deploy using portainer webhook to update services.
  4. Loop repeats where developers and users interact on dedicated UAT server which gets auto deployed or when:manual depending on case (https://docs.gitlab.com/ee/ci/yaml/#when)
  5. once the UAT image is accepted we bump the tag of the image by editing version.txt and tagged production image is released on to production stack.

Developers use frappe/bench:latest they are free to setup anything on their local devcontainer setup and try out.

I prefer the environments remain same for staging and production. Easier to replicate issues on staging that way.

@1ubuntuuser
Copy link
Author

@revant Thanks for describing in detail what your process is.

I think you're right, it's probably better if staging and production are the same, but not everyone is comfortable with more advanced docker flows as you outlined above. It's just not accessible for most devs; even those who use docker regularly. I'll consider making a PR.

Do you think the development containers stack could handle low traffic in production?

@revant
Copy link
Collaborator

revant commented Jul 26, 2022

Do you think the development containers stack could handle low traffic in production?

refer these templates https://github.com/castlecraft/benchless/tree/master/templates

you'll need to start nginx with supervisor

[program:nginx]
command=nginx -c /etc/nginx/nginx.conf  -g 'daemon off;'
process_name={{ bench_dir }}-nginx
numprocs=1
autostart=true
startsecs=0
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

@revant
Copy link
Collaborator

revant commented Jul 26, 2022

but not everyone is comfortable with more advanced docker flows as you outlined above.

for single developer, "I push to remote, pull from remote to vm" workflow makes sense.

We've multiple devs working on multiple sites and multiple apps, devops is automated by ci/cd to reduce confusion of who updated what last and devs can focus on releasing features multiple times a day than focusing on managing VM.

@1ubuntuuser
Copy link
Author

Yes, that makes sence. I think I will make a PR in the next couple months.

@revant
Copy link
Collaborator

revant commented Aug 2, 2022

I'll close this Issue. Whenever you start the work on PR we can initiate new Issue/PR for discussion.

@1ubuntuuser
Copy link
Author

@revant revant reopened this Oct 11, 2022
@revant
Copy link
Collaborator

revant commented Oct 11, 2022

I made this gist to use development bench for production. You need to additionally install nginx and supervisor.

https://gist.github.com/revant/010c058f7c485cc62f2cc4d604ab8511

If you use it in production and happy with usage, we'll add nginx and supervisor in frappe/bench image.

@1ubuntuuser
Copy link
Author

Thanks for that, I missed your gist. Is the work I did with separating the files still worth while?

Could you explain why Nginx has to run inside the frappe bench container, could it run in it's own container with some shared folders?

@revant
Copy link
Collaborator

revant commented Oct 11, 2022

Thanks for that, I missed your gist. Is the work I did with separating the files still worth while?

if nginx and supervisor runs in Frappe bench container then we can just reuse current devcontainer-example just like mentioned in gist

Could you explain why Nginx has to run inside the frappe bench container, could it run in it's own container with some shared folders?

less containerized setup. more like a vm setup. if you wish to have separate containers use existing stable production setup.

check this to use supervisor to run nginx

https://www.novixys.com/blog/python-web-application-docker-nginx-uwsgi/#6_Supervisor

For TLS certificates and https access to sites under benches some volume mounting and configuration should make the certificates available for use by nginx. Renewal cron job needs to be figured out.

@1ubuntuuser
Copy link
Author

hmmmm I see.. I'll see what I can come up with. As always, thanks for the information.

@1ubuntuuser
Copy link
Author

Still testing with this, so perhaps don't close it yet.

@1ubuntuuser
Copy link
Author

Things where going very well but I've hit a snag with SSL.

I successfully implemented certbot to very easily get ssl certificates generated and put where they belong. Now Nginx was supposed to dish up ssl certifactes based on the hostname, but apparently, it can't do that?

@revant's code kinda indicates it should, but the internet says dynamically loading certificates with host names isn't doable. Am I missing something?
https://github.com/castlecraft/benchless/blob/master/templates/nginx.conf.tmpl

    ssl_certificate      /etc/letsencrypt/live/$http_host/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/$http_host/privkey.pem;

@revant
Copy link
Collaborator

revant commented Nov 6, 2022

I didn't test benchless with ssl.

If we have bench why do we need $http_host we can just use the bench setup nginx and the config generated by it.
It will have everything needed for ssl as well.

@1ubuntuuser
Copy link
Author

1ubuntuuser commented Nov 8, 2022

we can just use the bench setup nginx and the config generated by it.
It will have everything needed for ssl as well.

That's where I started, but the output didn't contain any details regarding SSL so I assumed it wasn't supported. I think maybe I missed that the ssl certificates needs to be added to the site. https://frappeframework.com/docs/v14/user/en/bench/guides/lets-encrypt-ssl-setup

My only hesitation with the auto-created config is it seems to put each site on a different port, is this correct?

@revant
Copy link
Collaborator

revant commented Nov 16, 2022

My only hesitation with the auto-created config is it seems to put each site on a different port, is this correct?

in case of dns multitenant it should create each site with site_name

in case of port based multi tenant site gets created on different port.

refer: https://frappeframework.com/docs/v14/user/en/bench/guides/setup-multitenancy#dns-based-multitenancy

@revant
Copy link
Collaborator

revant commented Dec 21, 2022

https://github.com/castlecraft/frappe_containers

@1ubuntuuser check this.

it's single image that acts as different containers
i mounts VOLUME in build file.

It can be used as immutable container in traditional containerized setup and volume creation/cleanup will be handled by container engine.

check vm-like.compose.yml, it mounts volumes for apps, env, assets and sites, the set of containers act like vm. You enter any container and run full bench commands like get-app or build. only case here is, instead of supervisor you've to restart docker compose

@revant
Copy link
Collaborator

revant commented Dec 23, 2022

#1028

@revant revant closed this as completed Dec 23, 2022
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

2 participants