mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Fixes the version of the included version of golang to consistently be 1.21.8 across the Dockerfile and hardening manifest templates
196 lines
7.3 KiB
Text
196 lines
7.3 KiB
Text
# This Dockerfile was generated from templates/Dockerfile.erb
|
|
<% if local_artifacts == 'false' -%>
|
|
<% url_root = 'https://artifacts.elastic.co/downloads/logstash' -%>
|
|
<% else -%>
|
|
<% url_root = 'http://localhost:8000' -%>
|
|
<% end -%>
|
|
<% if image_flavor == 'oss' -%>
|
|
<% tarball = "logstash-oss-#{elastic_version}-linux-$(arch).tar.gz" -%>
|
|
<% license = 'Apache 2.0' -%>
|
|
<% else -%>
|
|
<% tarball = "logstash-#{elastic_version}-linux-$(arch).tar.gz" -%>
|
|
<% license = 'Elastic License' -%>
|
|
<% end -%>
|
|
<% if image_flavor == 'ubi8' %>
|
|
<% base_image = 'docker.elastic.co/ubi8/ubi-minimal' -%>
|
|
<% package_manager = 'microdnf' -%>
|
|
# Minimal distributions do not ship with en language packs.
|
|
<% locale = 'C.UTF-8' -%>
|
|
<% elsif image_flavor == 'ironbank' -%>
|
|
<% package_manager = 'yum' -%>
|
|
<% else -%>
|
|
<% base_image = 'ubuntu:20.04' -%>
|
|
<% package_manager = 'apt-get' -%>
|
|
<% locale = 'en_US.UTF-8' -%>
|
|
<% end -%>
|
|
<% if image_flavor == 'ironbank' -%>
|
|
ARG BASE_REGISTRY=registry1.dsop.io
|
|
ARG BASE_IMAGE=ironbank/redhat/ubi/ubi8
|
|
ARG BASE_TAG=8.10
|
|
ARG LOGSTASH_VERSION=<%= elastic_version %>
|
|
ARG GOLANG_VERSION=1.21.8
|
|
|
|
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} AS env2yaml
|
|
|
|
ARG GOLANG_VERSION
|
|
|
|
# install golang
|
|
RUN yum update -y && yum install -y git
|
|
COPY go${GOLANG_VERSION}.linux-amd64.tar.gz /opt/go.tar.gz
|
|
RUN tar -C /usr/local -xzf /opt/go.tar.gz
|
|
ENV PATH=$PATH:/usr/local/go/bin
|
|
|
|
# compile the env2yaml tool
|
|
COPY v2.3.0.tar.gz /opt/env2yaml.tar.gz
|
|
COPY scripts/go /usr/local/src/go
|
|
WORKDIR /usr/local/src/go/src/env2yaml
|
|
RUN mkdir -p vendor/gopkg.in
|
|
RUN tar -zxf /opt/env2yaml.tar.gz -C vendor/gopkg.in
|
|
RUN mv vendor/gopkg.in/yaml-2.3.0 vendor/gopkg.in/yaml.v2
|
|
ENV GOPATH=/usr/local/src/go
|
|
RUN go build -mod vendor
|
|
|
|
# stage 1: unpack logstash
|
|
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} AS builder
|
|
|
|
ARG LOGSTASH_VERSION
|
|
|
|
WORKDIR /usr/share/
|
|
COPY logstash-${LOGSTASH_VERSION}-linux-x86_64.tar.gz /opt/logstash.tar.gz
|
|
|
|
RUN tar zxf /opt/logstash.tar.gz && \
|
|
mv /usr/share/logstash-${LOGSTASH_VERSION} /usr/share/logstash
|
|
|
|
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG}
|
|
<% else -%>
|
|
FROM <%= base_image %>
|
|
<% end -%>
|
|
|
|
RUN for iter in {1..10}; do \
|
|
<% if image_flavor == 'full' || image_flavor == 'oss' -%>
|
|
export DEBIAN_FRONTEND=noninteractive && \
|
|
<% end -%>
|
|
<%= package_manager %> update -y && \
|
|
<% if image_flavor != 'ironbank' -%>
|
|
<%= package_manager %> upgrade -y && \
|
|
<% end -%>
|
|
<%= package_manager %> install -y procps findutils tar gzip curl && \
|
|
<% if image_flavor == 'ubi8' -%>
|
|
<%= package_manager %> install -y openssl && \
|
|
<% end -%>
|
|
<% if image_flavor == 'ubi8' || image_flavor == 'ironbank' -%>
|
|
<%= package_manager %> install -y which shadow-utils && \
|
|
<% else -%>
|
|
<%= package_manager %> install -y locales && \
|
|
<% end -%>
|
|
<%= package_manager %> clean all && \
|
|
<% if image_flavor == 'full' || image_flavor == 'oss' -%>
|
|
locale-gen 'en_US.UTF-8' && \
|
|
<%= package_manager %> clean metadata && \
|
|
<% end -%>
|
|
exit_code=0 && break || exit_code=$? && \
|
|
echo "packaging error: retry $iter in 10s" && \
|
|
<%= package_manager %> clean all && \
|
|
<% if image_flavor == 'full' || image_flavor == 'oss' -%>
|
|
<%= package_manager %> clean metadata && \
|
|
<% end -%>
|
|
sleep 10; done; \
|
|
(exit $exit_code)
|
|
|
|
# Provide a non-root user to run the process.
|
|
RUN groupadd --gid 1000 logstash && \
|
|
adduser --uid 1000 --gid 1000 \
|
|
<% if image_flavor != 'ironbank' %>--home <% else %>--home-dir <% end %>/usr/share/logstash --no-create-home \
|
|
logstash
|
|
|
|
<% if image_flavor == 'ironbank' %>
|
|
WORKDIR /usr/share/logstash
|
|
COPY --from=env2yaml /usr/local/src/go/src/env2yaml/env2yaml /usr/local/bin/env2yaml
|
|
COPY --from=builder --chown=1000:0 /usr/share/logstash /usr/share/logstash
|
|
<% end -%>
|
|
|
|
# Add Logstash itself.
|
|
RUN \
|
|
<% if image_flavor != 'ironbank' %> curl -Lo - <%= url_root %>/<%= tarball %> | \
|
|
tar zxf - -C /usr/share && \
|
|
mv /usr/share/logstash-<%= elastic_version %> /usr/share/logstash && \
|
|
<% end -%>
|
|
chown --recursive logstash:logstash /usr/share/logstash/ && \
|
|
chown -R logstash:root /usr/share/logstash && \
|
|
chmod -R g=u /usr/share/logstash && \
|
|
mkdir /licenses/ && \
|
|
mv /usr/share/logstash/NOTICE.TXT /licenses/NOTICE.TXT && \
|
|
mv /usr/share/logstash/LICENSE.txt /licenses/LICENSE.txt && \
|
|
<% if image_flavor != 'ironbank' -%>
|
|
find /usr/share/logstash -type d -exec chmod g+s {} \; && \
|
|
<% end -%>
|
|
ln -s /usr/share/logstash /opt/logstash
|
|
|
|
<% if image_flavor != 'ironbank' %>
|
|
WORKDIR /usr/share/logstash
|
|
<% end -%>
|
|
ENV ELASTIC_CONTAINER true
|
|
ENV PATH=/usr/share/logstash/bin:$PATH
|
|
|
|
# Provide a minimal configuration, so that simple invocations will provide
|
|
# a good experience.
|
|
<% if image_flavor != 'ironbank' -%>
|
|
COPY config/pipelines.yml config/pipelines.yml
|
|
<% if image_flavor == 'oss' -%>
|
|
COPY config/logstash-oss.yml config/logstash.yml
|
|
<% else -%>
|
|
COPY config/logstash-full.yml config/logstash.yml
|
|
<% end -%>
|
|
COPY config/log4j2.properties config/
|
|
COPY pipeline/default.conf pipeline/logstash.conf
|
|
RUN chown --recursive logstash:root config/ pipeline/
|
|
# Ensure Logstash gets the correct locale by default.
|
|
ENV LANG=<%= locale %> LC_ALL=<%= locale %>
|
|
COPY env2yaml/env2yaml /usr/local/bin/
|
|
# Place the startup wrapper script.
|
|
COPY bin/docker-entrypoint /usr/local/bin/
|
|
<% else -%>
|
|
COPY scripts/config/pipelines.yml config/pipelines.yml
|
|
COPY scripts/config/logstash.yml config/logstash.yml
|
|
COPY scripts/config/log4j2.properties config/
|
|
COPY scripts/pipeline/default.conf pipeline/logstash.conf
|
|
RUN chown --recursive logstash:root config/ pipeline/
|
|
# Place the startup wrapper script.
|
|
COPY scripts/bin/docker-entrypoint /usr/local/bin/
|
|
<% end -%>
|
|
|
|
RUN chmod 0755 /usr/local/bin/docker-entrypoint
|
|
|
|
USER 1000
|
|
|
|
EXPOSE 9600 5044
|
|
|
|
<% if image_flavor != 'ironbank' -%>
|
|
LABEL org.label-schema.schema-version="1.0" \
|
|
org.label-schema.vendor="Elastic" \
|
|
org.opencontainers.image.vendor="Elastic" \
|
|
org.label-schema.name="logstash" \
|
|
org.opencontainers.image.title="logstash" \
|
|
org.label-schema.version="<%= elastic_version %>" \
|
|
org.opencontainers.image.version="<%= elastic_version %>" \
|
|
org.label-schema.url="https://www.elastic.co/products/logstash" \
|
|
org.label-schema.vcs-url="https://github.com/elastic/logstash" \
|
|
org.label-schema.license="<%= license %>" \
|
|
org.opencontainers.image.licenses="<%= license %>" \
|
|
org.opencontainers.image.description="Logstash is a free and open server-side data processing pipeline that ingests data from a multitude of sources, transforms it, and then sends it to your favorite 'stash.'" \
|
|
org.label-schema.build-date=<%= created_date %> \
|
|
<% if image_flavor == 'ubi8' -%> license="<%= license %>" \
|
|
description="Logstash is a free and open server-side data processing pipeline that ingests data from a multitude of sources, transforms it, and then sends it to your favorite 'stash.'" \
|
|
name="logstash" \
|
|
maintainer="info@elastic.co" \
|
|
summary="Logstash is a free and open server-side data processing pipeline that ingests data from a multitude of sources, transforms it, and then sends it to your favorite 'stash.'" \
|
|
vendor="Elastic" \
|
|
<% end -%>
|
|
org.opencontainers.image.created=<%= created_date %>
|
|
<% end -%>
|
|
|
|
<% if image_flavor == 'ironbank' -%>
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=1m --retries=5 CMD curl -I -f --max-time 5 http://localhost:9600 || exit 1
|
|
<% end -%>
|
|
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
|