Skip to content

Commit 6b7e1cc

Browse files
Remove redundant testing and circular dependency from docker acceptance testing (#18181) (#18255)
* Use locally build artifact to build container from public dockerfile Previously we would build an image (which would not actually be used), build dockerfiles, modify dockerfiles to curl from `https://snapshots.elastic.co/downloads/logstash'` then build the image used for testing based on the modified dockerfile. This resulted in testing the last published image to `snapshots`. This presents two problems 1. The test is running against the last published image (not the tip of the branch being tested) 2. this carries a dependency on both a DRA and unified stack release having been run. Therefor acceptance tests will fail in between the time we bump logstash version and a successful run of unified release. This commit modifies the dockerfile to use the artifact prepared in the first step instead of curling the last published one. This solves both issues as the tests run against the code from the tip fo the branch being tested and there is no dependency on an artifact existing as a result of a unified release pipeline. * Remove redundant docker steps from workflows Previously for docker acceptance tests three steps were performed: 1. Build container images (based on local artifacts) 2. Build "public" dockerfiles 3. Build container based on (a modified) file from step 2. The ONLY difference between the dockerfile that ultimately is used to define an image between 1 and 2 is WHERE the logstash source is downloaded from. In acceptance testing we WANT to use the source at the current checkout of logstash (not a remote). Using remote causes a dependency issue when changes are not published. Publishing is tied to unified release and gated on tests so naturally this is a bad fit for that dependency. This commit removes the redundancy by ONLY generating images for testing (step 1 from above). This also firms up our use of LOCAL_ARTIFACTS. Namely, the ONLY time we want that set to `false` is when we build a "public" dockerfile. We explicitly set that in the corresponding DRA script now. Similarly we explicitly set it to `true` when testing. * Remove unused function and argument This commit removes the unused function for building from dockerfiles. It also removes an unused argument for the make task for build_docker. (cherry picked from commit a994c7c) Co-authored-by: Cas Donoghue <[email protected]>
1 parent 06a09d0 commit 6b7e1cc

File tree

4 files changed

+14
-102
lines changed

4 files changed

+14
-102
lines changed

.buildkite/scripts/dra/build_docker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ esac
2424
rake artifact:docker || error "artifact:docker build failed."
2525
rake artifact:docker_oss || error "artifact:docker_oss build failed."
2626
rake artifact:docker_wolfi || error "artifact:docker_wolfi build failed."
27+
28+
# Generating public dockerfiles is the primary use case for NOT using local artifacts
29+
export LOCAL_ARTIFACTS=false
2730
rake artifact:dockerfiles || error "artifact:dockerfiles build failed."
2831

2932
STACK_VERSION="$(./$(dirname "$0")/../common/qualified-version.sh)"

ci/docker_acceptance_tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ set -x
88
export JRUBY_OPTS="-J-Xmx1g"
99
export GRADLE_OPTS="-Xmx4g -Dorg.gradle.console=plain -Dorg.gradle.daemon=false -Dorg.gradle.logging.level=info -Dfile.encoding=UTF-8"
1010

11+
# Use local artifacts for acceptance test Docker builds
12+
export LOCAL_ARTIFACTS=true
13+
1114
if [ -n "$BUILD_JAVA_HOME" ]; then
1215
GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.java.home=$BUILD_JAVA_HOME"
1316
fi
@@ -48,7 +51,7 @@ if [[ $SELECTED_TEST_SUITE == "oss" ]]; then
4851
elif [[ $SELECTED_TEST_SUITE == "full" ]]; then
4952
echo "--- Building $SELECTED_TEST_SUITE docker images"
5053
cd $LS_HOME
51-
rake artifact:build_docker_full
54+
rake artifact:docker
5255
echo "--- Acceptance: Installing dependencies"
5356
cd $QA_DIR
5457
bundle install

docker/Makefile

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,12 @@ public-dockerfiles_full: templates/Dockerfile.erb docker_paths $(COPY_FILES)
132132
version_tag="${VERSION_TAG}" \
133133
release="${RELEASE}" \
134134
image_flavor="full" \
135-
local_artifacts="false" \
135+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
136136
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-full" && \
137137
cd $(ARTIFACTS_DIR)/docker && \
138138
cp $(ARTIFACTS_DIR)/Dockerfile-full Dockerfile && \
139139
tar -zcf ../logstash-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
140140

141-
build-from-dockerfiles_full: public-dockerfiles_full
142-
cd $(ARTIFACTS_DIR)/docker && \
143-
mkdir -p dockerfile_build_full && cd dockerfile_build_full && \
144-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
145-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
146-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-full:$(VERSION_TAG) .
147-
148141
public-dockerfiles_oss: templates/Dockerfile.erb docker_paths $(COPY_FILES)
149142
../vendor/jruby/bin/jruby -S erb -T "-"\
150143
created_date="${BUILD_DATE}" \
@@ -153,19 +146,12 @@ public-dockerfiles_oss: templates/Dockerfile.erb docker_paths $(COPY_FILES)
153146
version_tag="${VERSION_TAG}" \
154147
release="${RELEASE}" \
155148
image_flavor="oss" \
156-
local_artifacts="false" \
149+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
157150
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-oss" && \
158151
cd $(ARTIFACTS_DIR)/docker && \
159152
cp $(ARTIFACTS_DIR)/Dockerfile-oss Dockerfile && \
160153
tar -zcf ../logstash-oss-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
161154

162-
build-from-dockerfiles_oss: public-dockerfiles_oss
163-
cd $(ARTIFACTS_DIR)/docker && \
164-
mkdir -p dockerfile_build_oss && cd dockerfile_build_oss && \
165-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
166-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
167-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-oss:$(VERSION_TAG) .
168-
169155
public-dockerfiles_wolfi: templates/Dockerfile.erb docker_paths $(COPY_FILES)
170156
../vendor/jruby/bin/jruby -S erb -T "-"\
171157
created_date="${BUILD_DATE}" \
@@ -174,19 +160,12 @@ public-dockerfiles_wolfi: templates/Dockerfile.erb docker_paths $(COPY_FILES)
174160
version_tag="${VERSION_TAG}" \
175161
release="${RELEASE}" \
176162
image_flavor="wolfi" \
177-
local_artifacts="false" \
163+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
178164
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-wolfi" && \
179165
cd $(ARTIFACTS_DIR)/docker && \
180166
cp $(ARTIFACTS_DIR)/Dockerfile-wolfi Dockerfile && \
181167
tar -zcf ../logstash-wolfi-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
182168

183-
build-from-dockerfiles_wolfi: public-dockerfiles_wolfi
184-
cd $(ARTIFACTS_DIR)/docker && \
185-
mkdir -p dockerfile_build_wolfi && cd dockerfile_build_wolfi && \
186-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
187-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
188-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-wolfi:$(VERSION_TAG) .
189-
190169
public-dockerfiles_observability-sre: templates/Dockerfile.erb docker_paths $(COPY_FILES)
191170
../vendor/jruby/bin/jruby -S erb -T "-"\
192171
created_date="${BUILD_DATE}" \
@@ -195,19 +174,12 @@ public-dockerfiles_observability-sre: templates/Dockerfile.erb docker_paths $(CO
195174
version_tag="${VERSION_TAG}" \
196175
release="${RELEASE}" \
197176
image_flavor="observability-sre" \
198-
local_artifacts="false" \
177+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
199178
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-observability-sre" && \
200179
cd $(ARTIFACTS_DIR)/docker && \
201180
cp $(ARTIFACTS_DIR)/Dockerfile-observability-sre Dockerfile && \
202181
tar -zcf ../logstash-observability-sre-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
203182

204-
build-from-dockerfiles_observability-sre: public-dockerfiles_observability-sre
205-
cd $(ARTIFACTS_DIR)/docker && \
206-
mkdir -p dockerfile_build_observability-sre && cd dockerfile_build_observability-sre && \
207-
tar -zxf ../../logstash-observability-sre-$(VERSION_TAG)-docker-build-context.tar.gz && \
208-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
209-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-observability-sre:$(VERSION_TAG) .
210-
211183
public-dockerfiles_ironbank: templates/hardening_manifest.yaml.erb templates/IronbankDockerfile.erb ironbank_docker_paths $(COPY_IRONBANK_FILES)
212184
../vendor/jruby/bin/jruby -S erb -T "-"\
213185
elastic_version="${ELASTIC_VERSION}" \
@@ -219,7 +191,7 @@ public-dockerfiles_ironbank: templates/hardening_manifest.yaml.erb templates/Iro
219191
version_tag="${VERSION_TAG}" \
220192
release="${RELEASE}" \
221193
image_flavor="ironbank" \
222-
local_artifacts="false" \
194+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
223195
templates/IronbankDockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-ironbank" && \
224196
cd $(ARTIFACTS_DIR)/ironbank && \
225197
cp $(ARTIFACTS_DIR)/Dockerfile-ironbank Dockerfile && \

rakelib/artifacts.rake

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ namespace "artifact" do
169169

170170
desc "Generate rpm, deb, tar and zip artifacts"
171171
task "all" => ["prepare", "build"]
172-
task "docker_only" => ["prepare", "build_docker_full", "build_docker_oss", "build_docker_wolfi", "build_docker_observabilitySRE"]
172+
task "docker_only" => ["prepare", "docker", "docker_oss", "docker_wolfi", "docker_observabilitySRE"]
173173

174174
desc "Build all (jdk bundled and not) tar.gz and zip of default logstash plugins with all dependencies"
175175
task "archives" => ["prepare", "generate_build_metadata"] do
@@ -397,52 +397,24 @@ namespace "artifact" do
397397
build_dockerfile('oss')
398398
end
399399

400-
namespace "dockerfile_oss" do
401-
desc "Build Oss Docker image from Dockerfile context files"
402-
task "docker" => ["archives_docker", "dockerfile_oss"] do
403-
build_docker_from_dockerfiles('oss')
404-
end
405-
end
406-
407400
desc "Generate Dockerfile for observability-sre images"
408401
task "dockerfile_observabilitySRE" => ["prepare-observabilitySRE", "generate_build_metadata"] do
409402
puts("[dockerfiles] Building observability-sre Dockerfile")
410403
build_dockerfile('observability-sre')
411404
end
412405

413-
namespace "dockerfile_observabilitySRE" do
414-
desc "Build ObservabilitySrE Docker image from Dockerfile context files"
415-
task "docker" => ["archives_docker_observabilitySRE", "dockerfile_observabilitySRE"] do
416-
build_docker_from_dockerfiles('observability-sre')
417-
end
418-
end
419-
420406
desc "Generate Dockerfile for full images"
421407
task "dockerfile_full" => ["prepare", "generate_build_metadata"] do
422408
puts("[dockerfiles] Building full Dockerfiles")
423409
build_dockerfile('full')
424410
end
425411

426-
namespace "dockerfile_full" do
427-
desc "Build Full Docker image from Dockerfile context files"
428-
task "docker" => ["archives_docker", "dockerfile_full"] do
429-
build_docker_from_dockerfiles('full')
430-
end
431-
end
432-
433412
desc "Generate Dockerfile for wolfi images"
434413
task "dockerfile_wolfi" => ["prepare", "generate_build_metadata"] do
435414
puts("[dockerfiles] Building wolfi Dockerfiles")
436415
build_dockerfile('wolfi')
437416
end
438417

439-
namespace "dockerfile_wolfi" do
440-
desc "Build Wolfi Docker image from Dockerfile context files"
441-
task "docker" => ["archives_docker", "dockerfile_wolfi"] do
442-
build_docker_from_dockerfiles('wolfi')
443-
end
444-
end
445-
446418
desc "Generate build context for ironbank"
447419
task "dockerfile_ironbank" => ["prepare", "generate_build_metadata"] do
448420
puts("[dockerfiles] Building ironbank Dockerfiles")
@@ -469,30 +441,6 @@ namespace "artifact" do
469441
Rake::Task["artifact:archives_oss"].invoke
470442
end
471443

472-
task "build_docker_full" => [:generate_build_metadata] do
473-
Rake::Task["artifact:docker"].invoke
474-
Rake::Task["artifact:dockerfile_full"].invoke
475-
Rake::Task["artifact:dockerfile_full:docker"].invoke
476-
end
477-
478-
task "build_docker_oss" => [:generate_build_metadata] do
479-
Rake::Task["artifact:docker_oss"].invoke
480-
Rake::Task["artifact:dockerfile_oss"].invoke
481-
Rake::Task["artifact:dockerfile_oss:docker"].invoke
482-
end
483-
484-
task "build_docker_observabilitySRE" => [:generate_build_metadata] do
485-
Rake::Task["artifact:docker_observabilitySRE"].invoke
486-
Rake::Task["artifact:dockerfile_observabilitySRE"].invoke
487-
Rake::Task["artifact:dockerfile_observabilitySRE:docker"].invoke
488-
end
489-
490-
task "build_docker_wolfi" => [:generate_build_metadata] do
491-
Rake::Task["artifact:docker_wolfi"].invoke
492-
Rake::Task["artifact:dockerfile_wolfi"].invoke
493-
Rake::Task["artifact:dockerfile_wolfi:docker"].invoke
494-
end
495-
496444
task "generate_build_metadata" do
497445
require 'time'
498446
require 'tempfile'
@@ -927,27 +875,13 @@ namespace "artifact" do
927875
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),
928876
"RELEASE" => ENV["RELEASE"],
929877
"VERSION_QUALIFIER" => VERSION_QUALIFIER,
930-
"BUILD_DATE" => BUILD_DATE,
931-
"LOCAL_ARTIFACTS" => LOCAL_ARTIFACTS
878+
"BUILD_DATE" => BUILD_DATE
932879
}
933880
Dir.chdir("docker") do |dir|
934881
safe_system(env, "make build-from-local-#{flavor}-artifacts")
935882
end
936883
end
937884

938-
def build_docker_from_dockerfiles(flavor)
939-
env = {
940-
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),
941-
"RELEASE" => ENV["RELEASE"],
942-
"VERSION_QUALIFIER" => VERSION_QUALIFIER,
943-
"BUILD_DATE" => BUILD_DATE,
944-
"LOCAL_ARTIFACTS" => LOCAL_ARTIFACTS
945-
}
946-
Dir.chdir("docker") do |dir|
947-
safe_system(env, "make build-from-dockerfiles_#{flavor}")
948-
end
949-
end
950-
951885
def build_dockerfile(flavor)
952886
env = {
953887
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),

0 commit comments

Comments
 (0)