diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index deb07c9..a6cb9af 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -5,6 +5,8 @@ on: push: branches: - "main" + tags: + - '**' env: # Default image for the Chart @@ -20,6 +22,7 @@ jobs: outputs: artifact: ${{ steps.artifact.outputs.artifact-id }} version: ${{ steps.versions.outputs.version }} + buildname: ${{ steps.versions.outputs.build-name }} steps: - name: Checkout uses: actions/checkout@v4 @@ -54,7 +57,7 @@ jobs: id: artifact uses: actions/upload-artifact@v4 with: - name: otelcol-${{ steps.versions.outputs.version }} + name: "otelcol-${{ steps.versions.outputs.version }}_linux_amd64" retention-days: 1 path: "${{ steps.versions.outputs.build-path }}/${{ steps.versions.outputs.build-name }}" if-no-files-found: error @@ -66,7 +69,7 @@ jobs: packages: write needs: - compile - if: ${{ github.event_name != 'pull_request' }} + if: ${{ (github.event_name != 'pull_request') && (startsWith(github.ref, 'refs/tags/')) }} runs-on: ubuntu-latest steps: - name: Checkout @@ -74,9 +77,11 @@ jobs: with: fetch-depth: 0 - - uses: actions/download-artifact@v4 + - name: Download artifact + id: artifact + uses: actions/download-artifact@v4 with: - name: otelcol-${{ needs.compile.outputs.version }} + name: "otelcol-${{ needs.compile.outputs.version }}_linux_amd64" path: otelcol-dev - name: Get metadata for Docker image @@ -97,13 +102,65 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - + + - name: Build and export to Docker + uses: docker/build-push-action@v6 + with: + context: ${{ env.DOCKER_BUILD_DIR }} + build-args: + - "OTEL_BIN=${{ steps.artifact.outputs.download-path }}/${{ needs.compile.outputs.build-name }}" + load: true + tags: otelcol + + # - name: Test + # run: | + # docker run --rm otelcol + - name: Build and push to Github Packages - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: ${{ env.DOCKER_BUILD_DIR }} push: ${{ github.event_name != 'pull_request' }} + build-args: + - "OTEL_BIN=${{ steps.artifact.outputs.download-path }}/${{ needs.compile.outputs.build-name }}" tags: | ${{ steps.meta.outputs.tags }} ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.compile.outputs.version }} labels: ${{ steps.meta.outputs.labels }} + + release: + permissions: + contents: write + packages: read + needs: + - compile + - build-image + if: ${{ (github.event_name != 'pull_request') && (startsWith(github.ref, 'refs/tags/')) }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get artifact + id: artifact + uses: actions/download-artifact@v4 + with: + name: "otelcol-${{ needs.compile.outputs.version }}_linux_amd64" + path: otelcol-dev + + - name: Get list of artifacts + run: | + cd "${{ steps.artifact.outputs.download-path }}" + mkdir "otelcol-custom_${{ needs.compile.outputs.version }}" + cp "${{ needs.compile.outputs.build-name }}" "otelcol-custom_${{ needs.compile.outputs.version }}/otelcol-custom_${{ needs.compile.outputs.version }}_linux_amd64" + mv "${{ needs.compile.outputs.build-name }}" "otelcol-custom_${{ needs.compile.outputs.version }}_linux_amd64.bin" + tar zcvf "otelcol-custom_${{ needs.compile.outputs.version }}.tgz" "otelcol-custom_${{ needs.compile.outputs.version }}" + rm "otelcol-custom_${{ needs.compile.outputs.version }}" + + - name: Create a Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: "${{ steps.artifact.outputs.download-path }}/*" diff --git a/Dockerfile b/Dockerfile index baf8d49..7c749cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,11 @@ RUN apk --update add ca-certificates FROM debian:12-slim ARG USER_UID=10001 +ARG OTEL_BIN=otelcol-dev/otelcol-dev USER ${USER_UID} COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --chmod=755 otelcol-dev/otelcol-dev /otelcol-contrib +COPY --chmod=755 ${OTEL_BIN} /otelcol-contrib COPY otelcol-contrib.yaml /etc/otelcol-contrib/config.yaml ENTRYPOINT ["/otelcol-contrib"] CMD ["--config", "/etc/otelcol-contrib/config.yaml"] diff --git a/README.md b/README.md index b6f2e38..454fbcf 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,11 @@ If you want to get to your own custom collector compiled or updated: ``` With this configuration the collector will scrape its own metrics. +# Create a new release (with binaries) +Releases are managed by the GH Action workflow. Please commit all changes and then push an annotated tag to the repository. + +``` +git tag -a v -m "" +git push --tags +``` \ No newline at end of file