Skip to content

Commit

Permalink
chore: Update Conda environment name and install requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Aug 30, 2024
1 parent 4134dda commit ef05db8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
34 changes: 22 additions & 12 deletions dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ FLASK_PORT="${FLASK_PORT:-5050}"
LOG_FILE="/home/$(whoami)/logs/systemdashboard_flask.log"
USERNAME="$(whoami)"

# Ensure log directory exists
LOG_DIR="$(dirname "$LOG_FILE")"
mkdir -p "$LOG_DIR"

# Check for Miniconda3 and Anaconda3
CONDA_PATHS=("/home/$USERNAME/miniconda3" "/home/$USERNAME/anaconda3")
CONDA_FOUND=false

# Find which Conda is installed and set $CONDA_EXECUTABLE
for CONDA_PATH in "${CONDA_PATHS[@]}"; do
if [ -d "$CONDA_PATH" ]; then
CONDA_FOUND=true
CONDA_EXECUTABLE="$CONDA_PATH/bin/conda"
CONDA_SETUP_SCRIPT="$CONDA_PATH/etc/profile.d/conda.sh"
break
fi
done
Expand All @@ -31,9 +38,6 @@ if [ "$CONDA_FOUND" = false ]; then
exit 1
fi

# Derive the path to the Conda setup script
CONDA_SETUP_SCRIPT="$CONDA_PATH/etc/profile.d/conda.sh"

# Check if Conda setup script exists
if [ ! -f "$CONDA_SETUP_SCRIPT" ]; then
log_message "Conda setup script not found at $CONDA_SETUP_SCRIPT."
Expand All @@ -44,19 +48,20 @@ fi
source "$CONDA_SETUP_SCRIPT"

# Define Conda environment name
CONDA_ENV_NAME="systemdashboard"
CONDA_ENV_NAME="dashboard"

echo "Conda environment name: $CONDA_ENV_NAME"
echo $CONDA_EXECUTABLE
# Check if the Conda environment exists and create it if not
if ! conda env list | grep -q "$CONDA_ENV_NAME"; then
if ! conda info --envs | awk '{print $1}' | grep -q "^$CONDA_ENV_NAME$"; then
log_message "Conda environment '$CONDA_ENV_NAME' not found. Creating it..."
conda create -n "$CONDA_ENV_NAME" python=3.10 -y
log_message "Activating Conda environment '$CONDA_ENV_NAME'."
conda activate "$CONDA_ENV_NAME"
log_message "Installing required packages."
pip install -r "$REQUIREMENTS_FILE"

log_message "Activating Conda environment '$CONDA_ENV_NAME' and installing requirements."
# Use `conda run` to execute commands in the environment
conda run -n "$CONDA_ENV_NAME" pip install -r "$REQUIREMENTS_FILE"
else
log_message "Activating existing Conda environment '$CONDA_ENV_NAME'."
conda activate "$CONDA_ENV_NAME"
fi

# Continue with the rest of your script
Expand All @@ -71,11 +76,16 @@ if ! pgrep -f "flask run --host=0.0.0.0 --port=$FLASK_PORT" > /dev/null; then
# git pull in FLASK_APP_PATH directory
current_dir=$(pwd)
cd "$SCRIPT_DIR"
git stash && git pull
if ! git pull; then
log_message "Failed to pull updates from Git repository."
cd "$current_dir"
exit 1
fi
cd "$current_dir"

log_message "Starting Flask app..."
flask run --host=0.0.0.0 --port="$FLASK_PORT" &
# Ensure environment activation and `flask` command
bash -c "source $CONDA_SETUP_SCRIPT && conda activate $CONDA_ENV_NAME && flask run --host=0.0.0.0 --port=$FLASK_PORT" &>> "$LOG_FILE" &
else
log_message "Flask app is already running."
fi
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Flask==2.3.3
psutil==5.9.5
gunicorn
speetest-cli
flask-sqlalchemy
flask-login
flask-login
flask-session

0 comments on commit ef05db8

Please sign in to comment.