Skip to content

Commit cec9ab2

Browse files
yaauiedonoghuc
andcommitted
observabilitySRE: docker rake tasks (elastic#17272)
* observabilitySRE: docker rake tasks * Apply suggestions from code review Co-authored-by: Cas Donoghue <[email protected]> * Update rakelib/plugin.rake * Update rakelib/plugin.rake * Update docker/Makefile Co-authored-by: Cas Donoghue <[email protected]> --------- Co-authored-by: Cas Donoghue <[email protected]>
1 parent 079965f commit cec9ab2

File tree

6 files changed

+236
-36
lines changed

6 files changed

+236
-36
lines changed

build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,28 @@ tasks.register("compileGrammar") {
324324
}
325325
}
326326

327+
tasks.register("artifactDockerObservabilitySRE") {
328+
dependsOn bootstrap
329+
inputs.files fileTree("${projectDir}/rakelib")
330+
inputs.files fileTree("${projectDir}/bin")
331+
inputs.files fileTree("${projectDir}/config")
332+
inputs.files fileTree("${projectDir}/lib")
333+
inputs.files fileTree("${projectDir}/logstash-core-plugin-api")
334+
inputs.files fileTree("${projectDir}/logstash-core/lib")
335+
inputs.files fileTree("${projectDir}/logstash-core/src")
336+
inputs.files fileTree("${projectDir}/x-pack")
337+
outputs.files fileTree("${buildDir}") {
338+
include "Dockerfile-observability-sre"
339+
include "logstash-observability-sre-${project.version}-SNAPSHOT-linux-*.tar.gz"
340+
include "logstash-observability-sre-${project.version}-SNAPSHOT-docker-build-context.tar.gz"
341+
include "plugin_aliases_hashed.yml"
342+
include "jdk-*-linux-*.tar.gz"
343+
}
344+
doLast {
345+
rake(projectDir, buildDir, 'artifact:build_docker_observabilitySRE')
346+
}
347+
}
348+
327349
tasks.register("assembleTarDistribution") {
328350
dependsOn bootstrap
329351
inputs.files fileTree("${projectDir}/rakelib")

docker/Makefile

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ else
1616
ARCHITECTURE := $(shell uname -m)
1717
endif
1818

19-
IMAGE_FLAVORS ?= oss full ubi8 wolfi
19+
IMAGE_FLAVORS ?= oss full ubi8 wolfi observability-sre
2020
DEFAULT_IMAGE_FLAVOR ?= full
2121

2222
IMAGE_TAG := $(ELASTIC_REGISTRY)/logstash/logstash
2323
HTTPD ?= logstash-docker-artifact-server
2424

25-
all: build-from-local-artifacts build-from-local-oss-artifacts public-dockerfiles
25+
all: build-from-local-artifacts build-from-local-oss-artifacts build-from-local-observability-sre-artifacts public-dockerfiles
2626

2727
# Build from artifacts on the local filesystem, using an http server (running
2828
# in a container) to provide the artifacts to the Dockerfile.
@@ -54,6 +54,15 @@ build-from-local-ubi8-artifacts: dockerfile env2yaml
5454
(docker kill $(HTTPD); false);
5555
-docker kill $(HTTPD)
5656

57+
build-from-local-observability-sre-artifacts: dockerfile
58+
docker run --rm -d --name=$(HTTPD) \
59+
-p 8000:8000 --expose=8000 -v $(ARTIFACTS_DIR):/mnt \
60+
python:3 bash -c 'cd /mnt && python3 -m http.server'
61+
timeout 120 bash -c 'until curl -s localhost:8000 > /dev/null; do sleep 1; done'
62+
docker build --progress=plain --network=host -t $(IMAGE_TAG)-observability-sre:$(VERSION_TAG) -f $(ARTIFACTS_DIR)/Dockerfile-observability-sre data/logstash || \
63+
(docker kill $(HTTPD); false);
64+
-docker kill $(HTTPD)
65+
5766
build-from-local-wolfi-artifacts: dockerfile
5867
docker run --rm -d --name=$(HTTPD) \
5968
-p 8000:8000 --expose=8000 -v $(ARTIFACTS_DIR):/mnt \
@@ -118,7 +127,7 @@ ironbank_docker_paths:
118127
mkdir -p $(ARTIFACTS_DIR)/ironbank/scripts/go/src/env2yaml/vendor
119128
mkdir -p $(ARTIFACTS_DIR)/ironbank/scripts/pipeline
120129

121-
public-dockerfiles: public-dockerfiles_oss public-dockerfiles_full public-dockerfiles_ubi8 public-dockerfiles_wolfi public-dockerfiles_ironbank
130+
public-dockerfiles: public-dockerfiles_oss public-dockerfiles_full public-dockerfiles_ubi8 public-dockerfiles_wolfi public-dockerfiles_observability-sre public-dockerfiles_ironbank
122131

123132
public-dockerfiles_full: templates/Dockerfile.erb docker_paths $(COPY_FILES)
124133
../vendor/jruby/bin/jruby -S erb -T "-"\
@@ -162,6 +171,20 @@ public-dockerfiles_ubi8: templates/Dockerfile.erb docker_paths $(COPY_FILES)
162171
cp $(ARTIFACTS_DIR)/Dockerfile-ubi8 Dockerfile && \
163172
tar -zcf ../logstash-ubi8-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
164173

174+
public-dockerfiles_observability-sre: templates/Dockerfile.erb docker_paths $(COPY_FILES)
175+
../vendor/jruby/bin/jruby -S erb -T "-"\
176+
created_date="${BUILD_DATE}" \
177+
elastic_version="${ELASTIC_VERSION}" \
178+
arch="${ARCHITECTURE}" \
179+
version_tag="${VERSION_TAG}" \
180+
release="${RELEASE}" \
181+
image_flavor="observability-sre" \
182+
local_artifacts="false" \
183+
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-observability-sre" && \
184+
cd $(ARTIFACTS_DIR)/docker && \
185+
cp $(ARTIFACTS_DIR)/Dockerfile-observability-sre Dockerfile && \
186+
tar -zcf ../logstash-observability-sre-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
187+
165188
public-dockerfiles_wolfi: templates/Dockerfile.erb docker_paths $(COPY_FILES)
166189
../vendor/jruby/bin/jruby -S erb -T "-"\
167190
created_date="${BUILD_DATE}" \

docker/templates/Dockerfile.erb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This Dockerfile was generated from templates/Dockerfile.erb
2-
<% if image_flavor == 'wolfi' -%>
2+
<% if %w(wolfi observability-sre).include?(image_flavor) -%>
33
FROM docker.elastic.co/wolfi/go:1-dev as builder-env2yaml
44

55
COPY env2yaml/env2yaml.go /tmp/go/src/env2yaml/env2yaml.go
@@ -70,7 +70,7 @@ RUN dnf -y upgrade && \
7070
rm /tmp/logstash.tar.gz
7171
<%# End image_flavor 'ironbank' %>
7272
<% else -%>
73-
<%# Start image_flavor 'full', oss', 'ubi8', 'wolfi' %>
73+
<%# Start image_flavor 'full', oss', 'ubi8', 'wolfi', 'observability-sre' %>
7474
<% if local_artifacts == 'false' -%>
7575
<% url_root = 'https://artifacts.elastic.co/downloads/logstash' -%>
7676
<% else -%>
@@ -79,6 +79,9 @@ RUN dnf -y upgrade && \
7979
<% if image_flavor == 'oss' -%>
8080
<% tarball = "logstash-oss-#{elastic_version}-linux-$(arch).tar.gz" -%>
8181
<% license = 'Apache 2.0' -%>
82+
<% elsif image_flavor == 'observability-sre' %>
83+
<% tarball = "logstash-observability-sre-#{elastic_version}-linux-$(arch).tar.gz" -%>
84+
<% license = 'Elastic License' -%>
8285
<% else -%>
8386
<% tarball = "logstash-#{elastic_version}-linux-$(arch).tar.gz" -%>
8487
<% license = 'Elastic License' -%>
@@ -89,7 +92,7 @@ RUN dnf -y upgrade && \
8992
<% arch_command = 'uname -m' -%>
9093
# Minimal distributions do not ship with en language packs.
9194
<% locale = 'C.UTF-8' -%>
92-
<% elsif image_flavor == 'wolfi' %>
95+
<% elsif %w(wolfi observability-sre).include?(image_flavor) %>
9396
<% base_image = 'docker.elastic.co/wolfi/chainguard-base' -%>
9497
<% package_manager = 'apk' -%>
9598
<% arch_command = 'uname -m' -%>
@@ -105,7 +108,7 @@ RUN dnf -y upgrade && \
105108
FROM <%= base_image %>
106109

107110
RUN for iter in {1..10}; do \
108-
<% if image_flavor == 'wolfi' %>
111+
<% if %w(wolfi observability-sre).include?(image_flavor) %>
109112
<%= package_manager %> add --no-cache curl bash openssl && \
110113
<% else -%>
111114
<% if image_flavor == 'full' || image_flavor == 'oss' -%>
@@ -141,7 +144,7 @@ sleep 10; done; \
141144
(exit $exit_code)
142145

143146
# Provide a non-root user to run the process.
144-
<% if image_flavor == 'wolfi' -%>
147+
<% if %w(wolfi observability-sre).include?(image_flavor) -%>
145148
RUN addgroup -g 1000 logstash && \
146149
adduser -u 1000 -G logstash \
147150
--disabled-password \
@@ -186,7 +189,7 @@ RUN chown --recursive logstash:root config/ pipeline/
186189
# Ensure Logstash gets the correct locale by default.
187190
ENV LANG=<%= locale %> LC_ALL=<%= locale %>
188191

189-
<% if image_flavor == 'wolfi' -%>
192+
<% if %w(wolfi observability-sre).include?(image_flavor) -%>
190193
COPY --from=builder-env2yaml /tmp/go/src/env2yaml/env2yaml /usr/local/bin/env2yaml
191194
<% else -%>
192195
COPY env2yaml/env2yaml-amd64 env2yaml/env2yaml-arm64 env2yaml/
@@ -209,7 +212,7 @@ RUN set -eux; env2yamlarch="$(<%= arch_command %>)"; \
209212
COPY bin/docker-entrypoint /usr/local/bin/
210213

211214
RUN chmod 0755 /usr/local/bin/docker-entrypoint
212-
<%# End image_flavor 'full', oss', 'ubi8', 'wolfi' %>
215+
<%# End image_flavor 'full', oss', 'ubi8', 'wolfi', 'observability-sre' %>
213216
<% end -%>
214217

215218
USER 1000

0 commit comments

Comments
 (0)