Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of env2yaml arm64 Docker build context fixes #16063

Open
wants to merge 4 commits into
base: 7.17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ build-from-local-ubi8-artifacts: venv dockerfile env2yaml
(docker kill $(HTTPD); false);
-docker kill $(HTTPD)

COPY_FILES = $(ARTIFACTS_DIR)/docker/config/pipelines.yml $(ARTIFACTS_DIR)/docker/config/logstash-oss.yml $(ARTIFACTS_DIR)/docker/config/logstash-full.yml $(ARTIFACTS_DIR)/docker/config/log4j2.properties $(ARTIFACTS_DIR)/docker/pipeline/default.conf $(ARTIFACTS_DIR)/docker/bin/docker-entrypoint $(ARTIFACTS_DIR)/docker/env2yaml/env2yaml
COPY_FILES = $(ARTIFACTS_DIR)/docker/config/pipelines.yml $(ARTIFACTS_DIR)/docker/config/logstash-oss.yml $(ARTIFACTS_DIR)/docker/config/logstash-full.yml $(ARTIFACTS_DIR)/docker/config/log4j2.properties $(ARTIFACTS_DIR)/docker/pipeline/default.conf $(ARTIFACTS_DIR)/docker/bin/docker-entrypoint
COPY_FILES += $(ARTIFACTS_DIR)/docker/env2yaml/env2yaml-arm64
COPY_FILES += $(ARTIFACTS_DIR)/docker/env2yaml/env2yaml-amd64

$(ARTIFACTS_DIR)/docker/config/pipelines.yml: data/logstash/config/pipelines.yml
$(ARTIFACTS_DIR)/docker/config/logstash-oss.yml: data/logstash/config/logstash-oss.yml
Expand All @@ -73,6 +75,8 @@ $(ARTIFACTS_DIR)/docker/config/log4j2.properties: data/logstash/config/log4j2.pr
$(ARTIFACTS_DIR)/docker/pipeline/default.conf: data/logstash/pipeline/default.conf
$(ARTIFACTS_DIR)/docker/bin/docker-entrypoint: data/logstash/bin/docker-entrypoint
$(ARTIFACTS_DIR)/docker/env2yaml/env2yaml: data/logstash/env2yaml/env2yaml
$(ARTIFACTS_DIR)/docker/env2yaml/env2yaml-arm64: data/logstash/env2yaml/env2yaml-arm64
$(ARTIFACTS_DIR)/docker/env2yaml/env2yaml-amd64: data/logstash/env2yaml/env2yaml-amd64

$(ARTIFACTS_DIR)/docker/%:
cp -f $< $@
Expand Down Expand Up @@ -198,8 +202,12 @@ venv: requirements.txt
env2yaml:
docker run --rm \
-v "$(PWD)/data/logstash/env2yaml:/usr/src/env2yaml" \
-w /usr/src/env2yaml golang:1 go build

-e GOARCH=arm64 -e GOOS=linux \
-w /usr/src/env2yaml golang:1 go build -o /usr/src/env2yaml/env2yaml-arm64
docker run --rm \
-v "$(PWD)/data/logstash/env2yaml:/usr/src/env2yaml" \
-e GOARCH=amd64 -e GOOS=linux \
-w /usr/src/env2yaml golang:1 go build -o /usr/src/env2yaml/env2yaml-amd64
# Generate the Dockerfiles from Jinja2 templates.
dockerfile: venv templates/Dockerfile.j2
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
Expand Down
22 changes: 21 additions & 1 deletion docker/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
{% if image_flavor == 'ubi8' -%}
{% set base_image = 'docker.elastic.co/ubi8/ubi-minimal' -%}
{% set package_manager = 'microdnf' -%}
{% set arch_command = 'uname -m' -%}
# Minimal distributions do not ship with en language packs.
{% set locale = 'C.UTF-8' -%}
{% elif image_flavor == 'ironbank' -%}
{% set package_manager = 'yum' -%}
{% else -%}
{% set base_image = 'ubuntu:20.04' -%}
{% set package_manager = 'apt-get' -%}
{% set arch_command = 'dpkg --print-architecture' -%}
{% set locale = 'en_US.UTF-8' -%}
{% endif -%}

Expand Down Expand Up @@ -147,7 +149,24 @@ ADD 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 }}
ADD env2yaml/env2yaml /usr/local/bin/

# Copy over the appropriate env2yaml artifact
COPY env2yaml/env2yaml-amd64 env2yaml/env2yaml-arm64 env2yaml/

RUN env2yamlarch="$({{ arch_command }})"; \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you've got the hood open, I'd also suggest set -eux here (at the very least set -e so failures propagate correctly):

Suggested change
RUN env2yamlarch="$({{ arch_command }})"; \
RUN set -eux; \
env2yamlarch="$({{ arch_command }})"; \

case "${env2yamlarch}" in \
'x86_64'|'amd64') \
env2yamlarch=amd64; \
;; \
'aarch64'|'arm64') \
env2yamlarch=arm64; \
;; \
*) echo >&2 "error: unsupported architecture '$env2yamlarch'"; exit 1 ;; \
esac; \
cp env2yaml/env2yaml-${env2yamlarch} /usr/local/bin/env2yaml; \
rm -rf env2yaml


robbavey marked this conversation as resolved.
Show resolved Hide resolved
# Place the startup wrapper script.
ADD bin/docker-entrypoint /usr/local/bin/
{% else -%}
Expand All @@ -156,6 +175,7 @@ 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/

robbavey marked this conversation as resolved.
Show resolved Hide resolved
# Place the startup wrapper script.
COPY scripts/bin/docker-entrypoint /usr/local/bin/
{% endif -%}
Expand Down