Skip to content

Commit 22f2166

Browse files
authored
ci: build and push Docker image based on Chainguard base image (#3623)
1 parent a2840eb commit 22f2166

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

.github/workflows/snapshot.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,38 @@ jobs:
7575
with:
7676
subject-path: "${{ github.workspace }}/**/target/*.jar"
7777

78-
- if: ${{ failure() }}
78+
build-docker-images:
79+
name: "Build docker images"
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v4
83+
- uses: elastic/apm-pipeline-library/.github/actions/docker-login@current
84+
with:
85+
registry: docker.elastic.co
86+
secret: secret/apm-team/ci/docker-registry/prod
87+
url: ${{ secrets.VAULT_ADDR }}
88+
roleId: ${{ secrets.VAULT_ROLE_ID }}
89+
secretId: ${{ secrets.VAULT_SECRET_ID }}
90+
- name: prepare context for testing docker build
91+
run: |
92+
mkdir -p elastic-apm-agent/target
93+
curl -L -s -o elastic-apm-agent/target/elastic-apm-agent-1.49.0.jar \
94+
"https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.apm&a=elastic-apm-agent&v=1.49.0"
95+
- name: "Build docker image"
96+
run: ./scripts/docker-release/build_docker.sh "test"
97+
98+
notify:
99+
needs:
100+
- build-docker-images
101+
- deploy
102+
- validate
103+
runs-on: ubuntu-latest
104+
steps:
105+
- id: check
106+
uses: elastic/apm-pipeline-library/.github/actions/check-dependent-jobs@current
107+
with:
108+
needs: ${{ toJSON(needs) }}
109+
- if: ${{ failure() && ! inputs.dry_run }}
79110
uses: elastic/apm-pipeline-library/.github/actions/slack-message@current
80111
with:
81112
url: ${{ secrets.VAULT_ADDR }}

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,14 @@ docker.elastic.co and are located in the `observability` namespace.
330330

331331
For example, to download the v1.12.0 of the agent, use the following:
332332

333+
```bash
334+
docker pull docker.elastic.co/observability/apm-agent-java:1.12.0
333335
```
334-
docker pull docker.elastic.co/observability/apm-agent-java:1.12.0
336+
337+
In addition, you can use the `wolfi` version by adding the suffix `-wolfi`
338+
339+
```bash
340+
docker pull docker.elastic.co/observability/apm-agent-java:1.12.0-wolfi
335341
```
336342

337343
#### Creating images for a Release

Dockerfile.wolfi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM docker.elastic.co/wolfi/chainguard-base@sha256:9f940409f96296ef56140bcc4665c204dd499af4c32c96cc00e792558097c3f1
2+
RUN mkdir /usr/agent
3+
ARG JAR_FILE
4+
ARG HANDLER_FILE
5+
COPY ${JAR_FILE} /usr/agent/elastic-apm-agent.jar
6+
COPY ${HANDLER_FILE} /usr/agent/elastic-apm-handler
7+
RUN chmod +x /usr/agent/elastic-apm-handler

scripts/docker-release/build_docker.sh

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ readonly SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
1818
readonly PROJECT_ROOT=$SCRIPT_PATH/../../
1919
readonly NAMESPACE="observability"
2020

21-
if [ "$(ls -A ${PROJECT_ROOT}elastic-apm-agent/target/*.jar)" ]
21+
FILE=$(ls -A ${PROJECT_ROOT}elastic-apm-agent/target/*.jar | grep -E "elastic-apm-agent-[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?.jar" )
22+
23+
if [ -n "${FILE}" ]
2224
then
2325
# We have build files to use
2426
echo "INFO: Found local build artifact. Using locally built for Docker build"
25-
find -E ${PROJECT_ROOT}elastic-apm-agent/target -regex '.*/elastic-apm-agent-[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?.jar' -exec cp {} ${PROJECT_ROOT}apm-agent-java.jar \; || echo "INFO: No locally built image found"
27+
cp "${FILE}" "${PROJECT_ROOT}apm-agent-java.jar" || echo "INFO: No locally built image found"
2628
elif [ ! -z ${SONATYPE_FALLBACK+x} ]
2729
then
2830
echo "INFO: No local build artifact and SONATYPE_FALLBACK. Falling back to downloading artifact from Sonatype Nexus repository for version $RELEASE_VERSION"
@@ -37,19 +39,27 @@ then
3739
exit 1
3840
fi
3941

40-
echo "INFO: Starting Docker build for version $RELEASE_VERSION"
42+
ls -l apm-agent-java.jar
4143

42-
docker build -t docker.elastic.co/$NAMESPACE/apm-agent-java:$RELEASE_VERSION \
43-
--platform linux/amd64 \
44-
--build-arg JAR_FILE=apm-agent-java.jar \
45-
--build-arg HANDLER_FILE=apm-agent-lambda-layer/src/main/assembly/elastic-apm-handler .
44+
echo "INFO: Starting Docker build for version $RELEASE_VERSION"
45+
for DOCKERFILE in "Dockerfile" "Dockerfile.wolfi" ; do
46+
DOCKER_TAG=$RELEASE_VERSION
47+
if [[ $DOCKERFILE =~ "wolfi" ]]; then
48+
DOCKER_TAG="${RELEASE_VERSION}-wolfi"
49+
fi
50+
docker build -t docker.elastic.co/$NAMESPACE/apm-agent-java:$DOCKER_TAG \
51+
--platform linux/amd64 \
52+
--build-arg JAR_FILE=apm-agent-java.jar \
53+
--build-arg HANDLER_FILE=apm-agent-lambda-layer/src/main/assembly/elastic-apm-handler \
54+
--file $DOCKERFILE .
4655

47-
if [ $? -eq 0 ]
48-
then
49-
echo "INFO: Docker image built successfully"
50-
else
51-
echo "ERROR: Problem building Docker image!"
52-
fi
56+
if [ $? -eq 0 ]
57+
then
58+
echo "INFO: Docker image built successfully"
59+
else
60+
echo "ERROR: Problem building Docker image!"
61+
fi
62+
done
5363

5464
function finish {
5565

scripts/docker-release/push_docker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly DOCKER_PUSH_IMAGE_LATEST="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:lates
3232
echo "INFO: Pushing image $DOCKER_PUSH_IMAGE to $DOCKER_REGISTRY_URL"
3333

3434
docker push $DOCKER_PUSH_IMAGE || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
35+
docker push "${DOCKER_PUSH_IMAGE}-wolfi" || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
3536

3637
readonly LATEST_TAG=$(git tag --list --sort=version:refname "v*" | grep -v RC | sed s/^v// | tail -n 1)
3738

@@ -40,4 +41,6 @@ then
4041
echo "INFO: Current version ($RELEASE_VERSION) is the latest version. Tagging and pushing $DOCKER_PUSH_IMAGE_LATEST ..."
4142
docker tag $DOCKER_PUSH_IMAGE $DOCKER_PUSH_IMAGE_LATEST
4243
docker push $DOCKER_PUSH_IMAGE_LATEST || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
44+
docker tag "${DOCKER_PUSH_IMAGE}-wolfi" "${DOCKER_PUSH_IMAGE_LATEST}-wolfi"
45+
docker push "${DOCKER_PUSH_IMAGE_LATEST}-wolfi" || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
4346
fi

0 commit comments

Comments
 (0)