Skip to content

Commit

Permalink
Add elastic-agent-wolfi-complete Docker image (#5475)
Browse files Browse the repository at this point in the history
So, we have a Wolfi-based image with Synthetics.
  • Loading branch information
rdner authored Sep 11, 2024
1 parent ec4288e commit f8fd7a7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
18 changes: 12 additions & 6 deletions dev-tools/mage/dockervariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
)

const (
undefined = "undefined"
basic = "basic"
ubi = "ubi"
wolfi = "wolfi"
complete = "complete"
cloud = "cloud"
undefined = "undefined"
basic = "basic"
ubi = "ubi"
wolfi = "wolfi"
complete = "complete"
wolfiComplete = "wolfi-complete"
cloud = "cloud"
)

// DockerVariant defines the docker variant to build.
Expand All @@ -27,6 +28,7 @@ const (
Basic
UBI
Wolfi
WolfiComplete
Complete
Cloud
)
Expand All @@ -42,6 +44,8 @@ func (typ DockerVariant) String() string {
return ubi
case Wolfi:
return wolfi
case WolfiComplete:
return wolfiComplete
case Complete:
return complete
case Cloud:
Expand All @@ -67,6 +71,8 @@ func (typ *DockerVariant) UnmarshalText(text []byte) error {
*typ = UBI
case wolfi:
*typ = Wolfi
case wolfiComplete:
*typ = WolfiComplete
case complete:
*typ = Complete
case cloud:
Expand Down
28 changes: 28 additions & 0 deletions dev-tools/packaging/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ shared:
<<: *agent_docker_spec
docker_variant: 'complete'

- &agent_docker_wolfi_complete_spec
<<: *agent_docker_spec
docker_variant: 'wolfi-complete'

# Deb/RPM spec for community beats.
- &deb_rpm_spec
<<: *common
Expand Down Expand Up @@ -908,6 +912,18 @@ specs:
files:
'{{.BeatName}}{{.BinaryExt}}':
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
- os: linux
arch: amd64
types: [docker]
spec:
<<: *docker_wolfi_spec
<<: *docker_builder_spec
<<: *agent_docker_wolfi_complete_spec
<<: *docker_elastic_spec
<<: *elastic_license_for_binaries
files:
'{{.BeatName}}{{.BinaryExt}}':
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
- os: linux
arch: arm64
types: [docker]
Expand All @@ -920,6 +936,18 @@ specs:
files:
'{{.BeatName}}{{.BinaryExt}}':
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
- os: linux
arch: arm64
types: [docker]
spec:
<<: *docker_wolfi_arm_spec
<<: *docker_builder_arm_spec
<<: *agent_docker_wolfi_complete_spec
<<: *docker_elastic_spec
<<: *elastic_license_for_binaries
files:
'{{.BeatName}}{{.BinaryExt}}':
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
- os: linux
arch: amd64
types: [docker]
Expand Down
34 changes: 32 additions & 2 deletions dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ LABEL \
license="{{ .License }}" \
description="{{ .BeatDescription }}"

ENV ELASTIC_CONTAINER "true"
ENV ELASTIC_CONTAINER="true"
ENV PATH={{ $beatHome }}:$PATH
ENV GODEBUG="madvdontneed=1"

Expand Down Expand Up @@ -192,7 +192,7 @@ RUN echo \
ENV ELASTIC_SYNTHETICS_CAPABLE=true
ENV ELASTIC_AGENT_COMPLETE=true
ENV TZ=UTC
ENV NODE_VERSION=18.20.3
ENV NODE_VERSION=18.20.4
ENV PATH="$NODE_PATH/node/bin:$PATH"
# Install the latest version of @elastic/synthetics forcefully ignoring the previously
# cached node_modules, heartbeat then calls the global executable to run test suites
Expand Down Expand Up @@ -239,8 +239,38 @@ RUN for iter in {1..10}; do \
(exit $exit_code)
{{- end }}

{{- if (and (eq .Variant "wolfi-complete") (contains .from "wolfi")) }}
USER root
# Install required dependencies from wolfi repository
RUN for iter in {1..10}; do \
apk update && \
apk add --no-interactive --no-progress --no-cache nodejs-18=18.20.4-r0 npm=10.8.3-r0 glib dbus-glib libatk-1.0 \
libatk-bridge-2.0 cups-libs libxcomposite libxdamage libxrandr libxkbcommon pango alsa-lib \
font-opensans fontconfig gtk icu-data-full libnss mesa font-noto-cjk font-noto-emoji && \
exit_code=0 && break || exit_code=$? && echo "apk error: retry $iter in 10s" && sleep 10; \
done; \
(exit $exit_code)

# Setup synthetics env vars
ENV ELASTIC_SYNTHETICS_CAPABLE=true
ENV TZ=UTC
ENV NPM_CONFIG_PREFIX={{ $beatHome }}/.npm
ENV PATH="$NPM_CONFIG_PREFIX/bin:$PATH"

RUN echo \
$NPM_CONFIG_PREFIX \
{{ $beatHome }}/.config \
{{ $beatHome }}/.synthetics \
{{ $beatHome }}/.npm \
{{ $beatHome }}/.cache \
| xargs -IDIR sh -c 'mkdir -m 0770 -p DIR && chown -R {{ .user }} DIR'

USER {{ .user }}

RUN (npm i -g --loglevel verbose --production --engine-strict @elastic/synthetics@stack_release || sh -c 'tail -n +1 ${NPM_CONFIG_PREFIX}/_logs/* && exit 1')
{{- end }}

USER {{ .user }}

{{- range $i, $port := .ExposePorts }}
EXPOSE {{ $port }}
Expand Down

0 comments on commit f8fd7a7

Please sign in to comment.