Skip to content

Commit

Permalink
Merge pull request #159 from rtCamp/develop
Browse files Browse the repository at this point in the history
Bump v0.13.0
  • Loading branch information
Xieyt authored Apr 25, 2024
2 parents eed1be5 + 0446836 commit b0270a2
Show file tree
Hide file tree
Showing 73 changed files with 5,734 additions and 2,868 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bake-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0

- name: Set up tag
Expand Down
5 changes: 4 additions & 1 deletion Docker/frappe/bench-dev-server
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
trap "kill -- -$$" EXIT
cleanup (){
kill -s SIGTERM -- -$$
}
trap cleanup SIGQUIT SIGTERM
fuser -k 80/tcp
bench serve --port 80
5 changes: 4 additions & 1 deletion Docker/frappe/bench-dev-watch.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
trap "kill -- -$$" EXIT
cleanup (){
kill -s SIGTERM -- -$$
}
trap cleanup SIGQUIT SIGTERM
bench watch
19 changes: 17 additions & 2 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ emer() {
echo "$1"
exit 1
}
cleanup() {
echo "Received signal, stopping..."
# Insert cleanup code here (e.g., stop services, clean temp files)
if [ -n "$running_script_pid" ]; then
kill -s SIGTERM "$running_script_pid"
fi
exit 0
}

trap cleanup SIGQUIT SIGTERM

[[ "${USERID:-}" ]] || emer "[ERROR] Please provide USERID environment variable."
[[ "${USERGROUP:-}" ]] || emer "[ERROR] Please provide USERGROUP environment variable."
Expand All @@ -31,10 +41,15 @@ if [[ ! -f "/workspace/.profile" ]]; then
fi

chown "$USERID":"$USERGROUP" /workspace /workspace/frappe-bench

ls -pA /workspace | xargs -I{} chown -R "$USERID":"$USERGROUP" /workspace/{} &

if [ "$#" -gt 0 ]; then
gosu "$USERID":"$USERGROUP" "/scripts/$@"
gosu "$USERID":"$USERGROUP" "/scripts/$@" &
running_script_pid=$!
else
gosu "${USERID}":"${USERGROUP}" /scripts/user-script.sh
gosu "${USERID}":"${USERGROUP}" /scripts/user-script.sh &
running_script_pid=$!
fi

wait $running_script_pid
2 changes: 2 additions & 0 deletions Docker/frappe/frappe-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ stdout_logfile=/workspace/frappe-bench/logs/web.dev.log
redirect_stderr=true
user=frappe
directory=/workspace/frappe-bench
stopasgroup=true
stopsignal=QUIT

[program:frappe-bench-frappe-watch]
command=/opt/user/bench-dev-watch.sh
Expand Down
57 changes: 40 additions & 17 deletions Docker/frappe/user-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ source /prebake_info

set -e

cleanup() {
echo "Received signal, performing cleanup..."
# Add any necessary cleanup commands here

# Forward the signal to supervisord (if it's running)
if [ -n "$supervisord_pid" ]; then
kill -s SIGTERM "$supervisord_pid"
fi
exit 0
}

# Trap SIGQUIT, SIGTERM, SIGINT
trap cleanup SIGQUIT SIGTERM

