Skip to content

Commit

Permalink
Merge pull request #202 from rtCamp/develop
Browse files Browse the repository at this point in the history
Bump v0.15.0
  • Loading branch information
Xieyt authored Jun 25, 2024
2 parents 127af3e + 549b8b8 commit 2f2af4e
Show file tree
Hide file tree
Showing 47 changed files with 1,826 additions and 511 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bake-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0

- name: Set up tag
Expand Down
4 changes: 2 additions & 2 deletions Docker/frappe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal
gosu \
fonts-powerline \
zsh \
file \
&& 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 \
Expand Down Expand Up @@ -119,6 +120,7 @@ RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master
RUN unset ZSH

COPY --chown=frappe:frappe ./zshrc /opt/user/.zshrc
COPY --chown=frappe:frappe ./fm.zsh-theme /opt/user/fm.zsh-theme

RUN git clone --depth 1 https://github.com/pyenv/pyenv.git .pyenv \
&& pyenv install $PYTHON_VERSION \
Expand Down Expand Up @@ -161,7 +163,6 @@ COPY --chown=frappe:frappe --chmod=0755 ./bench-wrapper.sh /opt/user/.bin/bench

COPY --chmod=0755 ./prebake.sh /scripts/
COPY --chmod=0755 ./helper-function.sh /scripts/
COPY --chmod=0755 ./divide-supervisor-conf.py /scripts/

RUN ls -lah /workspace && /scripts/prebake.sh && mv /workspace/frappe-bench/apps/* /workspace/

Expand All @@ -181,7 +182,6 @@ RUN mkdir -p /scripts
COPY --chmod=0755 ./entrypoint.sh /
COPY --chmod=0755 ./user-script.sh /scripts/
COPY --chmod=0755 ./launch.sh /scripts/
COPY --chmod=0755 ./divide-supervisor-conf.py /scripts/
COPY --chmod=0755 ./helper-function.sh /scripts/

RUN rm -rf /opt && mkdir -p /workspace /opt
Expand Down
4 changes: 2 additions & 2 deletions Docker/frappe/bench-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
restart_command() {
supervisorctl -c /opt/user/supervisord.conf restart frappe-bench-dev:
supervisorctl -c /opt/user/supervisord.conf restart all
}
status_command() {
supervisorctl -c /opt/user/supervisord.conf status frappe-bench-dev:
supervisorctl -c /opt/user/supervisord.conf status all
}

if [[ "$@" =~ ^restart[[:space:]]* ]]; then
Expand Down
41 changes: 0 additions & 41 deletions Docker/frappe/divide-supervisor-conf.py

This file was deleted.

12 changes: 10 additions & 2 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ update_uid_gid "${USERID}" "${USERGROUP}" "frappe" "frappe"

mkdir -p /opt/user/conf.d

start_time=$(date +%s.%N)
chown -R "$USERID":"$USERGROUP" /opt
end_time=$(date +%s.%N)
execution_time=$(awk "BEGIN {print $end_time - $start_time}")
echo "Time taken for chown /opt : $execution_time seconds"

if [[ ! -d "/workspace/.oh-my-zsh" ]]; then
cp -pr /opt/user/.oh-my-zsh /workspace/
cp -p /opt/user/fm.zsh-theme /workspace/.oh-my-zsh/custom/themes/
fi

if [[ ! -f "/workspace/.zshrc" ]]; then
Expand All @@ -40,9 +45,12 @@ if [[ ! -f "/workspace/.profile" ]]; then
cp -p /opt/user/.profile /workspace/
fi

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

ls -pA /workspace | xargs -I{} chown -R "$USERID":"$USERGROUP" /workspace/{} &
# start_time=$(date +%s.%N)
# chown -R "$USERID":"$USERGROUP" /workspace
# end_time=$(date +%s.%N)
# execution_time=$(awk "BEGIN {print $end_time - $start_time}")
# echo "Time taken for chown /workspace : $execution_time seconds"

if [ "$#" -gt 0 ]; then
gosu "$USERID":"$USERGROUP" "/scripts/$@" &
Expand Down
57 changes: 57 additions & 0 deletions Docker/frappe/fm.zsh-theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Based on gnsh theme

setopt prompt_subst

() {

local PR_USER PR_USER_OP PR_PROMPT PR_HOST

# Check the UID
if [[ $UID -ne 0 ]]; then # normal user
PR_USER='%F{green}%n%f'
PR_USER_OP='%F{green}%#%f'
PR_PROMPT='%f➤ %f'
else # root
PR_USER='%F{red}%n%f'
PR_USER_OP='%F{red}%#%f'
PR_PROMPT='%F{red}➤ %f'
fi

FM_HOST() {
local default_hostname="%${1}"
local common_site_config="/workspace/frappe-bench/sites/common_site_config.json"
if [[ -f "$common_site_config" ]]; then
fm_hostname=$(jq -r .default_site "$common_site_config")
if [[ "$fm_hostname" != "null" ]]; then
echo "$fm_hostname"
else
echo "$default_hostname" # Default to hostname
fi
else
echo "$default_hostname" # Default to hostname
fi
}

# Check if we are on SSH or not
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
PR_HOST='%F{red}$(FM_HOST M)%f' # SSH
else
PR_HOST='%F{green}$(FM_HOST m)%f' # no SSH
fi

local return_code="%(?..%F{red}%? ↵%f)"

local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%~%f%b"
local git_branch='$(git_prompt_info)'

PROMPT="╭─${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
╰─$PR_PROMPT "
RPROMPT="${return_code}"

ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}‹"
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%f"

}
26 changes: 26 additions & 0 deletions Docker/frappe/helper-function.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/usr/bin/bash

# Function: chown directory and files
# Parameters:
# - user
# - group
chown_directory_and_files(){
local user; user="$1"
local group; group="$2"
local dir; dir="$3"

user_not_owned_files=$(find "$dir" ! -user "$user" -type f -exec realpath {} + | sort -u)
group_not_owned_files=$(find "$dir" ! -group "$group" -type f -exec realpath {} + | sort -u)

user_not_owned_dirs=$(find "$dir" ! -user "$user" -type d -exec realpath {} + | sort -u)
group_not_owned_dirs=$(find "$dir" ! -group "$group" -type d -exec realpath {} + | sort -u)

# Concatenate both lists, sort, and remove duplicates
not_owned_files=$(echo -e "$user_not_owned_files\n$group_not_owned_files" | sort -u)
not_owned_dirs=$(echo -e "$user_not_owned_dirs\n$group_not_owned_dirs" | sort -u)

cpu_cores=$(nproc)

echo "$not_owned_files" | xargs -P "$cpu_cores" -I{} bash -c "if [ -f {} ]; then chown ${user}:${group} {};fi"

echo "$not_owned_dirs" | xargs -P "$cpu_cores" -I{} bash -c "if [ -d {} ]; then chown -R ${user}:${group} {};fi"
}

# Function: update_common_site_config
# Description: Updates the common site config file with the provided key-value pair.
# Parameters:
Expand Down
Loading

0 comments on commit 2f2af4e

Please sign in to comment.