diff --git a/freva-rest/Dockerfile b/freva-rest/Dockerfile index 3d541f0..e6a504d 100644 --- a/freva-rest/Dockerfile +++ b/freva-rest/Dockerfile @@ -28,13 +28,15 @@ FROM base AS final WORKDIR /opt/freva-rest COPY --from=builder /opt/app/dist /opt/app/dist COPY src/freva_rest/api_config.toml $API_CONFIG -ENV PATH=/opt/conda/bin:$PATH +ENV PATH=/opt/conda/bin:/usr/local/bin:$PATH RUN mkdir -p /docker-entrypoint-initdb.d && \ mamba install -y -q -c conda-forge --override-channels freva-rest-server && \ python3 -m pip install --no-cache-dir /opt/app/dist/freva_rest*.whl -COPY entrypoint.sh /docker-entrypoint-initdb.d/entrypoint.sh -RUN chmod +x /docker-entrypoint-initdb.d/entrypoint.sh &&\ - mkdir -p /logs && chmod -R 666 /logs +COPY --chmod=0755 docker-scripts/entrypoint.sh /docker-entrypoint-initdb.d/entrypoint.sh +COPY --chmod=0755 docker-scripts/follow /usr/local/bin/follow +COPY docker-scripts/logging.sh /usr/local/lib/logging.sh +RUN mkdir -p /logs && chmod -R 2666 /logs ENTRYPOINT ["/docker-entrypoint-initdb.d/entrypoint.sh"] +CMD python3 -m freva_rest.cli diff --git a/freva-rest/docker-scripts/follow b/freva-rest/docker-scripts/follow new file mode 100755 index 0000000..486f287 --- /dev/null +++ b/freva-rest/docker-scripts/follow @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +source /usr/local/lib/logging.sh + +# Allowed services +VALID_SERVICES=("mysql" "mongodb" "redis" "solr") + +logs=() +for service in "$@"; do + service_lower=$(echo "$service" | tr '[:upper:]' '[:lower:]') + if [[ " ${VALID_SERVICES[*]} " =~ " $service_lower " ]]; then + log_file="/logs/${service_lower}.log" + if [[ -f "$log_file" ]]; then + logs+=("$log_file") + else + log_warn Log file for '$service_lower' does not exist: $log_file" + fi + else + log_error "Error: '$service' is not a valid service. Allowed: ${VALID_SERVICES[*]}" + exit 1 + fi +done +if [[ ${#logs[@]} -eq 0 ]]; then + log_error "No valid services provided. Allowed: ${VALID_SERVICES[*]}" + exit 1 +fi + +tail -f "${logs[@]}" diff --git a/freva-rest/docker-scripts/logging.sh b/freva-rest/docker-scripts/logging.sh new file mode 100755 index 0000000..7cd0749 --- /dev/null +++ b/freva-rest/docker-scripts/logging.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +MAGENTA='\033[0;35m' +CYAN='\033[0;36m' +NC='\033[0m' + +display_logo() { + echo -e "${BLUE}" + echo -e "${BLUE} ████████▓▒░ ████████▓▒░ ████████▓▒░ ██▓▒░ ██▓▒░ ███████▓▒░ ${NC}" + echo -e "${BLUE} ██▓▒░ ██▓▒░ █▓▒░ ██▓▒░ ██▓▒░ ██▓▒░ ██▓▒░ ██▓▒░${NC}" + echo -e "${BLUE} ██▓▒░ ██▓▒░ █▓▒░ ██▓▒░ ██▓▒▒▓█▓▒░ ██▓▒░ ██▓▒░${NC}" + echo -e "${BLUE} ███████▓▒░ ███████▓▒░ ███████▓▒░ ██▓▒▒▓█▓▒░ ██████████▓▒░${NC}" + echo -e "${BLUE} ██▓▒░ ██▓▒░ █▓▒░ ██▓▒░ ██▓▓█▓▒░ ██▓▒░ ██▓▒░${NC}" + echo -e "${BLUE} ██▓▒░ ██▓▒░ █▓▒░ ██▓▒░ ██▓▓█▓▒░ ██▓▒░ ██▓▒░${NC}" + echo -e "${BLUE} ██▓▒░ ██▓▒░ █▓▒░ █████████▓▒░ ███▓▒░ ██▓▒░ ██▓▒░${NC}" + echo -e "${NC}" + echo -e "${GREEN}================================================================${NC}" + echo -e "${YELLOW} Starting FREVA Services ${NC}" + echo -e "${GREEN}================================================================${NC}" + echo "" +} + +log_info() { + echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] [INFO]${NC} $*" +} + +log_warn() { + echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] [WARNNING]${NC} $* >&2" +} + +log_error() { + echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] [ERROR]${NC} $* >&2" +} + +log_debug() { + echo -e "${CYAN}[$(date +'%Y-%m-%d %H:%M:%S')] [DEBUG]${NC} $*" +} + +log_service() { + echo -e "${MAGENTA}[$(date +'%Y-%m-%d %H:%M:%S')] [SERVICE]${NC} === $* ===" +}