Skip to content

Commit

Permalink
Merge pull request #201 from rtCamp/migrate-v-0-15-0
Browse files Browse the repository at this point in the history
Add migration for `v0.15.0` and other fixes
  • Loading branch information
Xieyt authored Jun 21, 2024
2 parents 830d601 + 5a7212b commit 57d7bf0
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 85 deletions.
3 changes: 1 addition & 2 deletions Docker/frappe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -120,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 @@ -162,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 @@ -182,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.

11 changes: 6 additions & 5 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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 @@ -45,11 +46,11 @@ if [[ ! -f "/workspace/.profile" ]]; then
fi


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"
# 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"

}
2 changes: 1 addition & 1 deletion Docker/frappe/frappe-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stopsignal=QUIT
[program:frappe-bench-frappe-watch]
command=/opt/user/bench-dev-watch.sh
priority=4
autostart=false
autostart=true
autorestart=false
stdout_logfile=/workspace/frappe-bench/logs/watch.dev.log
redirect_stderr=true
Expand Down
2 changes: 1 addition & 1 deletion Docker/frappe/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export PATH=$HOME/.local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

ZSH_THEME="gnzh"
ZSH_THEME="fm"

plugins=(git z)

Expand Down
2 changes: 1 addition & 1 deletion frappe_manager/migration_manager/backup_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def exists(self):


current_migration_timestamp = f"{datetime.now().strftime('%d-%b-%y--%H-%M-%S')}"
CLI_MIGARATIONS_DIR = CLI_DIR / 'backups' / 'migrations'
CLI_MIGARATIONS_DIR = CLI_DIR / 'backups'


class BackupManager:
Expand Down
2 changes: 1 addition & 1 deletion frappe_manager/migration_manager/migration_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MigrationBase(ABC):
logger: Logger = log.get_logger()

def init(self):
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(services_path=CLI_DIR / 'services')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MigrationV0100(MigrationBase):

def init(self):
self.benches_dir = CLI_DIR / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.string_timestamp = datetime.now().strftime("%d-%b-%y--%H-%M-%S")
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MigrationV0110(MigrationBase):
def init(self):
self.cli_dir: Path = Path.home() / 'frappe'
self.benches_dir = self.cli_dir / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(
services_path=self.cli_dir / 'services'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MigrationV0120(MigrationBase):
def init(self):
self.cli_dir: Path = Path.home() / 'frappe'
self.benches_dir = self.cli_dir / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(
services_path=self.cli_dir / 'services'
Expand Down
13 changes: 3 additions & 10 deletions frappe_manager/migration_manager/migrations/migrate_0_13_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,18 @@ class MigrationV0130(MigrationBase):
def init(self):
self.cli_dir: Path = Path.home() / 'frappe'
self.benches_dir = self.cli_dir / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(
services_path=self.cli_dir / 'services'
)

def migrate_services(self):
# backup services compose
if not self.services_manager.compose_project.compose_file_manager.exists():
raise MigrationExceptionInBench(
f"Services compose at {self.services_manager.compose_project.compose_file_manager} not found."
)

self.backup_manager.backup(self.services_manager.compose_project.compose_file_manager.compose_path)

# remove version from services yml
try:
del self.services_manager.compose_project.compose_file_manager.yml['version']
except KeyError:
self.logger.warning(f"[services]: 'version' attribute not found in compose file.")
self.logger.warning("[services]: 'version' attribute not found in compose file.")
pass

# include new volume info
Expand Down Expand Up @@ -207,6 +199,7 @@ def migrate_bench_compose(self, bench: MigrationBench):
bench.compose_project.compose_file_manager.write_to_file()

richprint.print(f"Migrated [blue]{bench.name}[/blue] compose file.")
self.migrate_workers_compose(bench)

def migrate_workers_compose(self, bench: MigrationBench):
if bench.workers_compose_project.compose_file_manager.compose_path.exists():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MigrationV0131(MigrationBase):
def init(self):
self.cli_dir: Path = Path.home() / 'frappe'
self.benches_dir = self.cli_dir / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(
services_path=self.cli_dir / 'services'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MigrationV0140(MigrationBase):
def init(self):
self.cli_dir: Path = Path.home() / 'frappe'
self.benches_dir = self.cli_dir / "sites"
self.backup_manager = BackupManager(str(self.version), self.benches_dir)
self.backup_manager = BackupManager(name=str(self.version), benches_dir=self.benches_dir)
self.benches_manager = MigrationBenches(self.benches_dir)
self.services_manager: MigrationServicesManager = MigrationServicesManager(
services_path=self.cli_dir / 'services'
Expand Down
Loading

0 comments on commit 57d7bf0

Please sign in to comment.