Skip to content

Commit 0c99b52

Browse files
EDOT and Slim docker images added (#7173) (#7466)
* EDOT and Slim docker images added * lint * fix arm * Update pkg/testing/kubernetes/supported.go Co-authored-by: Craig MacKenzie <[email protected]> * edot separate dockerfile template * verbose test * verbose test * fixed package-test conflict * condition * dockers len check * name in packages.yml * merged into same dockerfile again * merged into same dockerfile again * agent package version * agent package version * rename and a bit of refactor * change images * Revert "change images" This reverts commit 4d641bb. * revert helm changes * helm * feat: utilise edot-related images in otel k8s integration tests * fix: download all docker artifacts in k8s integration steps * Revert "helm" This reverts commit eee5fe6. * feat: introduce new k8s integration test for edot and edot-wolfi images * fix: overwrite env var of values.yaml * feat: add slim and slim-wolfi images in k8s integration tests * fix: static image repository for upgrading managed agent helm test * fix: static string value for OVERWRITE_ENV_VAR * fix: apply docker image size checks only for built variants --------- Co-authored-by: Craig MacKenzie <[email protected]> Co-authored-by: Panos Koutsovasilis <[email protected]> (cherry picked from commit 93a7d4c) Co-authored-by: Michal Pristas <[email protected]>
1 parent 5bcaa9d commit 0c99b52

File tree

13 files changed

+525
-25
lines changed

13 files changed

+525
-25
lines changed

.buildkite/bk.integration.pipeline.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ steps:
260260
DOCKER_VARIANTS: "{{matrix.variants}}"
261261
TARGET_ARCH: "amd64"
262262
command: |
263-
buildkite-agent artifact download build/distributions/elastic-agent-*-linux-amd64.docker.tar.gz . --step 'packaging-containers-x86-64'
263+
buildkite-agent artifact download build/distributions/*-linux-amd64.docker.tar.gz . --step 'packaging-containers-x86-64'
264264
.buildkite/scripts/steps/integration_tests_tf.sh kubernetes false
265265
artifact_paths:
266266
- build/**
@@ -276,7 +276,8 @@ steps:
276276
matrix:
277277
setup:
278278
variants:
279-
- "basic,wolfi,complete,complete-wolfi,service,cloud"
279+
- "basic,slim,complete,service,elastic-otel-collector"
280+
- "wolfi,slim-wolfi,complete-wolfi,elastic-otel-collector-wolfi"
280281
version:
281282
- v1.27.16
282283
- v1.28.9

.buildkite/scripts/buildkite-k8s-integration-tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ for variant in "${docker_variants[@]}"; do
4949
image_archive="elastic-agent-${variant}-${AGENT_VERSION}-linux-${TARGET_ARCH}.docker.tar.gz"
5050
if [[ "${variant}" == "basic" ]]; then
5151
image_archive="elastic-agent-${AGENT_VERSION}-linux-${TARGET_ARCH}.docker.tar.gz"
52+
elif [[ "${variant}" == "elastic-otel-collector" ]]; then
53+
image_archive="elastic-otel-collector-${AGENT_VERSION}-linux-${TARGET_ARCH}.docker.tar.gz"
54+
elif [[ "${variant}" == "elastic-otel-collector-wolfi" ]]; then
55+
image_archive="elastic-otel-collector-wolfi-${AGENT_VERSION}-linux-${TARGET_ARCH}.docker.tar.gz"
5256
fi
5357
image_archive_path="${DOCKER_IMAGE_ARCHIVES_DIR}/$image_archive"
5458

dev-tools/mage/copy.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import (
1313
"regexp"
1414
)
1515

16+
type SkipFn func(string) bool
17+
1618
// Copy copies a file or a directory (recursively) and preserves the permissions.
1719
func Copy(src, dest string) error {
18-
copy := &CopyTask{Source: src, Dest: dest}
20+
return CopyWithCheck(src, dest, nil)
21+
}
22+
23+
func CopyWithCheck(src, dest string, skipFn SkipFn) error {
24+
copy := &CopyTask{Source: src, Dest: dest, skipFn: skipFn}
1925
return copy.Execute()
2026
}
2127

@@ -27,6 +33,7 @@ type CopyTask struct {
2733
DirMode os.FileMode // Mode to use for copied dirs. Defaults to preserve permissions.
2834
Exclude []string // Exclude paths that match these regular expressions.
2935
excludes []*regexp.Regexp // Compiled exclude regexes.
36+
skipFn SkipFn // external check, returns true if we skip
3037
}
3138

3239
// Execute executes the copy and returns an error of there is a failure.
@@ -63,6 +70,15 @@ func (t *CopyTask) isExcluded(src string) bool {
6370
return true
6471
}
6572
}
73+
74+
return false
75+
}
76+
77+
func (t *CopyTask) isDestinationExcluded(dst string) bool {
78+
if t.skipFn != nil {
79+
return t.skipFn(dst)
80+
}
81+
6682
return false
6783
}
6884

@@ -78,6 +94,10 @@ func (t *CopyTask) fileCopy(src, dest string, entry fs.DirEntry) error {
7894
return nil
7995
}
8096

97+
if t.isDestinationExcluded(dest) {
98+
return nil
99+
}
100+
81101
srcFile, err := os.Open(src)
82102
if err != nil {
83103
return err

dev-tools/mage/dockerbuilder.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import (
1818
"strings"
1919
"time"
2020

21+
"github.com/elastic/elastic-agent/internal/pkg/agent/install"
22+
"github.com/elastic/elastic-agent/pkg/component"
23+
2124
"github.com/magefile/mage/sh"
2225
)
2326

@@ -103,8 +106,35 @@ func (b *dockerBuilder) exposePorts() []string {
103106

104107
func (b *dockerBuilder) copyFiles() error {
105108
for _, f := range b.Files {
109+
source := f.Source
110+
var checkFn func(string) bool
106111
target := filepath.Join(b.beatDir, f.Target)
107-
if err := Copy(f.Source, target); err != nil {
112+
113+
if f.ExpandSpec {
114+
specFilename := filepath.Base(source)
115+
specContent, err := os.ReadFile(source)
116+
if err != nil {
117+
if os.IsNotExist(err) {
118+
return nil
119+
}
120+
return fmt.Errorf("failed reading spec file for component %q: %w", specFilename, err)
121+
}
122+
123+
// create filter
124+
allowedPaths, err := component.ParseComponentFiles(specContent, specFilename, true)
125+
if err != nil {
126+
return fmt.Errorf("failed computing component files %q: %w", specFilename, err)
127+
}
128+
checkFn, err = install.SkipComponentsPathWithSubpathsFn(allowedPaths)
129+
if err != nil {
130+
return fmt.Errorf("failed compiling skip fn %q: %w", specFilename, err)
131+
}
132+
133+
source = filepath.Dir(source) // change source to components directory
134+
target = filepath.Dir(target) // target pointing to spec file
135+
}
136+
137+
if err := CopyWithCheck(source, target, checkFn); err != nil {
108138
if f.SkipOnMissing && errors.Is(err, os.ErrNotExist) {
109139
continue
110140
}

dev-tools/mage/dockervariants.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import (
1010
)
1111

1212
const (
13-
undefined = "undefined"
14-
basic = "basic"
15-
ubi = "ubi"
16-
wolfi = "wolfi"
17-
complete = "complete"
18-
completeWolfi = "complete-wolfi"
19-
cloud = "cloud"
20-
service = "service"
13+
undefined = "undefined"
14+
basic = "basic"
15+
ubi = "ubi"
16+
wolfi = "wolfi"
17+
complete = "complete"
18+
completeWolfi = "complete-wolfi"
19+
cloud = "cloud"
20+
service = "service"
21+
edotCollector = "elastic-otel-collector"
22+
slim = "slim"
23+
edotCollectorWolfi = "elastic-otel-collector-wolfi"
24+
slimWolfi = "slim-wolfi"
2125
)
2226

2327
// DockerVariant defines the docker variant to build.
@@ -33,6 +37,10 @@ const (
3337
Complete
3438
Cloud
3539
Service
40+
EdotCollector
41+
Slim
42+
EdotCollectorWolfi
43+
SlimWolfi
3644
)
3745

3846
// String returns the name of the docker variant type.
@@ -54,6 +62,14 @@ func (typ DockerVariant) String() string {
5462
return cloud
5563
case Service:
5664
return service
65+
case EdotCollector:
66+
return edotCollector
67+
case Slim:
68+
return slim
69+
case EdotCollectorWolfi:
70+
return edotCollectorWolfi
71+
case SlimWolfi:
72+
return slimWolfi
5773
default:
5874
return invalid
5975
}
@@ -83,6 +99,14 @@ func (typ *DockerVariant) UnmarshalText(text []byte) error {
8399
*typ = Cloud
84100
case service:
85101
*typ = Service
102+
case edotCollector:
103+
*typ = EdotCollector
104+
case slim:
105+
*typ = Slim
106+
case edotCollectorWolfi:
107+
*typ = EdotCollectorWolfi
108+
case slimWolfi:
109+
*typ = SlimWolfi
86110
default:
87111
return fmt.Errorf("unknown docker variant: %v", string(text))
88112
}

dev-tools/mage/pkgtypes.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ type PackageSpec struct {
115115
localPostRmScript string
116116
}
117117

118+
// add new prop into package file called expand spc
119+
// expand spec is checked during packaging and expands to multiple files
120+
// if expand is not present file is copied normally
121+
118122
// PackageFile represents a file or directory within a package.
119123
type PackageFile struct {
120124
Source string `yaml:"source,omitempty"` // Regular source file or directory.
@@ -129,6 +133,7 @@ type PackageFile struct {
129133
Owner string `yaml:"owner,omitempty"` // File Owner, for user and group name (rpm only).
130134
SkipOnMissing bool `yaml:"skip_on_missing,omitempty"` // Prevents build failure if the file is missing.
131135
Symlink bool `yaml:"symlink"` // Symlink marks file as a symlink pointing from target to source.
136+
ExpandSpec bool `yaml:"expand_spec,omitempty"` // Optional
132137
}
133138

134139
// OSArchNames defines the names of architectures for use in packages.
@@ -481,9 +486,13 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec {
481486
// ImageName computes the image name from the spec.
482487
func (s PackageSpec) ImageName() string {
483488
if s.DockerVariant == Basic {
489+
return s.Name
490+
}
491+
if s.DockerVariant == EdotCollector || s.DockerVariant == EdotCollectorWolfi {
484492
// no suffix for basic docker variant
485493
return s.Name
486494
}
495+
487496
return fmt.Sprintf("%s-%s", s.Name, s.DockerVariant)
488497
}
489498

0 commit comments

Comments
 (0)