From fa4013a1cbcf831d609a6e68c7aed44424ebd8ed Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 4 Sep 2024 15:52:48 +0200 Subject: [PATCH 1/3] Add container automation for autoinstrumentation. For use with the OpenTelemetry k8s Operator --- .github/workflows/release.yml | 43 +++++++++++++++++++++++++++++++++++ DockerFile | 21 +++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 DockerFile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1d9e493..b97a8ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,8 @@ jobs: outputs: agent-version: ${{ steps.bootstrap.outputs.agent-version }} major-version: ${{ steps.bootstrap.outputs.major-version }} + env: + DOCKER_IMAGE_NAME: "docker.elastic.co/observability/elastic-otel-dotnet" steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace @@ -57,6 +59,47 @@ jobs: - name: Release to Nuget (only for release events) if: ${{ github.event_name == 'release' }} run: dotnet nuget push '${{ env.RELEASE_PACKAGES }}' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols + + - name: Log in to the Elastic Container registry + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }} + username: ${{ secrets.ELASTIC_DOCKER_USERNAME }} + password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) + id: docker-meta + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 + with: + images: ${{ env.DOCKER_IMAGE_NAME }} + flavor: | + latest=auto + tags: | + # "1.2.3" and "latest" Docker tags on push of git tag "v1.2.3" + type=semver,pattern={{version}},value=${{ steps.bootstrap.outputs.agent-version }} + # "edge" Docker tag on git push to default branch + type=edge + + - name: Build and Push Profiler Docker Image + id: docker-push + continue-on-error: true # continue for now until we see it working in action + uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 # v6.5.0 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.docker-meta.outputs.tags }} + labels: ${{ steps.docker-meta.outputs.labels }} + + - name: Attest image + uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 + continue-on-error: true # continue for now until we see it working in action + with: + subject-name: ${{ env.DOCKER_IMAGE_NAME }} + subject-digest: ${{ steps.docker-push.outputs.digest }} + push-to-registry: true - if: ${{ success() && github.event_name == 'release' }} uses: elastic/oblt-actions/slack/send@v1.12.1 diff --git a/DockerFile b/DockerFile new file mode 100644 index 0000000..8f7d01f --- /dev/null +++ b/DockerFile @@ -0,0 +1,21 @@ +# Based on the opentelemetry dotnet operator image: +# https://github.com/open-telemetry/opentelemetry-operator/blob/main/autoinstrumentation/dotnet/Dockerfile +# To build locally you need to call: +# - ./build.sh redistribute +# This ensures the distribution is locally available under .artifacts/elastic-distribution + +FROM busybox as downloader + +WORKDIR /autoinstrumentation + +COPY ".artifacts/elastic-distribution/elastic-dotnet-instrumentation-linux-glibc-x64.zip" . +COPY ".artifacts/elastic-distribution/elastic-dotnet-instrumentation-linux-musl-x64.zip" . + +RUN unzip elastic-dotnet-instrumentation-linux-glibc-x64.zip &&\ + unzip elastic-dotnet-instrumentation-linux-musl-x64.zip "linux-musl-x64/*" -d . &&\ + rm elastic-dotnet-instrumentation-linux-glibc-x64.zip elastic-dotnet-instrumentation-linux-musl-x64.zip &&\ + chmod -R go+r . + +FROM busybox + +COPY --from=downloader /autoinstrumentation /autoinstrumentation \ No newline at end of file From a21160694fb4a115a7f3c1582bf4518323277897 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 4 Sep 2024 15:56:46 +0200 Subject: [PATCH 2/3] move release targets after container push --- .github/workflows/release.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b97a8ac..6581eec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,27 +39,17 @@ jobs: - name: List distributions run: ls -al ${{ env.RELEASE_DISTRO }} - + - name: Generate build provenance (Distribution) uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 with: subject-path: "${{ github.workspace }}/${{ env.RELEASE_DISTRO }}" - + - name: Generate build provenance (Packages) uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 with: subject-path: "${{ github.workspace }}/${{ env.RELEASE_PACKAGES }}" - - - name: Attach Distribution to release - if: ${{ github.event_name == 'release' }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release upload ${{ github.ref_name }} ${{ env.RELEASE_DISTRO }} - - name: Release to Nuget (only for release events) - if: ${{ github.event_name == 'release' }} - run: dotnet nuget push '${{ env.RELEASE_PACKAGES }}' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols - - name: Log in to the Elastic Container registry uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 with: @@ -79,7 +69,7 @@ jobs: type=semver,pattern={{version}},value=${{ steps.bootstrap.outputs.agent-version }} # "edge" Docker tag on git push to default branch type=edge - + - name: Build and Push Profiler Docker Image id: docker-push continue-on-error: true # continue for now until we see it working in action @@ -101,6 +91,16 @@ jobs: subject-digest: ${{ steps.docker-push.outputs.digest }} push-to-registry: true + - name: Attach Distribution to release + if: ${{ github.event_name == 'release' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.ref_name }} ${{ env.RELEASE_DISTRO }} + + - name: Release to Nuget (only for release events) + if: ${{ github.event_name == 'release' }} + run: dotnet nuget push '${{ env.RELEASE_PACKAGES }}' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols + - if: ${{ success() && github.event_name == 'release' }} uses: elastic/oblt-actions/slack/send@v1.12.1 with: From 063e479781f87e7243adcbe887a7518eee9d0079 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 4 Sep 2024 16:08:00 +0200 Subject: [PATCH 3/3] add more label metadata to image --- .github/workflows/release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6581eec..9497134 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,6 +69,10 @@ jobs: type=semver,pattern={{version}},value=${{ steps.bootstrap.outputs.agent-version }} # "edge" Docker tag on git push to default branch type=edge + labels: | + org.opencontainers.image.title=elastic-otel-dotnet + org.opencontainers.image.description=Elastic Distribution of OpenTelemetry .NET + org.opencontainers.image.vendor=Elastic - name: Build and Push Profiler Docker Image id: docker-push