frappe / bench

CLI to manage Multi-tenant deployments for Frappe apps
https://frappeframework.com/docs/user/en/bench
GNU General Public License v3.0
1.37k stars 1.2k forks source link

Silent confirmation (-y) for bench install-app command #1560

Open simwai opened 4 months ago

simwai commented 4 months ago

Issue: Feature Request

Is your feature request related to a problem? Please describe. I'm always frustrated when I try to install ecommerce_integrations in the pwd.yml file of the frappe_docker repo and bench has no option for silent confirmation (-y) when I need to run these steps.

$ bench get-app ecommerce_integrations --branch main $ bench --site sitename install-app ecommerce_integrations (Here, it is necessary to confirm manually multiple questions sometimes.)

Describe the solution you'd like A parameter -y to confirm all questions which could appear on the bench install-app command

Describe alternatives you've considered I tried out about 3 different variants to find a workaround, but gave up in the end. I tried expect, yes | command and EOF, but it all didn't help me out.

ankush commented 4 months ago

Here, it is necessary to confirm manually multiple questions sometimes.

What questions? I can't find any in install_app function call.

If it was interactive https://frappecloud.com won't work too. It just issues simple install-app

https://github.com/frappe/agent/blob/2c926d8062d5867d8874f95e2f228f14974f8f4b/agent/site.py#L90-L93

simwai commented 4 months ago

I don't get exactly why you reference to frappecloud. The questions are like if I would like to override current installation.

simwai commented 4 months ago

Here you can see how a docker compose -f pwd.yml up fails, because of the question.

[+] Running 11/0
 ✔ Container frappe_docker-redis-cache-1   Running                                                                                              0.0s
 ✔ Container frappe_docker-scheduler-1     Running                                                                                              0.0s
 ✔ Container frappe_docker-redis-queue-1   Running                                                                                              0.0s
 ✔ Container frappe_docker-queue-short-1   Running                                                                                              0.0s
 ✔ Container frappe_docker-queue-long-1    Running                                                                                              0.0s
 ✔ Container frappe_docker-websocket-1     Running                                                                                              0.0s
 ✔ Container frappe_docker-configurator-1  Created                                                                                              0.0s
 ✔ Container frappe_docker-db-1            Running                                                                                              0.0s
 ✔ Container frappe_docker_frontend_1      Recreated                                                                                            0.0s
 ✔ Container frappe_docker_backend_1       Recreated                                                                                            0.0s
 ✔ Container frappe_docker-create-site-1   Created                                                                                              0.0s
Attaching to backend-1, configurator-1, create-site-1, db-1, frontend-1, queue-long-1, queue-short-1, redis-cache-1, redis-queue-1, scheduler-1, websocket-1
create-site-1   | wait-for-it: waiting 120 seconds for db:3306
db-1            | 2024-05-23 15:36:09 348 [Warning] Aborted connection 348 to db: 'unconnected' user: 'unauthenticated' host: '172.26.0.6' (This connection closed normally without authentication)
create-site-1   | wait-for-it: db:3306 is available after 0 seconds
create-site-1   | wait-for-it: waiting 120 seconds for redis-cache:6379
create-site-1   | wait-for-it: redis-cache:6379 is available after 0 seconds
create-site-1   | wait-for-it: waiting 120 seconds for redis-queue:6379
create-site-1   | wait-for-it: redis-queue:6379 is available after 0 seconds
create-site-1   | sites/common_site_config.json found
create-site-1   | Site frontend already exists
create-site-1   | Aborted!
backend-1       | [2024-05-23 15:36:11 +0000] [1] [INFO] Starting gunicorn 22.0.0
backend-1       | [2024-05-23 15:36:11 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
backend-1       | [2024-05-23 15:36:11 +0000] [1] [INFO] Using worker: gthread
backend-1       | [2024-05-23 15:36:11 +0000] [6] [INFO] Booting worker with pid: 6
backend-1       | [2024-05-23 15:36:11 +0000] [7] [INFO] Booting worker with pid: 7
create-site-1   | A directory for the application 'ecommerce_integrations' already exists. Do you want to continue and overwrite it? [y/N]: An error occurred while installing ecommerce_integrations: App ecommerce_integrations not in apps.txt
  create-site:
    image: frappe/erpnext:v15.25.0
    deploy:
      restart_policy:
        condition: none
    volumes:
      - sites:/home/frappe/frappe-bench/sites
      - logs:/home/frappe/frappe-bench/logs
    entrypoint:
      - bash
      - -c
    command:
      - >
        wait-for-it -t 120 db:3306;
        wait-for-it -t 120 redis-cache:6379;
        wait-for-it -t 120 redis-queue:6379;
        export start=`date +%s`;
        until [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".db_host // empty"` ]] && \
          [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_cache // empty"` ]] && \
          [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_queue // empty"` ]];
        do
          echo "Waiting for sites/common_site_config.json to be created";
          sleep 5;
          if (( `date +%s`-start > 120 )); then
            echo "could not find sites/common_site_config.json with required keys";
            exit 1
          fi
        done;
        echo "sites/common_site_config.json found";
        bench new-site --no-mariadb-socket --admin-password=admin --db-root-password=admin --install-app erpnext --set-default frontend || true;
        bench get-app ecommerce_integrations --branch main;
        bench --site frontend install-app ecommerce_integrations;
simwai commented 4 months ago

Heyo sry, I am not kinda sure if that happened on the install or the get-app command and I also discovered that I would need to add bench --site frontend migrate; command to the pwd.yml file. Would be awesome if this could be mentioned in the custom apps installation guide, because this is at the moment not very intuitive.