Skip to content

fix: Add NODE_NAME env variable from downward api instaed of relying … #153

fix: Add NODE_NAME env variable from downward api instaed of relying …

fix: Add NODE_NAME env variable from downward api instaed of relying … #153

Workflow file for this run

name: Build
on:
push:
branches:
- main
release:
types:
- published
pull_request:
branches:
- main
env:
CR_CONFIGFILE: "${{ github.workspace }}/cr.yaml"
CR_INDEX_PATH: "${{ github.workspace }}/.cr-index"
CR_PACKAGE_PATH: "${{ github.workspace }}/.cr-release-packages"
CR_TOOL_PATH: "${{ github.workspace }}/.cr-tool"
CHART_PATH: "${{ github.workspace }}/charts/gpu-metrics-exporter"
jobs:
build:
name: Build
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Get release tag
if: github.event_name == 'release'
run: echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build Go binary amd64
run: go build -ldflags "-s -w -X main.GitCommit=$GITHUB_SHA -X main.GitRef=$GITHUB_REF -X main.Version=${RELEASE_TAG:-commit-$GITHUB_SHA}" -o bin/gpu-metrics-exporter-amd64 ./cmd/main.go
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
- name: Build Go binary arm64
run: go build -ldflags "-s -w -X main.GitCommit=$GITHUB_SHA -X main.GitRef=$GITHUB_REF -X main.Version=${RELEASE_TAG:-commit-$GITHUB_SHA}" -o bin/gpu-metrics-exporter-arm64 ./cmd/main.go
env:
GOOS: linux
GOARCH: arm64
CGO_ENABLED: 0
- name: Test
run: go test -race ./...
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push PR
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64,linux/amd64
file: ./Dockerfile
push: true
tags: ghcr.io/castai/gpu-metrics-exporter/gpu-metrics-exporter:${{ github.sha }}
- name: Build and push main
if: ${{ github.event_name != 'pull_request' && github.event_name != 'release' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64,linux/amd64
file: ./Dockerfile
push: true
tags: ghcr.io/castai/gpu-metrics-exporter/gpu-metrics-exporter:${{ github.sha }}
- name: Build and push release
if: ${{ github.event_name == 'release' }}
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/arm64,linux/amd64
file: ./Dockerfile
tags: |
ghcr.io/castai/gpu-metrics-exporter/gpu-metrics-exporter:${{ env.RELEASE_TAG }}
ghcr.io/castai/gpu-metrics-exporter/gpu-metrics-exporter:latest
- name: Checkout helm-charts
if: ${{ github.event_name == 'release' }}
# The cr tool only works if the target repository is already checked out
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: castai/helm-charts
path: helm-charts
token: ${{ secrets.HELM_CHARTS_REPO_TOKEN }}
- name: Configure Git for helm-charts
if: ${{ github.event_name == 'release' }}
run: |
cd helm-charts
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
if: ${{ github.event_name == 'release' }}
uses: azure/[email protected]
id: install
- name: Install CR tool
if: ${{ github.event_name == 'release' }}
run: |
mkdir "${CR_TOOL_PATH}"
mkdir "${CR_PACKAGE_PATH}"
mkdir "${CR_INDEX_PATH}"
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/v1.6.1/chart-releaser_1.6.1_linux_amd64.tar.gz"
tar -xzf cr.tar.gz -C "${CR_TOOL_PATH}"
rm -f cr.tar.gz
- name: Bump chart version
if: ${{ github.event_name == 'release' }}
run: |
echo "Release tag is ${{env.RELEASE_TAG}}"
python ./.github/workflows/bump_chart.py ${CHART_PATH}/Chart.yaml ${{env.RELEASE_TAG}}
- name: Parse Chart.yaml
if: ${{ github.event_name == 'release' }}
id: parse-chart
run: |
description=$(yq ".description" < ${CHART_PATH}/Chart.yaml)
name=$(yq ".name" < ${CHART_PATH}/Chart.yaml)
version=$(yq ".version" < ${CHART_PATH}/Chart.yaml)
echo "chartpath=${CHART_PATH}" >> $GITHUB_OUTPUT
echo "desc=${description}" >> $GITHUB_OUTPUT
echo "tagname=${name}-${version}" >> $GITHUB_OUTPUT
echo "packagename=${name}-${version}" >> $GITHUB_OUTPUT
- name: Create helm package
if: ${{ github.event_name == 'release' }}
run: |
"${CR_TOOL_PATH}/cr" package "${{ steps.parse-chart.outputs.chartpath }}" --config "${CR_CONFIGFILE}" --package-path "${CR_PACKAGE_PATH}"
echo "Result of chart package:"
ls -l "${CR_PACKAGE_PATH}"
git status
- name: Make helm charts github release
if: ${{ github.event_name == 'release' }}
uses: softprops/[email protected]
with:
body: |
${{ steps.parse-chart.outputs.desc }}
Source commit: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
files: |
${{ env.CR_PACKAGE_PATH }}/${{ steps.parse-chart.outputs.packagename }}.tgz
${{ env.CR_PACKAGE_PATH }}/${{ steps.parse-chart.outputs.packagename }}.tgz.prov
repository: castai/helm-charts
tag_name: ${{ steps.parse-chart.outputs.tagname }}
token: ${{ secrets.HELM_CHARTS_REPO_TOKEN }}
- name: Update helm repo index.yaml
if: ${{ github.event_name == 'release' }}
run: |
cd helm-charts
"${CR_TOOL_PATH}/cr" index --config "${CR_CONFIGFILE}" --token "${{ secrets.HELM_CHARTS_REPO_TOKEN }}" --index-path "${CR_INDEX_PATH}" --package-path "${CR_PACKAGE_PATH}" --push
- name: Commit Chart.yaml changes
if: ${{ github.event_name == 'release' }}
run: |
git status
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git add charts/gpu-metrics-exporter/Chart.yaml
git stash
git fetch
git checkout main
git stash pop
git add charts/gpu-metrics-exporter/Chart.yaml
git commit -m "[Release] Update Chart.yaml"
git push
- name: Sync chart with helm-charts github
if: ${{ github.event_name == 'release' }}
run: |
cd helm-charts
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git checkout main
mkdir -p ./charts/gpu-metrics-exporter
cp -r ${CHART_PATH}/* ./charts/gpu-metrics-exporter
git add charts/gpu-metrics-exporter
git commit -m "Update gpu-metrics-exporter chart to ${{env.RELEASE_TAG}}"
git push