emer() {
echo "$@"
exit 1
Expand All @@ -25,6 +39,10 @@ if [[ ! "${MARIADB_HOST:-}" ]]; then
MARIADB_HOST='global-db'
fi

if [[ "${DEBUG:-}" ]]; then
set -x
fi

if [[ ! "${MARIADB_ROOT_PASS:-}" ]]; then
MARIADB_ROOT_PASS='root'
fi
Expand All @@ -43,13 +61,10 @@ configure_common_site_config() {
update_common_site_config redis_cache "redis://${CONTAINER_NAME_PREFIX}-redis-cache:6379"
update_common_site_config redis_queue "redis://${CONTAINER_NAME_PREFIX}-redis-queue:6379"
update_common_site_config redis_socketio "redis://${CONTAINER_NAME_PREFIX}-redis-socketio:6379"
update_common_site_config mail_port 1025
update_common_site_config mail_server 'mailhog'
update_common_site_config disable_mail_smtp_authentication 1
update_common_site_config webserver_port "$WEB_PORT"
update_common_site_config developer_mode "$DEVELOPER_MODE"
update_common_site_config socketio_port "$REDIS_SOCKETIO_PORT"
update_common_site_config restart_supervisor_on_update 0
update_common_site_config developer_mode "$DEVELOPER_MODE"

# end_time=$(date +%s.%N)
# execution_time=$(awk "BEGIN {print $end_time - $start_time}")
Expand Down Expand Up @@ -90,7 +105,7 @@ if [[ ! -d "/workspace/frappe-bench/sites/$SITENAME" ]]; then
/scripts/divide-supervisor-conf.py config/supervisor.conf

echo "Environment: ${ENVIRONMENT}"
echo "Configuring frappe dev server"
echo "Configuring frappe server"
bench_serve_help_output=$($BENCH_COMMAND serve --help)
host_changed=$(echo "$bench_serve_help_output" | grep -c 'host' || true)

Expand All @@ -101,6 +116,10 @@ if [[ ! -d "/workspace/frappe-bench/sites/$SITENAME" ]]; then
awk -v a="$WEB_PORT" '{sub(/--port [[:digit:]]+/,"--port "a); print}' /opt/user/bench-dev-server >file.tmp && mv file.tmp /opt/user/bench-dev-server.sh
fi

if [[ "$DEVELOPER_MODE" == "true" ]]; then
bench setup requirements --dev
fi

chmod +x /opt/user/bench-dev-server.sh

$BENCH_COMMAND build &
Expand All @@ -119,7 +138,9 @@ if [[ ! -d "/workspace/frappe-bench/sites/$SITENAME" ]]; then
if [[ -n "$BENCH_START_OFF" ]]; then
tail -f /dev/null
else
supervisord -c /opt/user/supervisord.conf
supervisord -c /opt/user/supervisord.conf &
supervisord_pid=$!
wait $supervisord_pid
fi

else
Expand All @@ -140,6 +161,7 @@ else
$BENCH_COMMAND setup supervisor --skip-redis --skip-supervisord --yes --user "$USER"
/scripts/divide-supervisor-conf.py config/supervisor.conf

# Addresses the introduction of the --host flag in bench serve command for compatibility with Frappe version updates.
if [[ "$host_changed" -ge 1 ]]; then
awk -v a="$WEB_PORT" '{sub(/--port [[:digit:]]+/,"--host 0.0.0.0 --port "a); print}' /opt/user/bench-dev-server >file.tmp && mv file.tmp /opt/user/bench-dev-server.sh
else
Expand All @@ -148,23 +170,24 @@ else

chmod +x /opt/user/bench-dev-server.sh

# Addresses the introduction of the --host flag in bench serve command for compatibility with Frappe version updates.
if [[ "${ENVIRONMENT}" = "dev" ]]; then
cp /opt/user/frappe-dev.conf /opt/user/conf.d/frappe-dev.conf
else
if [[ -f '/opt/user/conf.d/frappe-bench-frappe-web.fm.supervisor.conf' ]]; then
# if [[ "${ENVIRONMENT}" = "dev" ]]; then
# cp /opt/user/frappe-dev.conf /opt/user/conf.d/frappe-dev.conf
# else
# if [[ -f '/workspace/frappe-bench/config/frappe-bench-frappe-web.fm.supervisor.conf' ]]; then

ln -sfn /workspace/frappe-bench/config/frappe-bench-frappe-web.fm.supervisor.conf /opt/user/conf.d/frappe-bench-frappe-web.fm.supervisor.conf
else
emer 'Not able to start the server. /opt/user/conf.d/frappe-bench-frappe-web.fm.supervisor.conf not found.'
fi
fi
# ln -sfn /workspace/frappe-bench/config/frappe-bench-frappe-web.fm.supervisor.conf /opt/user/conf.d/frappe-bench-frappe-web.fm.supervisor.conf
# else
# emer 'Not able to start the server. /workspace/frappe-bench/config/frappe-bench-frappe-web.fm.supervisor.conf not found.'
# fi
# fi

if [[ -n "$BENCH_START_OFF" ]]; then
tail -f /dev/null
else
echo "Starting supervisor.."
supervisord -c /opt/user/supervisord.conf
supervisord -c /opt/user/supervisord.conf &
supervisord_pid=$!
wait $supervisord_pid
fi

fi
4 changes: 2 additions & 2 deletions Docker/images-tag.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"frappe": "v0.12.0",
"nginx": "v0.10.0",
"frappe": "v0.13.0",
"nginx": "v0.13.0",
"mailhog": "v0.8.3"
}
1 change: 1 addition & 0 deletions Docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ COPY --from=builder /dist/ /config/
COPY template.conf /config/
COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh
RUN mkdir -p /etc/nginx/custom

ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
16 changes: 11 additions & 5 deletions Docker/nginx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/bash
cleanup() {
echo "Received signal, performing cleanup..."
if [ -n "$nginx_pid" ]; then
kill -s SIGTERM "$nginx_pid"
fi
exit 0
}

# wait for all the programs to load first
echo "Waiting for mailhog adminer to start"
wait-for-it -t 120 mailhog:8025
wait-for-it -t 120 adminer:8080
trap cleanup SIGTERM

/config/jinja2 -D SITENAME="$SITENAME" /config/template.conf > /etc/nginx/conf.d/default.conf

nginx -g 'daemon off;'
nginx -g 'daemon off;' &
nginx_pid=$!
wait $nginx_pid
36 changes: 11 additions & 25 deletions Docker/nginx/template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ upstream frappe-bench-frappe {
upstream frappe-bench-socketio-server {
server socketio:80 fail_timeout=120;
}
upstream mailhog {
server mailhog:8025 fail_timeout=120;
}
upstream adminer {
server adminer:8080 fail_timeout=120;
}
server {

listen 80;
Expand Down Expand Up @@ -80,25 +74,14 @@ server {
proxy_pass http://frappe-bench-frappe;
}

# mailhog
location ^~ /mailhog/ {

chunked_transfer_encoding on;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://mailhog/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
}

# adminer
location ^~ /adminer/ {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://adminer/;
# certbot webroot
location ^~ /.well-known/acme-challenge/ {
auth_basic off;
auth_request off;
allow all;
root /usr/share/nginx/html;
try_files $uri =404;
break;
}

# error pages
Expand Down Expand Up @@ -145,4 +128,7 @@ server {
text/x-component
;
# text/html is always compressed by HttpGzipModule

# include custom config
include /etc/nginx/custom/*.conf;
}
23 changes: 17 additions & 6 deletions frappe_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
# TODO configure this using config
# sites_dir = Path().home() / __name__.split(".")[0]
CLI_DIR = Path.home() / "frappe"
CLI_METADATA_PATH = CLI_DIR / ".fm.toml"
CLI_FM_CONFIG_PATH = CLI_DIR / "fm_config.toml"
CLI_SITES_ARCHIVE = CLI_DIR / "archived"
CLI_LOG_DIRECTORY = CLI_DIR / 'logs'
CLI_SITES_DIRECTORY = CLI_DIR / 'sites'
CLI_BENCHES_DIRECTORY = CLI_DIR / 'sites'
CLI_SERVICES_DIRECTORY = CLI_DIR / 'services'

CLI_SERVICES_NGINX_PROXY_DIR = CLI_SERVICES_DIRECTORY / 'nginx-proxy'
CLI_SERVICES_NGINX_PROXY_SSL_DIR = CLI_SERVICES_NGINX_PROXY_DIR / 'ssl'

CLI_BENCH_CONFIG_FILE_NAME = 'bench_config.toml'
SSL_RENEW_BEFORE_DAYS = 30


DEFAULT_EXTENSIONS = [
Expand All @@ -25,8 +32,6 @@
class SiteServicesEnum(str, Enum):
frappe = "frappe"
nginx = "nginx"
mailhog = "mailhog"
adminer = "adminer"
mariadb = "mariadb"
redis_queue = "redis-queue"
redis_cache = "redis-cache"
Expand All @@ -36,6 +41,12 @@ class SiteServicesEnum(str, Enum):


STABLE_APP_BRANCH_MAPPING_LIST = {
"erpnext" :'version-15',
"hrms" :'version-15',
"frappe": 'version-15',
"erpnext": 'version-15',
"hrms": 'version-15',
}


class EnableDisableOptionsEnum(str, Enum):
enable = 'enable'
disable = 'disable'
Loading

0 comments on commit b0270a2

Please sign in to comment.