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

Muti bench instances run simultaneously, Custom Queues, Supervisor Integration, Improved User Experience, and Optimizations #91

Merged
merged 100 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
454c726
remove zombie subprocess processes
Xieyt Jan 5, 2024
4ade60c
notify user for to update
Xieyt Jan 5, 2024
866701d
fix: docker on detection
Xieyt Jan 5, 2024
a84694d
fix: log and shell command when using --service
Xieyt Jan 5, 2024
cb31f2b
check site after creation
Xieyt Jan 8, 2024
edb3472
fix: shell,logs command --service flag
Xieyt Jan 8, 2024
49dc657
docker group checking when daemon is not running
Xieyt Jan 8, 2024
2cd6f54
add and optmize helper functions
Xieyt Jan 8, 2024
b984427
refractor: compose file managment
Xieyt Jan 8, 2024
a689604
move ComposeFile default templates dir.
Xieyt Jan 8, 2024
4cab059
refractor: logic to check site status
Xieyt Jan 8, 2024
daa4864
refractor: site.py
Xieyt Jan 8, 2024
3494c09
add func get_container_hex in utils
Xieyt Jan 8, 2024
65a9b48
chore: format
Xieyt Jan 8, 2024
06be7bc
move check_ports functions
Xieyt Jan 8, 2024
2c03053
optimize ports checking
Xieyt Jan 8, 2024
cd3fb66
chore: format code
Xieyt Jan 8, 2024
9abc7a0
Optimize shell and logs commands
Xieyt Jan 8, 2024
bc30d1b
add docker run,rm and cp command funcetions
Xieyt Jan 8, 2024
5b9153c
fix: docker compose up,restart and exec commands
Xieyt Jan 8, 2024
b409d42
supervisor.conf for running different services
Xieyt Jan 8, 2024
8a4fee9
feat: dynamic workers
Xieyt Jan 8, 2024
4708ee2
Optmize site creation logic
Xieyt Jan 8, 2024
882ef60
update: logs changes with new dev server run method using supervisor
Xieyt Jan 8, 2024
cd02f24
add util function docker_host_cp
Xieyt Jan 8, 2024
13916a0
chore: format code
Xieyt Jan 8, 2024
2ba885d
functions for managingin user and tol level networks attribute names
Xieyt Jan 8, 2024
67a8a91
richprint.error support extra error msg printing
Xieyt Jan 8, 2024
0a72bb9
remove ssl support from nginx
Xieyt Jan 8, 2024
210b45d
chore: format code
Xieyt Jan 8, 2024
a848587
detect keyboard interrupt when loggging
Xieyt Jan 8, 2024
d4e59b4
optmize: compose file migration
Xieyt Jan 8, 2024
18958ee
don't invoke fm when help msg
Xieyt Jan 8, 2024
8d0b45b
enhancement: site services status in fm info command
Xieyt Jan 8, 2024
cb91073
revamp fm list command
Xieyt Jan 8, 2024
98f9c21
exception handling in fm logs command
Xieyt Jan 8, 2024
9ea50d6
move Richprint to dedicated DisplayManager module
Xieyt Jan 8, 2024
832803d
more detail
Xieyt Jan 8, 2024
3d6dcc4
show error msg when exit in this function
Xieyt Jan 8, 2024
b5a7760
chore: clean code
Xieyt Jan 8, 2024
b1089e1
dep change pyyaml to ruamel.yaml
Xieyt Jan 8, 2024
fe2a579
update images tags to v0.10.0
Xieyt Jan 8, 2024
ff94721
add owrker service status info in fm info command
Xieyt Jan 8, 2024
9fc1939
add __init__.py to workers_manager
Xieyt Jan 8, 2024
f9371b9
update docker imag tag
Xieyt Jan 8, 2024
58de7c9
create symlink for old frappe dev server log
Xieyt Jan 8, 2024
286a8aa
fix dynamic worker generation
Xieyt Jan 9, 2024
d41a13f
stop extra_hosts setup in workers compose
Xieyt Jan 9, 2024
4885fe1
don't log when help is called
Xieyt Jan 9, 2024
4775be5
update: docker group not found status msg
Xieyt Jan 9, 2024
8b50cf9
fix: running services detection
Xieyt Jan 9, 2024
d0957e4
site compose convert null to empty string
Xieyt Jan 9, 2024
ba10863
fix: fm info generate workers info
Xieyt Jan 9, 2024
958e310
fix: fm info not showing anything when workers not available
Xieyt Jan 9, 2024
04915d1
fix: alignment
Xieyt Jan 9, 2024
b20e358
fix: wrong parameter
Xieyt Jan 9, 2024
8f6ea18
add supervisor config regeneration function
Xieyt Jan 9, 2024
bf5566c
fix: workers are not getting created when the site is migrated
Xieyt Jan 9, 2024
52cf000
fix: migrate compose set ENVRONMENT to dev
Xieyt Jan 9, 2024
6da60bf
default dev env when compose migrate
Xieyt Jan 9, 2024
bf464c3
chore: typo
Xieyt Jan 9, 2024
6585cce
add more env for frappe container in migrate
Xieyt Jan 9, 2024
44bcc59
set VIRTUAL_HOST in nginx in migrate
Xieyt Jan 9, 2024
1e2cb82
add: param status_msg
Xieyt Jan 9, 2024
c3690e4
add status when starting site
Xieyt Jan 9, 2024
e48ab9d
symlink for bench-start.log
Xieyt Jan 9, 2024
8327dfa
fix: compose file migration
Xieyt Jan 9, 2024
2257e78
fix: getting docker port binds
Xieyt Jan 10, 2024
d7ed47a
add: missing containers from enum
Xieyt Jan 10, 2024
b44c13c
fix: symlink bench-start.log with web.dev.log
Xieyt Jan 11, 2024
b63bc64
fix: bench restart in frappe container
Xieyt Jan 11, 2024
34aa6e4
fix: typo
Xieyt Jan 11, 2024
b2d8293
update supervisord log location and optmizations
Xieyt Jan 11, 2024
2efb8e6
force common_site_config update on each start
Xieyt Jan 11, 2024
19179c8
fix: workers not starting
Xieyt Jan 11, 2024
13964be
optimze: chown more faster
Xieyt Jan 11, 2024
4a62124
fix: chown only when site is being created
Xieyt Jan 12, 2024
9b5c973
fix: workers generation in migration
Xieyt Jan 12, 2024
b45e4bd
Move templates and utils
Xieyt Jan 31, 2024
7f3811d
feat: global services
Xieyt Jan 31, 2024
416aff6
optimize frappe docker image
Xieyt Jan 31, 2024
ed5a21e
fix docker compose file formatting
Xieyt Jan 31, 2024
7db9ca8
refractor main.py to split commands
Xieyt Jan 31, 2024
db788d2
optmize docker wrapper
Xieyt Jan 31, 2024
62916b7
feat: migration module for handling migrations
Xieyt Jan 31, 2024
3381a25
misc: poetry inproject venv
Xieyt Jan 31, 2024
04842db
bump: v0.10.0
Xieyt Jan 31, 2024
c93bdc9
fix bench restart in frappe container
Xieyt Jan 31, 2024
fdeb3a8
turn off fm pypi update check
Xieyt Jan 31, 2024
d04faa4
services rollback if failure
Xieyt Jan 31, 2024
57b0670
emoji change for service runnning status
Xieyt Jan 31, 2024
e7ce5c8
fix services not working in linux
Xieyt Jan 31, 2024
fe5b322
fix: after migration choose archive, version update
Xieyt Feb 1, 2024
ec74dad
fix: services not starting in osx
Xieyt Feb 1, 2024
9ba59ca
add logs for site start in fm create command
Xieyt Feb 1, 2024
c034b35
add ask for migration prompt
Xieyt Feb 5, 2024
8c90508
remove commands hints
Xieyt Feb 5, 2024
542e1ad
enable restart always on all sites
Xieyt Feb 5, 2024
5e98765
more info for user when migration
Xieyt Feb 5, 2024
41a8db4
update create command to include template flag
Xieyt Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
TAG='v0.9.0'
TAG='v0.10.0'
ARCH=$(uname -m)

