Support for reading Mariadb and Admin password from file when using docker secrets
With this PR, password can be read from docker secrets in both compose as well as swarm environment.
```YAML
secrets:
mariadb-root-password:
file: mariadb-root-password.txt
erpnext-admin-password:
file: erpnext-admin-password.txt
services:
erpnext:
image: frappe/erpnext-worker:${ERPNEXT_VERSION:-v12.5.2}
environment:
- SITE_NAME=example.com
- DB_ROOT_USER=root
- MARIADB_HOST=mariadb
- INSTALL_APPS=erpnext
- FORCE=1
- REDIS_CACHE=redis-cache:6379
- REDIS_QUEUE=redis-queue:6379
- REDIS_SOCKETIO=redis-socketio:6379
- SOCKETIO_PORT=9000
- AUTO_MIGRATE=1
- ADMIN_PASSWORD_FILE=/run/secrets/erpnext-admin-password
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mariadb-root-password
secrets:
- erpnext-admin-password
- mariadb-root-password
restart: on-failure
volumes:
- erpnext-data:/home/frappe/frappe-bench/sites
- assets-data:/home/frappe/frappe-bench/sites/assets
links:
- redis-cache
- redis-queue
- redis-socketio
- mariadb
depends_on:
- mariadb
- redis-cache
- redis-queue
- redis-socketio
networks:
- erpnext-net
```
Reference: [Addind docker secrets in to your images](https://docs.docker.com/engine/swarm/secrets/#build-support-for-docker-secrets-into-your-images)
Changes to be committed:
modified: ../../README.md
modified: ../common/commands/new.py
modified: ../common/commands/restore_backup.py
modified: ../erpnext-nginx/docker-entrypoint.sh
This commit is contained in:
@@ -5,6 +5,7 @@ import hashlib
|
||||
import frappe
|
||||
import boto3
|
||||
|
||||
from new import get_password
|
||||
from push_backup import DATE_FORMAT, check_environment_variables
|
||||
from frappe.utils import get_sites, random_string
|
||||
from frappe.commands.site import _new_site
|
||||
@@ -38,7 +39,7 @@ def decompress_db(files_base, site):
|
||||
os.system(command)
|
||||
|
||||
def restore_database(files_base, site):
|
||||
db_root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
|
||||
db_root_password = get_password('MYSQL_ROOT_PASSWORD')
|
||||
if not db_root_password:
|
||||
print('Variable MYSQL_ROOT_PASSWORD not set')
|
||||
exit(1)
|
||||
@@ -158,7 +159,7 @@ def main():
|
||||
restore_private_files(files_base)
|
||||
restore_files(files_base)
|
||||
else:
|
||||
mariadb_root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
|
||||
mariadb_root_password = get_password('MYSQL_ROOT_PASSWORD')
|
||||
if not mariadb_root_password:
|
||||
print('Variable MYSQL_ROOT_PASSWORD not set')
|
||||
exit(1)
|
||||
|
||||
Reference in New Issue
Block a user