Skip to content

OCI test repo - compile & push multi-platform testing-infra-agent #49

OCI test repo - compile & push multi-platform testing-infra-agent

OCI test repo - compile & push multi-platform testing-infra-agent #49

# This action creates a new Testing Infra-agent OCI package version in the agent-control GitHub's package registry.
#
# The blob is a zip or tar containing:
# - newrelic-infra (.exe)
# - integrations/nri-docker (.exe)
#
# More information about our expected oci package registry in:
# https://github.com/newrelic/newrelic-agent-control/docs/oci-packages/README.md
#
name: OCI test repo - compile & push multi-platform testing-infra-agent
on:
workflow_dispatch:
inputs:
agent_version:
description: 'Version tag'
required: true
nri_docker_version:
description: 'Embedded docker version'
required: false
default: "2.6.6"
env:
IMAGE_NAME: "testing-infra-agent"
AGENT_VERSION: ${{ github.event.inputs.agent_version }}
NRI_DOCKER_VERSION: ${{ github.event.inputs.nri_docker_version }}
jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { os: linux, arch: amd64, binary: newrelic-infra, format: tar }
- { os: linux, arch: arm64, binary: newrelic-infra, format: tar }
- { os: windows, arch: amd64, binary: newrelic-infra.exe, format: zip }
- { os: windows, arch: arm64, binary: newrelic-infra.exe, format: zip }
- { os: darwin, arch: arm64, binary: newrelic-infra, format: tar }
- { os: darwin, arch: amd64, binary: newrelic-infra, format: tar }
permissions:
packages: write
contents: read
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
repository: newrelic/infrastructure-agent
ref: ${{ env.AGENT_VERSION }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Download and Add nri-docker integration
shell: bash
run: |
mkdir -p integrations
if [ "${{ matrix.os }}" = "windows" ]; then
# we always package amd64 docker because arm64 doesn't exist.
URL="https://download.newrelic.com/infrastructure_agent/binaries/windows/amd64/nri-docker-amd64.${{ env.NRI_DOCKER_VERSION }}.zip"
curl -L -o nri-docker.zip "$URL"
unzip -j nri-docker.zip '*/nri-docker.exe' -d integrations
rm nri-docker.zip
elif [ "${{ matrix.os }}" = "linux" ]; then
URL="https://download.newrelic.com/infrastructure_agent/binaries/linux/${{ matrix.arch }}/nri-docker_linux_${{ env.NRI_DOCKER_VERSION }}_${{ matrix.arch }}.tar.gz"
echo $URL
curl -L -o nri-docker.tar.gz "$URL"
tar -xzf nri-docker.tar.gz --strip-components=6 -C integrations '*/nri-docker'
rm nri-docker.tar.gz
fi
- name: Compile Binary
run: |
# force amd64 if OS is windows because compiling infra arm64 is unsupported
GOARCH_VALUE=${{ matrix.os == 'windows' && 'amd64' || matrix.arch }}
GOOS=${{ matrix.os }} GOARCH=$GOARCH_VALUE go build \
-o ${{ matrix.binary }} \
./cmd/newrelic-infra
- name: Package Artifact
id: package
run: |
if [ "${{ matrix.os }}" = "windows" ]; then
FILENAME="newrelic-infra-${{ matrix.arch }}.zip"
zip -r $FILENAME ${{ matrix.binary }} integrations/
echo "mime=application/zip" >> $GITHUB_OUTPUT
else
FILENAME="newrelic-infra-${{ matrix.os }}-${{ matrix.arch }}.tar.gz"
tar -cvzf $FILENAME ${{ matrix.binary }} integrations/
echo "mime=application/vnd.oci.image.layer.v1.tar+gzip" >> $GITHUB_OUTPUT
fi
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
- name: Install ORAS
uses: oras-project/setup-oras@v1
- name: Push Platform Tag
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
cat <<EOF > layer_annotations.json
{
"${{ steps.package.outputs.filename }}": {
"org.opencontainers.image.title": "${{ steps.package.outputs.filename }}",
"org.opencontainers.image.version": "${{ env.AGENT_VERSION }}",
"com.newrelic.artifact.type": "binary"
}
}
EOF
DIGEST=$(oras push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} \
--artifact-type application/vnd.newrelic.agent.v1+${{ matrix.format }} \
--artifact-platform ${{ matrix.os }}/${{ matrix.arch }} \
--annotation-file layer_annotations.json \
${{ steps.package.outputs.filename }}:application/vnd.newrelic.agent.v1+${{ matrix.format }} | grep "Digest:" | awk '{print $2}')
echo "$DIGEST" > digest-${{ matrix.os }}-${{ matrix.arch }}.txt
- name: Upload Digest Artifact
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.os }}-${{ matrix.arch }}
path: digest-${{ matrix.os }}-${{ matrix.arch }}.txt
create-index:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Install ORAS
uses: oras-project/setup-oras@v1
- name: Download All Digests
uses: actions/download-artifact@v4
with:
path: digests
pattern: digest-*
merge-multiple: true
- name: Create Multi-Platform Index
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
REPO="ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}"
VERSION="${{ env.AGENT_VERSION }}"
# Combine all downloaded digests into a single string for the command
# Each entry looks like REPO@sha256:xxxx
DIGEST_LIST=""
for f in digests/*.txt; do
D=$(cat "$f")
DIGEST_LIST="$DIGEST_LIST $REPO@$D"
done
echo "Creating index for: $DIGEST_LIST"
# Create the single tagged index pointing to all anonymous platform manifests
oras manifest index create $REPO:v$VERSION $DIGEST_LIST