Skip to content

Commit

Permalink
Merge pull request #105 from rtCamp/develop
Browse files Browse the repository at this point in the history
Bump v0.10.0
  • Loading branch information
Xieyt authored Feb 5, 2024
2 parents 7ce68d7 + cc88869 commit 5ed8d6d
Show file tree
Hide file tree
Showing 61 changed files with 6,094 additions and 2,119 deletions.
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

0 comments on commit 5ed8d6d

Please sign in to comment.