Skip to content

Commit 6a3ca5e

Browse files
committed
feat: add nri-docker and right format to testing infra-agent oci repo
1 parent b4dc8e0 commit 6a3ca5e

File tree

1 file changed

+148
-17
lines changed

1 file changed

+148
-17
lines changed

.github/workflows/push_oci_artifact.yml

Lines changed: 148 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,100 @@
1+
# This action creates a new Testing Infra-agent OCI package version in the agent-control package registry
2+
#
3+
# The blob is a zip or tar containing:
4+
# - newrelic-infra (.exe)
5+
# - integrations/nri-docker (.exe)
6+
#
7+
# The format for this package is a multiplatform index and one manifest with the artifact blob for each architecture.
8+
# The created index will be as the following:
9+
#
10+
# {
11+
# "schemaVersion": 2,
12+
# "mediaType": "application/vnd.oci.image.index.v1+json",
13+
# "manifests": [
14+
# {
15+
# "mediaType": "application/vnd.oci.image.manifest.v1+json",
16+
# "digest": "sha256:9b34549b8f5002df0518b002c8ba0ddcb2e004dee988620642fe71ac8d05c780",
17+
# "size": 696,
18+
# "platform": {
19+
# "architecture": "amd64",
20+
# "os": "darwin"
21+
# },
22+
# "artifactType": "application/vnd.newrelic.agent.v1+tar"
23+
# }
24+
# [...]
25+
# }
26+
#
27+
# Then each of the different manifests for each artifact
28+
#
29+
# {
30+
# "schemaVersion": 2,
31+
# "mediaType": "application/vnd.oci.image.manifest.v1+json",
32+
# "artifactType": "application/vnd.newrelic.agent.v1+zip",
33+
# "config": {
34+
# "mediaType": "application/vnd.oci.image.config.v1+json",
35+
# "digest": "sha256:7758599fc4d06bd93a65bf28bc98fbff6c559a9a56be1ec3d75ff6aa8a8cfe6e",
36+
# "size": 39
37+
# },
38+
# "layers": [
39+
# {
40+
# "mediaType": "application/vnd.newrelic.agent.v1+zip",
41+
# "digest": "sha256:a66a406acbaf188f0f9a2b34464fc18c66bb45742894f23ca5f9ed65e6c5ad8c",
42+
# "size": 21676600,
43+
# "annotations": {
44+
# "com.newrelic.artifact.type": "binary",
45+
# "org.opencontainers.image.title": "newrelic-infra-amd64.zip",
46+
# "org.opencontainers.image.version": "1.71.3"
47+
# }
48+
# }
49+
# ],
50+
# "annotations": {
51+
# "org.opencontainers.image.created": "2026-01-12T14:33:18Z"
52+
# }
53+
# }
54+
#
55+
# We require the artifactType to know the type of the artifact (it's also present as mediaType in the layer but it's more
56+
# correct to also place it as artifactType )
57+
#
58+
# The required annotations are:
59+
# - image.title
60+
# - com.newrelic.artifact.type
61+
#
62+
# The other 2 annotations, org.opencontainers.image.version and org.opencontainers.image.created are for info purposes.
63+
#
64+
# When pushing the artifact with oras with --artifact-platform, the config will be populated with platform.ach and platform.os
65+
# that are needed when creating the oras index to have a multiarch registry.
66+
#
67+
# At the end the resulting registry will be:
68+
# TAG (ex v1.7.7) --> Index (Pointing to different manifest digests per os/arch) --> manifest (identified by digest) -> Blob
69+
170
name: OCI test repo - compile & push multi-platform testing-infra-agent
271
on:
372
workflow_dispatch:
473
inputs:
5-
tag:
74+
agent_version:
675
description: 'Version tag'
776
required: true
77+
nri_docker_version:
78+
description: 'Embedded docker version'
79+
required: false
80+
default: "2.6.6"
881

982
env:
1083
IMAGE_NAME: "testing-infra-agent"
1184
AGENT_VERSION: ${{ github.event.inputs.agent_version }}
85+
NRI_DOCKER_VERSION: ${{ github.event.inputs.nri_docker_version }}
1286

1387
jobs:
1488
build-and-push:
1589
runs-on: ubuntu-latest
1690
strategy:
1791
matrix:
1892
include:
19-
- { os: linux, arch: amd64, goos: linux, goarch: amd64, binary: newrelic-infra }
20-
- { os: linux, arch: arm64, goos: linux, goarch: arm64, binary: newrelic-infra }
21-
- { os: windows, arch: amd64, goos: windows, goarch: amd64, binary: newrelic-infra.exe }
22-
- { os: darwin, arch: arm64, goos: darwin, goarch: arm64, binary: newrelic-infra }
23-
- { os: darwin, arch: amd64, goos: darwin, goarch: amd64, binary: newrelic-infra }
93+
- { os: linux, arch: amd64, binary: newrelic-infra, format: tar }
94+
- { os: linux, arch: arm64, binary: newrelic-infra, format: tar }
95+
- { os: windows, arch: amd64, binary: newrelic-infra.exe, format: zip }
96+
- { os: darwin, arch: arm64, binary: newrelic-infra, format: tar }
97+
- { os: darwin, arch: amd64, binary: newrelic-infra, format: tar }
2498

2599
permissions:
26100
packages: write
@@ -38,9 +112,33 @@ jobs:
38112
with:
39113
go-version: '1.25.6'
40114