# arm64
Expand Down
26 changes: 14 additions & 12 deletions Docker/frappe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal
jq \
gosu \
fonts-powerline \
zsh

#&& rm -rf /var/lib/apt/lists/*
zsh \
&& rm -rf /var/lib/apt/lists/*

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales
Expand Down Expand Up @@ -112,11 +111,7 @@ RUN git clone --depth 1 https://github.com/pyenv/pyenv.git .pyenv \
&& pyenv global $PYTHON_VERSION \
&& echo 'export PYENV_ROOT="/opt/.pyenv"' >> "$USERZSHRC" \
&& echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> "$USERZSHRC" \
&& echo 'eval "$(pyenv init -)"' >>"$USERZSHRC"

#&& echo 'eval "$(pyenv init -)"' >>"$USERPROFILE"
#&& sed -Ei -e '/^([^#]|$)/ {a export PYENV_ROOT="/opt/.pyenv" a export PATH="$PYENV_ROOT/bin:$PATH" a ' -e ':a' -e '$!{n;ba};}' "$USERPROFILE" \
#&& echo 'eval "$(pyenv init --path)"' >>"$USERPROFILE" \
&& echo 'eval "$(pyenv init --path)"' >>"$USERZSHRC"

RUN pip install frappe-bench

Expand All @@ -138,21 +133,28 @@ RUN mkdir -p /opt/.nvm \
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >> "$USERZSHRC" \
&& echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$USERZSHRC"


RUN mkdir -p /workspace

WORKDIR /workspace

RUN mkdir -p /opt/user/.bin
ENV PATH /opt/user/.bin:${PATH}

RUN echo PATH='/opt/user/.bin:$PATH' >> "$USERZSHRC"
RUN echo 'export PATH="/opt/user/.bin:$PATH"' >> "$USERZSHRC"

COPY ./supervisord.conf /opt/user/
COPY ./bench-start.sh /opt/user/
COPY ./bench-dev-server /opt/user/
COPY ./frappe-dev.conf /opt/user/
COPY ./bench-wrapper.sh /opt/user/.bin/bench

COPY ./entrypoint.sh /
COPY ./user-script.sh /
COPY ./user-script.sh /scripts/
COPY ./launch.sh /scripts/
COPY ./divide-supervisor-conf.py /scripts/

RUN mkdir -p /scripts

RUN sudo chmod +x /entrypoint.sh /user-script.sh /opt/user/bench-start.sh /opt/user/.bin/bench
RUN sudo chmod +x /entrypoint.sh /scripts/user-script.sh /scripts/launch.sh /scripts/divide-supervisor-conf.py /opt/user/bench-dev-server /opt/user/.bin/bench

ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
3 changes: 3 additions & 0 deletions Docker/frappe/bench-dev-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
fuser -k 80/tcp
bench serve --port 80
4 changes: 0 additions & 4 deletions Docker/frappe/bench-start.sh

This file was deleted.

2 changes: 1 addition & 1 deletion Docker/frappe/bench-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
after_command() {
supervisorctl -c /opt/user/supervisord.conf restart bench-dev
supervisorctl -c /opt/user/supervisord.conf restart frappe-bench-dev:
}
if [[ "$@" =~ ^restart[[:space:]]* ]]; then
after_command
Expand Down
41 changes: 41 additions & 0 deletions Docker/frappe/divide-supervisor-conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import sys
import configparser
from pathlib import Path

print(sys.argv)
conf_file_path= Path(sys.argv[1])
conf_file_absolute_path = conf_file_path.absolute()

if not len(sys.argv) == 2:
print(f"Generates individual program conf from supervisor.conf.\nUSAGE: {sys.argv[0]} SUPERVISOR_CONF_PATH\n\n SUPERVISOR_CONF_PATH -> Absolute path to supervisor.conf")
sys.exit(0)

config = configparser.ConfigParser(allow_no_value=True,strict=False,interpolation=None)

superconf = open(conf_file_absolute_path,'r+')

config.read_file(superconf)

print(f"Divided {conf_file_absolute_path} into ")

for section_name in config.sections():
if not 'group:' in section_name:

section_config = configparser.ConfigParser(interpolation=None)
section_config.add_section(section_name)
for key, value in config.items(section_name):
if 'frappe-bench-frappe-web' in section_name:
if key == 'command':
value = value.replace("127.0.0.1:80","0.0.0.0:80")
section_config.set(section_name, key, value)

if 'worker' in section_name:
file_name = f"{section_name.replace('program:','')}.workers.fm.supervisor.conf"
else:
file_name = f"{section_name.replace('program:','')}.fm.supervisor.conf"

with open(conf_file_path.parent / file_name, 'w') as section_file:
section_config.write(section_file)
print(f" - {section_name} => {file_name}")
20 changes: 18 additions & 2 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

emer() {
echo "$1"
exit 1
Expand All @@ -15,17 +16,32 @@ useradd --no-log-init -r -m -u "$USERID" -g "$USERGROUP" -G sudo -s /usr/bin/zsh
usermod -a -G tty "$NAME"
echo "$NAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

mkdir -p /opt/user/conf.d

chown -R "$USERID":"$USERGROUP" /opt

if [[ ! -d "/workspace/.oh-my-zsh" ]]; then
cp -r /opt/user/.oh-my-zsh /workspace/.oh-my-zsh
fi

if [[ ! -f "/workspace/.zshrc" ]]; then
cat /opt/user/.zshrc > /workspace/.zshrc
fi

if [[ ! -f "/workspace/.profile" ]]; then
cat /opt/user/.profile > /workspace/.profile
fi

chown -R "$USERID":"$USERGROUP" /workspace
gosu "${USERID}":"${USERGROUP}" /user-script.sh

if [[ ! -d '/workspace/frappe-bench' ]]; then
chown -R "$USERID":"$USERGROUP" /workspace
# find /workspace -type d -print0 | xargs -0 -n 200 -P "$(nproc)" chown "$USERID":"$USERGROUP"
# find /workspace -type f -print0 | xargs -0 -n 200 -P "$(nproc)" chown "$USERID":"$USERGROUP"
fi


if [ "$#" -gt 0 ]; then
gosu "$USERID":"$USERGROUP" "/scripts/$@"
else
gosu "${USERID}":"${USERGROUP}" /scripts/user-script.sh
fi
22 changes: 22 additions & 0 deletions Docker/frappe/frappe-dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[program:frappe-bench-frappe-dev]
command=/opt/user/bench-dev-server.sh
priority=4
autostart=true
autorestart=false
stdout_logfile=/workspace/frappe-bench/logs/web.dev.log
redirect_stderr=true
user=frappe
directory=/workspace/frappe-bench

[program:frappe-bench-frappe-watch]
command=bench watch
priority=4
autostart=true
autorestart=false
stdout_logfile=/workspace/frappe-bench/logs/watch.dev.log
redirect_stderr=true
user=frappe
directory=/workspace/frappe-bench

[group:frappe-bench-dev]
programs=frappe-bench-frappe-dev,frappe-bench-frappe-watch
61 changes: 61 additions & 0 deletions Docker/frappe/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/zsh
emer() {
echo "$1"
exit 1
}

[[ "${WAIT_FOR:-}" ]] || emer "The WAIT_FOR env is not given."
[[ "${COMMAND:-}" ]] || emer "COMMAND is not given."

if [[ ! "${TIMEOUT:-}" ]]; then
TIMEOUT=300
fi
if [[ ! "${CHECK_ITERATION:-}" ]]; then
CHECK_ITERATION=10
fi

file_to_check="${WAIT_FOR}"

timeout_seconds="$TIMEOUT"

start_time=$(date +%s)
check_iteration="$CHECK_ITERATION"

total_iteration=1
iteration=1
IFS=',' read -A files <<< "$file_to_check"
while true; do
all_files_exist=true

for file in ${files[@]}; do
if [[ ! -s "$file" ]]; then
all_files_exist=false
break
fi
done

if $all_files_exist || [[ $(( $(date +%s) - start_time )) -ge "$timeout_seconds" ]]; then
break
fi

sleep 1
((total_iteration++))
((iteration++))
if [ $((iteration % check_iteration)) -eq 0 ]; then
echo "Checked $iteration times..."
fi
done

if [[ "${CHANGE_DIR:-}" ]];then
cd "$CHANGE_DIR" || true
fi

source /opt/user/.zshrc

if $all_files_exist; then
echo "$file_to_check populated within $total_iteration seconds."
echo "Running Command: $COMMAND"
eval "$COMMAND"
else
echo "$file_to_check did not populate within $timeout_seconds seconds. Giving Up"
fi
24 changes: 4 additions & 20 deletions Docker/frappe/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,11 @@ serverurl = unix:///opt/user/supervisor.sock

[supervisord]
nodaemon = true
logfile=/tmp/supervisord.log
pidfile=/tmp/supervisord.pid
logfile=/workspace/frappe-bench/logs/supervisord.log
pidfile=/workspace/frappe-bench/logs/supervisord.pid

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

# [program:taill]
# command =/usr/bin/tail -f /opt/user/bench-start.log
# stdout_logfile = /dev/stdout
# stderr_logfile = /dev/stdout
# stdout_logfile_maxbytes = 0
# stderr_logfile_maxbytes = 0
# autostart=true

[program:bench-dev]
command = /opt/user/bench-start.sh
stdout_logfile = /workspace/logs/bench-start.log
redirect_stderr = true
user = frappe
startsecs = 4
killasgroup = true
stopasgroup= true
autostart = true
directory = /workspace/frappe-bench
[include]
files = /opt/user/conf.d/*.conf
Loading