FROM ubuntu:22.04

ARG ARGUS_BUILD_UID=2133
ARG ARGUS_BUILD_GID=2015

ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Asia/Shanghai \
    ARGUS_LOGS_WORLD_WRITABLE=1

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
      ca-certificates curl wget iproute2 iputils-ping net-tools jq tzdata \
      cron procps supervisor vim less tar gzip python3; \
    rm -rf /var/lib/apt/lists/*; \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

WORKDIR /

# Offline fluent-bit assets and bundle tarball are staged by the build script
COPY node-bootstrap.sh /usr/local/bin/node-bootstrap.sh
COPY health-watcher.sh /usr/local/bin/health-watcher.sh
COPY private/start-fluent-bit.sh /private/start-fluent-bit.sh
COPY private/etc /private/etc
COPY private/packages /private/packages
COPY bundle/ /bundle/

RUN chmod +x /usr/local/bin/node-bootstrap.sh /usr/local/bin/health-watcher.sh /private/start-fluent-bit.sh || true; \
    mkdir -p /logs/train /logs/infer /buffers /opt/argus-metric; \
    if [ "${ARGUS_LOGS_WORLD_WRITABLE}" = "1" ]; then chmod 1777 /logs/train /logs/infer || true; else chmod 755 /logs/train /logs/infer || true; fi; \
    chmod 770 /buffers || true

ENTRYPOINT ["/usr/local/bin/node-bootstrap.sh"]
