Skip to content

Commit 34d790e

Browse files
committed
feat: create site and configure option in erpnext stack
1 parent 8d9b702 commit 34d790e

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

compose/erpnext.yml

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,73 @@ services:
239239
- bench-network
240240
- mariadb-network
241241

242+
configurator:
243+
<<: *custom_image
244+
deploy:
245+
mode: replicated
246+
replicas: ${CONFIGURE:-0}
247+
restart_policy:
248+
condition: none
249+
volumes:
250+
- sites:/home/frappe/frappe-bench/sites
251+
entrypoint: ["bash", "-c"]
252+
command:
253+
- >
254+
bench set-config -g db_host $$DB_HOST;
255+
bench set-config -gp db_port $$DB_PORT;
256+
bench set-config -g redis_cache "redis://$$REDIS_CACHE";
257+
bench set-config -g redis_queue "redis://$$REDIS_QUEUE";
258+
bench set-config -g redis_socketio "redis://$$REDIS_SOCKETIO";
259+
bench set-config -gp socketio_port $$SOCKETIO_PORT;
260+
environment:
261+
DB_HOST: ${DB_HOST:-mariadb_db}
262+
DB_PORT: ${DB_PORT:-3306}
263+
REDIS_CACHE: redis-cache:6379
264+
REDIS_QUEUE: redis-queue:6379
265+
REDIS_SOCKETIO: redis-socketio:6379
266+
SOCKETIO_PORT: 9000
267+
268+
create-site:
269+
<<: *custom_image
270+
deploy:
271+
mode: replicated
272+
replicas: ${CREATE_SITE:-0}
273+
restart_policy:
274+
condition: none
275+
entrypoint: ["bash", "-c"]
276+
command:
277+
- >
278+
wait-for-it -t 120 $$DB_HOST:$$DB_PORT;
279+
wait-for-it -t 120 redis-cache:6379;
280+
wait-for-it -t 120 redis-queue:6379;
281+
export start=`date +%s`;
282+
until [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".db_host // empty"` ]] && \
283+
[[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_cache // empty"` ]] && \
284+
[[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_queue // empty"` ]];
285+
do
286+
echo "Waiting for sites/common_site_config.json to be created";
287+
sleep 5;
288+
if (( `date +%s`-start > 120 )); then
289+
echo "could not find sites/common_site_config.json with required keys";
290+
exit 1
291+
fi
292+
done;
293+
echo "sites/common_site_config.json found";
294+
[[ -d "sites/${SITE_NAME}" ]] && echo "${SITE_NAME} already exists" && exit 0;
295+
bench new-site --mariadb-user-host-login-scope='%' --admin-password=$${ADMIN_PASSWORD} --db-root-username=root --db-root-password=$${DB_ROOT_PASSWORD} $${INSTALL_APP_ARGS} $${SITE_NAME};
296+
volumes:
297+
- sites:/home/frappe/frappe-bench/sites
298+
environment:
299+
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
300+
DB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
301+
INSTALL_APP_ARGS: ${INSTALL_APP_ARGS}
302+
SITE_NAME: ${SITE_NAME}
303+
networks:
304+
- bench-network
305+
- mariadb-network
306+
242307
redis-cache:
243-
image: redis:6.2-alpine
308+
image: redis:7-alpine
244309
deploy:
245310
restart_policy:
246311
condition: on-failure
@@ -256,7 +321,7 @@ services:
256321
retries: 3
257322

258323
redis-queue:
259-
image: redis:6.2-alpine
324+
image: redis:7-alpine
260325
deploy:
261326
restart_policy:
262327
condition: on-failure
@@ -274,7 +339,7 @@ services:
274339
retries: 3
275340

276341
redis-socketio:
277-
image: redis:6.2-alpine
342+
image: redis:7-alpine
278343
deploy:
279344
restart_policy:
280345
condition: on-failure
@@ -322,6 +387,8 @@ networks:
322387
# BENCH_NAME | Name of the bench newtork | erpnext
323388
# IMAGE_NAME | Container image to use | docker.io/frappe/erpnext
324389
# MIGRATE | Enable migration on deploy | 1
390+
# CONFIGURE | Re-generate common_site_config.json | 0
391+
# CREATE_SITE | Enable site creation on deploy | 0
325392
# RESTIC_PASSWORD | Restic Password. DO NOT Forget! | nil
326393
# RESTIC_REPOSITORY | Path Styled S3 endpoint | nil
327394
# SITES | Mandatory List of sites as back | nil

0 commit comments

Comments
 (0)