# This Dockerfile was generated from templates/IronbankDockerfile.erb

ARG BASE_REGISTRY=registry1.dso.mil
ARG BASE_IMAGE=ironbank/redhat/ubi/ubi9
ARG BASE_TAG=9.7
ARG LOGSTASH_VERSION=9.3.8-SNAPSHOT

FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG}

ARG LOGSTASH_VERSION

ENV ELASTIC_CONTAINER=true
ENV PATH=/usr/share/logstash/bin:$PATH

WORKDIR /usr/share

COPY scripts/config/* config/
COPY scripts/pipeline/default.conf pipeline/logstash.conf
COPY scripts/bin/docker-entrypoint /usr/local/bin/
COPY logstash-${LOGSTASH_VERSION}-linux-x86_64.tar.gz /tmp/logstash.tar.gz

RUN dnf -y upgrade && \
  dnf install -y procps findutils tar gzip which shadow-utils && \
  dnf clean all && \
  groupadd --gid 1000 logstash && \
  adduser --uid 1000 --gid 1000 --home-dir /usr/share/logstash --no-create-home logstash && \
  tar -zxf /tmp/logstash.tar.gz -C /usr/share/ && \
  mv /usr/share/logstash-${LOGSTASH_VERSION} /usr/share/logstash && \
  chown -R 1000:0 /usr/share/logstash && \
  chown --recursive logstash:logstash /usr/share/logstash/ && \
  chown -R logstash:root /usr/share/logstash config/ pipeline/ && \
  chmod -R g=u /usr/share/logstash && \
  mv config/* /usr/share/logstash/config && \
  mv pipeline /usr/share/logstash/pipeline && \
  mkdir /licenses/ && \
  mv /usr/share/logstash/NOTICE.TXT /licenses/NOTICE.TXT && \
  mv /usr/share/logstash/LICENSE.txt /licenses/LICENSE.txt && \
  ln -s /usr/share/logstash /opt/logstash && \
  chmod 0755 /usr/local/bin/docker-entrypoint && \
  rmdir config && \
  rm /tmp/logstash.tar.gz


COPY --chown=logstash:root scripts/env2yaml/classes /usr/share/logstash/env2yaml/classes/
COPY --chown=logstash:root scripts/env2yaml/lib /usr/share/logstash/env2yaml/lib/
COPY --chmod=0755 scripts/env2yaml/env2yaml /usr/local/bin/env2yaml

WORKDIR /usr/share/logstash

USER 1000

EXPOSE 9600 5044

ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
