Skip to content

Commit 3ae6299

Browse files
[9.0] (backport #18181) Remove redundant testing and circular dependency from docker acceptance testing (#18253)
* Remove redundant testing and circular dependency from docker acceptance testing (#18181) * 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) # Conflicts: # docker/Makefile # rakelib/artifacts.rake * resolve merge conflicts --------- Co-authored-by: Cas Donoghue <[email protected]>
1 parent ce27919 commit 3ae6299

File tree

4 files changed

+13
-74
lines changed

4 files changed

+13
-74
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: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,12 @@ public-dockerfiles_full: templates/Dockerfile.erb docker_paths $(COPY_FILES)
123123
version_tag="${VERSION_TAG}" \
124124
release="${RELEASE}" \
125125
image_flavor="full" \
126-
local_artifacts="false" \
126+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
127127
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-full" && \
128128
cd $(ARTIFACTS_DIR)/docker && \
129129
cp $(ARTIFACTS_DIR)/Dockerfile-full Dockerfile && \
130130
tar -zcf ../logstash-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
131131

132-
build-from-dockerfiles_full: public-dockerfiles_full
133-
cd $(ARTIFACTS_DIR)/docker && \
134-
mkdir -p dockerfile_build_full && cd dockerfile_build_full && \
135-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
136-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
137-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-full:$(VERSION_TAG) .
138-
139132
public-dockerfiles_oss: templates/Dockerfile.erb docker_paths $(COPY_FILES)
140133
../vendor/jruby/bin/jruby -S erb -T "-"\
141134
created_date="${BUILD_DATE}" \
@@ -144,19 +137,12 @@ public-dockerfiles_oss: templates/Dockerfile.erb docker_paths $(COPY_FILES)
144137
version_tag="${VERSION_TAG}" \
145138
release="${RELEASE}" \
146139
image_flavor="oss" \
147-
local_artifacts="false" \
140+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
148141
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-oss" && \
149142
cd $(ARTIFACTS_DIR)/docker && \
150143
cp $(ARTIFACTS_DIR)/Dockerfile-oss Dockerfile && \
151144
tar -zcf ../logstash-oss-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
152145

153-
build-from-dockerfiles_oss: public-dockerfiles_oss
154-
cd $(ARTIFACTS_DIR)/docker && \
155-
mkdir -p dockerfile_build_oss && cd dockerfile_build_oss && \
156-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
157-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
158-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-oss:$(VERSION_TAG) .
159-
160146
public-dockerfiles_wolfi: templates/Dockerfile.erb docker_paths $(COPY_FILES)
161147
../vendor/jruby/bin/jruby -S erb -T "-"\
162148
created_date="${BUILD_DATE}" \
@@ -165,19 +151,12 @@ public-dockerfiles_wolfi: templates/Dockerfile.erb docker_paths $(COPY_FILES)
165151
version_tag="${VERSION_TAG}" \
166152
release="${RELEASE}" \
167153
image_flavor="wolfi" \
168-
local_artifacts="false" \
154+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
169155
templates/Dockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-wolfi" && \
170156
cd $(ARTIFACTS_DIR)/docker && \
171157
cp $(ARTIFACTS_DIR)/Dockerfile-wolfi Dockerfile && \
172158
tar -zcf ../logstash-wolfi-$(VERSION_TAG)-docker-build-context.tar.gz Dockerfile bin config env2yaml pipeline
173159

174-
build-from-dockerfiles_wolfi: public-dockerfiles_wolfi
175-
cd $(ARTIFACTS_DIR)/docker && \
176-
mkdir -p dockerfile_build_wolfi && cd dockerfile_build_wolfi && \
177-
tar -zxf ../../logstash-$(VERSION_TAG)-docker-build-context.tar.gz && \
178-
sed 's/artifacts/snapshots/g' Dockerfile > Dockerfile.tmp && mv Dockerfile.tmp Dockerfile && \
179-
docker build --progress=plain --network=host -t $(IMAGE_TAG)-dockerfile-wolfi:$(VERSION_TAG) .
180-
181160
public-dockerfiles_ironbank: templates/hardening_manifest.yaml.erb templates/IronbankDockerfile.erb ironbank_docker_paths $(COPY_IRONBANK_FILES)
182161
../vendor/jruby/bin/jruby -S erb -T "-"\
183162
elastic_version="${ELASTIC_VERSION}" \
@@ -189,7 +168,7 @@ public-dockerfiles_ironbank: templates/hardening_manifest.yaml.erb templates/Iro
189168
version_tag="${VERSION_TAG}" \
190169
release="${RELEASE}" \
191170
image_flavor="ironbank" \
192-
local_artifacts="false" \
171+
local_artifacts="$(or $(LOCAL_ARTIFACTS),false)" \
193172
templates/IronbankDockerfile.erb > "${ARTIFACTS_DIR}/Dockerfile-ironbank" && \
194173
cd $(ARTIFACTS_DIR)/ironbank && \
195174
cp $(ARTIFACTS_DIR)/Dockerfile-ironbank Dockerfile && \

rakelib/artifacts.rake

Lines changed: 2 additions & 48 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"]
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
@@ -384,26 +384,12 @@ namespace "artifact" do
384384
build_dockerfile('full')
385385
end
386386

387-
namespace "dockerfile_full" do
388-
desc "Build Full Docker image from Dockerfile context files"
389-
task "docker" => ["archives_docker", "dockerfile_full"] do
390-
build_docker_from_dockerfiles('full')
391-
end
392-
end
393-
394387
desc "Generate Dockerfile for wolfi images"
395388
task "dockerfile_wolfi" => ["prepare", "generate_build_metadata"] do
396389
puts("[dockerfiles] Building wolfi Dockerfiles")
397390
build_dockerfile('wolfi')
398391
end
399392

400-
namespace "dockerfile_wolfi" do
401-
desc "Build Wolfi Docker image from Dockerfile context files"
402-
task "docker" => ["archives_docker", "dockerfile_wolfi"] do
403-
build_docker_from_dockerfiles('wolfi')
404-
end
405-
end
406-
407393
desc "Generate build context for ironbank"
408394
task "dockerfile_ironbank" => ["prepare", "generate_build_metadata"] do
409395
puts("[dockerfiles] Building ironbank Dockerfiles")
@@ -429,24 +415,6 @@ namespace "artifact" do
429415
Rake::Task["artifact:archives_oss"].invoke
430416
end
431417

432-
task "build_docker_full" => [:generate_build_metadata] do
433-
Rake::Task["artifact:docker"].invoke
434-
Rake::Task["artifact:dockerfile_full"].invoke
435-
Rake::Task["artifact:dockerfile_full:docker"].invoke
436-
end
437-
438-
task "build_docker_oss" => [:generate_build_metadata] do
439-
Rake::Task["artifact:docker_oss"].invoke
440-
Rake::Task["artifact:dockerfile_oss"].invoke
441-
Rake::Task["artifact:dockerfile_oss:docker"].invoke
442-
end
443-
444-
task "build_docker_wolfi" => [:generate_build_metadata] do
445-
Rake::Task["artifact:docker_wolfi"].invoke
446-
Rake::Task["artifact:dockerfile_wolfi"].invoke
447-
Rake::Task["artifact:dockerfile_wolfi:docker"].invoke
448-
end
449-
450418
task "generate_build_metadata" do
451419
require 'time'
452420
require 'tempfile'
@@ -826,27 +794,13 @@ namespace "artifact" do
826794
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),
827795
"RELEASE" => ENV["RELEASE"],
828796
"VERSION_QUALIFIER" => VERSION_QUALIFIER,
829-
"BUILD_DATE" => BUILD_DATE,
830-
"LOCAL_ARTIFACTS" => LOCAL_ARTIFACTS
797+
"BUILD_DATE" => BUILD_DATE
831798
}
832799
Dir.chdir("docker") do |dir|
833800
safe_system(env, "make build-from-local-#{flavor}-artifacts")
834801
end
835802
end
836803

837-
def build_docker_from_dockerfiles(flavor)
838-
env = {
839-
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),
840-
"RELEASE" => ENV["RELEASE"],
841-
"VERSION_QUALIFIER" => VERSION_QUALIFIER,
842-
"BUILD_DATE" => BUILD_DATE,
843-
"LOCAL_ARTIFACTS" => LOCAL_ARTIFACTS
844-
}
845-
Dir.chdir("docker") do |dir|
846-
safe_system(env, "make build-from-dockerfiles_#{flavor}")
847-
end
848-
end
849-
850804
def build_dockerfile(flavor)
851805
env = {
852806
"ARTIFACTS_DIR" => ::File.join(Dir.pwd, "build"),

0 commit comments

Comments
 (0)