mirror of
https://github.com/joaovitoriasilva/endurain.git
synced 2026-01-08 15:33:53 -05:00
Fix Docker UID/GID issue & workout step handling
[docker] fix docker not respecting UID and GID [backend] fix workout step not prepared for "any stroke" for "target_value"
This commit is contained in:
@@ -962,8 +962,12 @@ def parse_frame_workout_step(frame):
|
||||
secondary_target_value = None
|
||||
|
||||
if workout_set_data[3] == "swim_stroke":
|
||||
secondary_target_value = workout_set_data[4]
|
||||
workout_set_data[4] = None
|
||||
if isinstance(workout_set_data[4], str):
|
||||
secondary_target_value = workout_set_data[4]
|
||||
workout_set_data[4] = None
|
||||
elif isinstance(workout_set_data[4], int) and workout_set_data[4] == 255:
|
||||
secondary_target_value = "any stroke"
|
||||
workout_set_data[4] = None
|
||||
|
||||
if workout_set_data[5] == 7:
|
||||
workout_set_data[5] = "active"
|
||||
|
||||
@@ -3,53 +3,80 @@
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Check if the mounted directory exists and has proper permissions
|
||||
echo "Checking ownership of necessary directories..."
|
||||
# Function to log messages
|
||||
echo_info_log() {
|
||||
echo "INFO: $1"
|
||||
}
|
||||
|
||||
# Dynamically adjust UID and GID based on host-mounted directory
|
||||
if [ -d "/app/backend/logs" ]; then
|
||||
HOST_UID=$(stat -c '%u' /app/backend/logs) # Get UID if directory exists
|
||||
HOST_GID=$(stat -c '%g' /app/backend/logs) # Get GID if directory exists
|
||||
else
|
||||
echo "/app/backend/logs directory does not exist. Using default provided UID and GID. Default is 1000."
|
||||
HOST_UID=${UID:-1000}
|
||||
HOST_GID=${GID:-1000}
|
||||
fi
|
||||
echo_error_log() {
|
||||
echo "ERROR: $1" >&2
|
||||
}
|
||||
|
||||
# Function to validate UID and GID
|
||||
validate_id() {
|
||||
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
echo_error_log "Invalid ID: $1. Must be a non-negative integer."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check ownership of necessary directories
|
||||
echo_info_log "Checking ownership of necessary directories..."
|
||||
|
||||
# Dynamically adjust UID and GID based on host-mounted directory or environment variables
|
||||
HOST_UID=${UID:-$(stat -c '%u' /app/backend/logs 2>/dev/null || echo 1000)}
|
||||
HOST_GID=${GID:-$(stat -c '%g' /app/backend/logs 2>/dev/null || echo 1000)}
|
||||
|
||||
# Validate UID and GID
|
||||
validate_id "$HOST_UID"
|
||||
validate_id "$HOST_GID"
|
||||
|
||||
# Avoid setting ownership to root (UID/GID = 0)
|
||||
if [ "$HOST_UID" -ne 0 ] && [ "$HOST_GID" -ne 0 ]; then
|
||||
echo "Adjusting ownership to match host UID ($HOST_UID) and GID ($HOST_GID)..."
|
||||
for dir in /app/backend/logs /app/backend/user_images /app/backend/files; do
|
||||
if [ -d "$dir" ]; then
|
||||
chown -R "$HOST_UID:$HOST_GID" "$dir"
|
||||
else
|
||||
echo "Directory $dir does not exist, skipping chown."
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "Directory is owned by root UID/GID (0). Adjusting will fail, change ownership manually to non-root, example 1000:1000."
|
||||
if [ "$HOST_UID" -eq 0 ] || [ "$HOST_GID" -eq 0 ]; then
|
||||
echo_error_log "UID or GID is set to 0 (root). Adjust ownership manually to a non-root user."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo_info_log "Adjusting ownership to match host UID ($HOST_UID) and GID ($HOST_GID)..."
|
||||
|
||||
# List of directories to adjust ownership
|
||||
directories=(
|
||||
/app/backend/logs
|
||||
/app/backend/user_images
|
||||
/app/backend/files
|
||||
/app/backend/server_images
|
||||
)
|
||||
|
||||
# Adjust ownership for each directory
|
||||
for dir in "${directories[@]}"; do
|
||||
if [ -d "$dir" ]; then
|
||||
chown -R "$HOST_UID:$HOST_GID" "$dir"
|
||||
echo_info_log "Ownership adjusted for $dir"
|
||||
else
|
||||
echo_info_log "Directory $dir does not exist, skipping."
|
||||
fi
|
||||
done
|
||||
|
||||
# Substitute MY_APP_ENDURAIN_HOST with the value of ENDURAIN_HOST
|
||||
if [ -n "$ENDURAIN_HOST" ]; then
|
||||
echo "Substituting MY_APP_ENDURAIN_HOST with $ENDURAIN_HOST"
|
||||
echo_info_log "Substituting MY_APP_ENDURAIN_HOST with $ENDURAIN_HOST"
|
||||
find /app/frontend/dist -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|MY_APP_ENDURAIN_HOST|${ENDURAIN_HOST}|g" '{}' +
|
||||
fi
|
||||
|
||||
# Substitute MY_APP_STRAVA_CLIENT_ID with the value of STRAVA_CLIENT_ID
|
||||
if [ -n "$STRAVA_CLIENT_ID" ]; then
|
||||
echo "Substituting MY_APP_STRAVA_CLIENT_ID with $STRAVA_CLIENT_ID"
|
||||
echo_info_log "Substituting MY_APP_STRAVA_CLIENT_ID with $STRAVA_CLIENT_ID"
|
||||
find /app/frontend/dist -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|MY_APP_STRAVA_CLIENT_ID|${STRAVA_CLIENT_ID}|g" '{}' +
|
||||
fi
|
||||
|
||||
echo "Starting FastAPI with BEHIND_PROXY=$BEHIND_PROXY"
|
||||
echo_info_log "Starting FastAPI with BEHIND_PROXY=$BEHIND_PROXY"
|
||||
|
||||
# Define the base command for starting the FastAPI server as an array
|
||||
CMD=("uvicorn" "main:app" "--host" "0.0.0.0" "--port" "8080")
|
||||
|
||||
# Add --proxy-headers if BEHIND_PROXY is true
|
||||
if [ "$BEHIND_PROXY" = "true" ]; then
|
||||
echo "Enabling proxy headers"
|
||||
echo_info_log "Enabling proxy headers"
|
||||
CMD+=("--proxy-headers")
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user