Skip to content

Commit 0f7f287

Browse files
authored
Fix multiarch service image push from main to serverless (#10129)
* Create a manifest image and push to repository. * Change to only use docker for agentless publish. * Update secret_path. * Debug lines. * Try 3. * Fix digest variable. * Cleanups from code review.
1 parent a4704e8 commit 0f7f287

File tree

4 files changed

+80
-29
lines changed

4 files changed

+80
-29
lines changed

.buildkite/pipeline.agentless-app-release.yaml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
env:
22
VERSION: "${BUILDKITE_COMMIT:0:12}"
3+
4+
# This section is used to define the plugins that will be used in the pipeline.
5+
# See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins
6+
common:
7+
- docker_login_plugin: &docker_login_plugin
8+
elastic/vault-docker-login#v0.5.2:
9+
secret_path: 'kv/ci-shared/platform-ingest/elastic_docker_registry'
10+
311
steps:
4-
- label: "Mirror Elastic-Agent Snapshot DRA to internal registry"
5-
key: "mirror-elastic-agent"
6-
command: ".buildkite/scripts/steps/ecp-internal-release.sh"
12+
- label: "Packaging: Service Container linux/amd64"
13+
key: packaging-service-container-amd64
14+
env:
15+
PACKAGES: "docker"
16+
PLATFORMS: "linux/amd64"
17+
DOCKER_VARIANTS: "service"
18+
command: |
19+
.buildkite/scripts/steps/integration-package.sh
20+
artifact_paths:
21+
- "build/distributions/elastic-agent-service-git-*.docker.tar.gz"
722
agents:
8-
image: docker.elastic.co/ci-agent-images/serverless-helm-builder:0.0.2@sha256:d00e8a7a0ab3618cfaacb0a7b1e1b06ee29728eb2b44de602374bd8f6b9b92ac
23+
provider: "gcp"
24+
machineType: "c2-standard-16"
25+
diskSizeGb: 400
926

27+
- label: "Packaging: Service Container linux/arm64"
28+
key: packaging-service-container-arm64
29+
env:
30+
PACKAGES: "docker"
31+
PLATFORMS: "linux/arm64"
32+
DOCKER_VARIANTS: "service"
33+
command: |
34+
.buildkite/scripts/steps/integration-package.sh
35+
artifact_paths:
36+
- "build/distributions/elastic-agent-service-git-*.docker.tar.gz"
37+
agents:
38+
provider: "aws"
39+
instanceType: "t4g.2xlarge"
40+
imagePrefix: "core-ubuntu-2204-aarch64"
41+
diskSizeGb: 400
42+
43+
# wait for packaging to be done
44+
- wait: ~
1045

46+
- label: "Publish to internal registry"
47+
key: "mirror-elastic-agent"
48+
command: ".buildkite/scripts/steps/ecp-internal-release.sh"
49+
agents:
50+
provider: "gcp"
51+
machineType: "c2-standard-16"
52+
plugins:
53+
- *docker_login_plugin
1154

1255
# wait for metadata to be set
1356
- wait: ~

.buildkite/scripts/steps/ecp-internal-release.sh

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ set -eu
2020
_SELF=$(dirname $0)
2121
source "${_SELF}/../common.sh"
2222

23-
2423
# annotate create temp markdown file if not exists
2524
# this file will be later used to annotate the build
2625
# it appends to the file the message passed as argument
@@ -33,37 +32,39 @@ write_annotation() {
3332
cat $BUILDKITE_ANNOTATE_FILE | buildkite-agent annotate --style info
3433
}
3534

35+
BUILD_VERSION="$(jq -r '.version' .package-version)"
36+
DOCKER_TAG="git-${VERSION}"
3637
PRIVATE_REPO="docker.elastic.co/observability-ci/ecp-elastic-agent-service"
37-
SNAPSHOT_DRA_URL=https://snapshots.elastic.co/latest/master.json
38+
PRIVATE_IMAGE="${PRIVATE_REPO}:${DOCKER_TAG}"
3839

39-
DRA_RESULT=$(curl -s -X GET "$SNAPSHOT_DRA_URL")
40-
echo "$DRA_RESULT"
41-
BUILD_ID=$(echo "$DRA_RESULT" | jq '.build_id' | tr -d '"')
42-
BUILD_VERSION=$(echo "$DRA_RESULT" | jq '.version' | tr -d '"')
40+
# download the amd64 and arm64 builds of the image from the previous steps
41+
buildkite-agent artifact download "build/distributions/**" . --step "packaging-service-container-amd64"
42+
buildkite-agent artifact download "build/distributions/**" . --step "packaging-service-container-arm64"
4343

44-
MANIFEST_URL="https://snapshots.elastic.co/$BUILD_ID/agent-package/agent-artifacts-$BUILD_VERSION.json"
45-
GIT_COMMIT=$(curl -s -X GET "$MANIFEST_URL" | jq '.projects["elastic-agent-core"]["commit_hash"]' | tr -d '"')
46-
GIT_SHORT_COMMIT=$(echo "$GIT_COMMIT" | cut -c1-12)
44+
# AMD64
45+
docker load -i ./build/distributions/elastic-agent-service-$DOCKER_TAG-$BUILD_VERSION-linux-amd64.docker.tar.gz
46+
docker image tag "elastic-agent-service:$DOCKER_TAG" "$PRIVATE_IMAGE"
47+
docker push "$PRIVATE_IMAGE"
48+
AMD64_DIGEST=$(docker image inspect --format "{{index .RepoDigests 0}}" "$PRIVATE_IMAGE")
4749

48-
DOCKER_TAG="git-${GIT_SHORT_COMMIT}"
49-
PRIVATE_IMAGE="${PRIVATE_REPO}:${DOCKER_TAG}"
50+
# ARM64 (overwrites AMD64 tags)
51+
docker load -i ./build/distributions/elastic-agent-service-$DOCKER_TAG-$BUILD_VERSION-linux-arm64.docker.tar.gz
52+
docker image tag "elastic-agent-service:$DOCKER_TAG" "$PRIVATE_IMAGE"
53+
docker push "$PRIVATE_IMAGE"
54+
ARM64_DIGEST=$(docker image inspect --format "{{index .RepoDigests 0}}" "$PRIVATE_IMAGE")
5055

51-
# TODO: let's avoid accessing vault directly but use the vault plugin itself
52-
# https://github.com/elastic/vault-docker-login-buildkite-plugin does not support
53-
# the `skopeo` command by default but looks for the current installed tools in the runner
54-
# Let's contribute in a follow-up PR to support `skopeo` as well.
55-
DOCKER_REGISTRY_SECRET_PATH="kv/ci-shared/platform-ingest/docker_registry_prod"
56-
DOCKER_REGISTRY="docker.elastic.co"
57-
DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
58-
DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
59-
skopeo login --username "${DOCKER_USERNAME_SECRET}" --password "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}"
60-
skopeo copy --all "docker://docker.elastic.co/cloud-release/elastic-agent-service:$BUILD_ID-SNAPSHOT" "docker://$PRIVATE_IMAGE"
56+
# at this point the $PRIVATE_IMAGE is pointing to only the arm64 based image, we need the image to
57+
# be a multi-architecture based image so we create an image from the digests and tag it the same and
58+
# push it to the registry (aka. make the tag now a multi-architecture based image)
59+
docker buildx imagetools create -t "$PRIVATE_IMAGE" \
60+
"$AMD64_DIGEST" \
61+
"$ARM64_DIGEST"
62+
docker push "$PRIVATE_IMAGE"
6163

6264
annotate "* Image: $PRIVATE_IMAGE"
63-
annotate "* Short commit: $GIT_SHORT_COMMIT"
64-
annotate "* Commit: https://github.com/elastic/elastic-agent/commit/$GIT_COMMIT"
65-
annotate "* Manifest: $MANIFEST_URL"
65+
annotate "* Short commit: $VERSION"
66+
annotate "* Commit: https://github.com/elastic/elastic-agent/commit/$VERSION"
6667

67-
buildkite-agent meta-data set "git-short-commit" "$GIT_SHORT_COMMIT"
68+
buildkite-agent meta-data set "git-short-commit" "$VERSION"
6869

6970
write_annotation

.buildkite/scripts/steps/integration-package.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ set -euo pipefail
33

44
source .buildkite/scripts/common.sh
55

6+
# This script is not only used by integration CI, but also the agentless release pipeline to build the docker images
7+
# that get released to serverless. USE_PACKAGE_VERSION is important here for both CI and agentless, as it validates
8+
# that the components bundled to serverless are the same components that the CI validated.
9+
#
10+
# Making a change here can affect the released images to agentless, so be cautious.
11+
612
export SNAPSHOT="true"
713
export EXTERNAL="true"
814
export USE_PACKAGE_VERSION="true"

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Sub-directories/files ownership. Remember that order matters; the last matching pattern takes the most precedence.
88
/.buildkite @elastic/elastic-agent-control-plane @elastic/observablt-ci
99
/.ci @elastic/elastic-agent-control-plane @elastic/observablt-ci
10+
/.ci/scripts/ecp-internal-release.sh @elastic/elastic-agent-control-plane
1011
/.ci/scripts/update-otel.sh @elastic/elastic-agent-control-plane
1112
/.github @elastic/elastic-agent-control-plane @elastic/observablt-ci
1213
/.github/CODEOWNERS @elastic/ingest-tech-lead

0 commit comments

Comments
 (0)