Skip to content

Commit

Permalink
Backport of env2yaml arm64 Docker build context fixes
Browse files Browse the repository at this point in the history
This commit contains fixes made to the main 8.x branch to generate
arm64 and amd64 env2yaml binaries, copy them into the build context
and correctly identify the correct binary in the Dockerfile to
include in the Docker image.

A clean backport was not available due to the change in format of
Dockerfile template from j2 to erb in elastic#15142

This contains fixes from elastic#15980 and elastic#16053.
  • Loading branch information
robbavey committed Apr 5, 2024
1 parent 3e412da commit 54a79bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
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
21 changes: 20 additions & 1 deletion docker/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,25 @@ 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/
COPY env2yaml/env2yaml-arm64 env2yaml/

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


# Place the startup wrapper script.
ADD bin/docker-entrypoint /usr/local/bin/
{% else -%}
Expand All @@ -156,6 +174,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/

# Place the startup wrapper script.
COPY scripts/bin/docker-entrypoint /usr/local/bin/
{% endif -%}
Expand Down

0 comments on commit 54a79bd

Please sign in to comment.