115+
- name: Download and Add nri-docker integration
116+
shell: bash
117+
run: |
118+
mkdir -p integrations
119+
120+
if [ "${{ matrix.os }}" = "windows" ]; then
121+
URL="https://download.newrelic.com/infrastructure_agent/binaries/windows/${{ matrix.arch }}/nri-docker-${{ matrix.arch }}.${{ env.NRI_DOCKER_VERSION }}.zip"
122+
curl -L -o nri-docker.zip "$URL"
123+
mkdir -p integrations-tmp
124+
unzip -j nri-docker.zip -d integrations-tmp/
125+
mv integrations-tmp/nri-docker.exe integrations/nri-docker.exe
126+
rm -rf integrations-tmp
127+
rm nri-docker.zip
128+
elif [ "${{ matrix.os }}" = "linux" ]; then
129+
URL="https://download.newrelic.com/infrastructure_agent/binaries/linux/${{ matrix.arch }}/nri-docker_linux_${{ env.NRI_DOCKER_VERSION }}_${{ matrix.arch }}.tar.gz"
130+
echo $URL
131+
curl -L -o nri-docker.tar.gz "$URL"
132+
mkdir -p integrations-tmp
133+
tar -xzf nri-docker.tar.gz -C integrations-tmp/ --strip-components=1
134+
mv integrations-tmp/var/db/newrelic-infra/newrelic-integrations/bin/nri-docker integrations/nri-docker
135+
rm -rf integrations-tmp
136+
rm nri-docker.tar.gz
137+
fi
138+
41139
- name: Compile Binary
42140
run: |
43-
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
141+
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build \
44142
-o ${{ matrix.binary }} \
45143
./cmd/newrelic-infra
46144
@@ -49,11 +147,11 @@ jobs:
49147
run: |
50148
if [ "${{ matrix.os }}" = "windows" ]; then
51149
FILENAME="newrelic-infra-${{ matrix.arch }}.zip"
52-
zip $FILENAME ${{ matrix.binary }}
150+
zip -r $FILENAME ${{ matrix.binary }} integrations/
53151
echo "mime=application/zip" >> $GITHUB_OUTPUT
54152
else
55153
FILENAME="newrelic-infra-${{ matrix.os }}-${{ matrix.arch }}.tar.gz"
56-
tar -cvzf $FILENAME ${{ matrix.binary }}
154+
tar -cvzf $FILENAME ${{ matrix.binary }} integrations/
57155
echo "mime=application/vnd.oci.image.layer.v1.tar+gzip" >> $GITHUB_OUTPUT
58156
fi
59157
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
@@ -65,9 +163,29 @@ jobs:
65163
run: |
66164
echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
67165
68-
oras push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.AGENT_VERSION }}-${{ matrix.os }}-${{ matrix.arch }} \
166+
cat <<EOF > layer_annotations.json
167+
{
168+
"${{ steps.package.outputs.filename }}": {
169+
"org.opencontainers.image.title": "${{ steps.package.outputs.filename }}",
170+
"org.opencontainers.image.version": "${{ env.AGENT_VERSION }}",
171+
"com.newrelic.artifact.type": "binary"
172+
}
173+
}
174+
EOF
175+
176+
DIGEST=$(oras push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} \
177+
--artifact-type application/vnd.newrelic.agent.v1+${{ matrix.format }} \
69178
--artifact-platform ${{ matrix.os }}/${{ matrix.arch }} \
70-
${{ steps.package.outputs.filename }}:${{ steps.package.outputs.mime }}
179+
--annotation-file layer_annotations.json \
180+
${{ steps.package.outputs.filename }}:application/vnd.newrelic.agent.v1+${{ matrix.format }} | grep "Digest:" | awk '{print $2}')
181+
182+
echo "$DIGEST" > digest-${{ matrix.os }}-${{ matrix.arch }}.txt
183+
184+
- name: Upload Digest Artifact
185+
uses: actions/upload-artifact@v4
186+
with:
187+
name: digest-${{ matrix.os }}-${{ matrix.arch }}
188+
path: digest-${{ matrix.os }}-${{ matrix.arch }}.txt
71189

72190
create-index:
73191
needs: build-and-push
@@ -78,15 +196,28 @@ jobs:
78196
- name: Install ORAS
79197
uses: oras-project/setup-oras@22ce207df3b08e061f537244349aac6ae1d214f6 # v1
80198

199+
- name: Download All Digests
200+
uses: actions/download-artifact@v4
201+
with:
202+
path: digests
203+
pattern: digest-*
204+
merge-multiple: true
205+
81206
- name: Create Multi-Platform Index
82207
run: |
83208
echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
84209
REPO="ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}"
85210
VERSION="${{ env.AGENT_VERSION }}"
211+
212+
# Combine all downloaded digests into a single string for the command
213+
# Each entry looks like REPO@sha256:xxxx
214+
DIGEST_LIST=""
215+
for f in digests/*.txt; do
216+
D=$(cat "$f")
217+
DIGEST_LIST="$DIGEST_LIST $REPO@$D"
218+
done
219+
220+
echo "Creating index for: $DIGEST_LIST"
86221
87-
oras manifest index create $REPO:v$VERSION \
88-
$REPO:$VERSION-linux-amd64 \
89-
$REPO:$VERSION-linux-arm64 \
90-
$REPO:$VERSION-windows-amd64 \
91-
$REPO:$VERSION-darwin-arm64 \
92-
$REPO:$VERSION-darwin-amd64
222+
# Create the single tagged index pointing to all anonymous platform manifests
223+
oras manifest index create $REPO:v$VERSION $DIGEST_LIST

0 commit comments

Comments
 (0)