How to Add host_name in site_config.json for Frappe in Docker Container?

Hi everyone,

I’m working on a Google Drive integration with Frappe in a Dockerized setup. During the OAuth process, I need to set a host_name in site_config.json so that I can properly handle the redirect URL. However, I’m having trouble getting it to persist or reflect correctly. Here’s what I’ve tried so far:

  1. Adding host_name after container startup:
  • I used the bench command while the container was running to set the config:
bench --site example7.com set-config host_name https://example7.com
  • I faced the redirect issue, but the site_config.json file is updated.
  1. Docker up/down attempts:
  • I tried bringing the container down and back up after doing above, but the changes still weren’t reflected.
  1. Attempting during the Docker build process:
  • Now, I’m thinking about setting the host_name during the Docker build phase. Here’s the section in my custom Docker Containerfile where I tried adding the configuration:

dockerfile

Copy code

RUN export APP_INSTALL_ARGS="" && \
    if [ -n "${APPS_JSON_BASE64}" ]; then \
        export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json"; \
    fi && \
    bench init ${APP_INSTALL_ARGS} \
        --frappe-branch=${FRAPPE_BRANCH} \
        --frappe-path=${FRAPPE_PATH} \
        --no-procfile \
        --no-backups \
        --skip-redis-config-generation \
        /home/frappe/frappe-bench && \
    cd /home/frappe/frappe-bench && \
    echo "{}" > sites/common_site_config.json && \
    if [ -d "sites" ]; then \
        bench --site example7.com set-config host_name https://example7.com; \
    else \
        echo "sites directory missing!"; \
        exit 1; \
    fi && \
    find apps -mindepth 1 -path "*/.git" | xargs rm -fr
  • When I build and run the container, I receive an error saying “site name is not set yet” during the bench command execution.

how to resolve this. any other way to add this

Steps to Set Up Google Drive Backup with Ngrok for Local System Testing

Here’s a detailed guide to configure Google Drive backup using Ngrok for a local Frappe/ERPNext site:


1. Start Ngrok Service

Run the following command to expose your local development server to the internet using Ngrok:

ngrok http 8000 --host-header=one.localhost

Replace one.localhost with your local site name if it’s different.

Example Ngrok URL: https://25a1-43-254-176-144.ngrok-free.app


2. Update Site Configuration

  • Update site_config.json:
    Open the site_config.json file for your one.localhost site and replace the host_name with the generated Ngrok URL:

    {
      "host_name": "https://25a1-43-254-176-144.ngrok-free.app",
      ...
    }
    
  • Update common_site_config.json:
    Change the webserver_port value from 8000 to 443 to match the Ngrok HTTPS configuration:

    {
      "webserver_port": 443,
      ...
    }
    

3. Configure Google API Settings

In your Google Cloud Console, create a project (or use an existing one) and set up the following:

  • Client ID: Your Google OAuth client ID.
  • Client Secret: Your Google OAuth client secret.
  • API Key and App ID: Obtain these from the Google API dashboard.

4. Set Authorized URLs in Google App

Configure the OAuth credentials with the following values:

  • Authorized JavaScript Origins:
    Add the Ngrok URL:

    https://25a1-43-254-176-144.ngrok-free.app
    
  • Authorized Redirect URIs:
    Add the callback URL for Google OAuth in Frappe:

    https://25a1-43-254-176-144.ngrok-free.app:443/api/method/frappe.integrations.google_oauth.callback
    

5. Set Up Google Drive in Frappe

  • Go to the Google Drive settings in Frappe.
  • Authorize Google Drive access by clicking the authorization button in the Google Drive Doctype.

6. Authorize and Test Backup

  • After successful authorization, your site will be able to back up files to Google Drive automatically.
  • Verify the setup by creating a manual backup and ensuring it’s uploaded to Google Drive.
1 Like

Thank you @nirav

During build no site exists. You need to add it at runtime not during build.

Thank you @revant_one. It’s fixed now.