Skip to content

Commit

Permalink
Add example github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jriguera committed Mar 15, 2024
1 parent c14d40e commit 2f64c5c
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Release Docker image

on:
workflow_dispatch: { }
push:
branches:
- "main"

env:
# Default image for the Chart
DOCKER_IMAGE_NAME: otel-collector
DOCKER_REGISTRY: ghcr.io/${{ github.repository }}
DOCKER_BUILD_DIR: '.'

permissions: {}

jobs:
compile:
runs-on: ubuntu-latest
outputs:
artifact: ${{ steps.artifact.outputs.artifact-id }}
version: ${{ steps.versions.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup golang stable
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Get build versions
id: versions
run: |
awk -F':' '/^[[:blank:]]+otelcol_version[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "otelcol-version="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+output_path[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "build-path="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+name[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "build-name="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+version[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "version="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
- name: Download the collector builder
run: |
curl -Ss -fL -o ocb https://github.com/open-telemetry/opentelemetry-collector/releases/download/cmd%2Fbuilder%2Fv${VERSION}/ocb_${VERSION}_linux_amd64
chmod +x ocb
env:
VERSION: "${{ steps.versions.outputs.otelcol-version }}"

- name: Build the OTEL collectory binary
run: |
./ocb --config builder-config.yaml
- name: Archive binary
id: artifact
uses: actions/upload-artifact@v4
with:
name: otelcol-${{ steps.versions.outputs.version }}
retention-days: 1
path: "${{ steps.versions.outputs.build-path }}/${{ steps.versions.outputs.build-name }}"
if-no-files-found: error
overwrite: true

build-image:
permissions:
contents: read
packages: write
needs:
- compile
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/download-artifact@v4
with:
name: otelcol-${{ needs.compile.outputs.version }}
path: otelcol-dev

- name: Get metadata for Docker image
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
type=ref,event=branch
type=sha
- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push to Github Packages
uses: docker/build-push-action@v5
with:
context: ${{ env.DOCKER_BUILD_DIR }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.meta.outputs.tags }}
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.compile.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 2f64c5c

Please sign in to comment.