Skip to content

Commit

Permalink
Add more helper scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Feb 20, 2025
1 parent b58174e commit 36fdcd0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
10 changes: 6 additions & 4 deletions freva-rest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions freva-rest/docker-scripts/follow
Original file line number Diff line number Diff line change
@@ -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[@]}"
45 changes: 45 additions & 0 deletions freva-rest/docker-scripts/logging.sh
Original file line number Diff line number Diff line change
@@ -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} === $* ==="
}

0 comments on commit 36fdcd0

Please sign in to comment.