feat(ci): add container image labels to pipeline configuration #355
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pipeline | |
on: | |
push: | |
branches: | |
- '**' # Matches all branches | |
pull_request: | |
branches: | |
- '**' # Matches all branches | |
workflow_dispatch: | |
inputs: | |
force_build: | |
description: 'Forces a build even if no changes are detected' | |
required: true | |
default: 'false' | |
force_publish: | |
description: 'Forces a publish even if no changes are detected' | |
required: true | |
default: 'false' | |
concurrency: | |
group: pipeline-${{ github.ref_name }} | |
cancel-in-progress: true | |
env: | |
containerImage: "kubernetes-reflector" | |
containerImageBuildContext: "src/" | |
containerImageBuildDockerfile: "src/ES.Kubernetes.Reflector/Dockerfile" | |
containerImageRegistry: "ghcr.io/emberstack" | |
helmChart: "reflector" | |
helmChartDir: "src/helm/reflector" | |
jobs: | |
discovery: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: read | |
outputs: | |
pathsFilter_src: ${{ steps.pathsFilter.outputs.src }} | |
gitVersion_SemVer: ${{ steps.gitversion.outputs.GitVersion_SemVer }} | |
gitVersion_AssemblySemFileVer: ${{ steps.gitversion.outputs.GitVersion_AssemblySemFileVer }} | |
requiresBuild: ${{ steps.requires_build.outputs.result }} | |
requiresBuildPush: ${{ steps.requires_build_push.outputs.result }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: tools - dotnet - install | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '9.x' | |
- name: tools - gitversion - install | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
versionSpec: '5.x' | |
preferLatestVersion: true | |
- name: gitversion - execute | |
id: gitversion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
useConfigFile: true | |
configFilePath: GitVersion.yaml | |
- name: tools - detect changes | |
id: pathsFilter | |
uses: dorny/paths-filter@v3 | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
src: | |
- 'src/**' | |
- name: evaluate - requires_build | |
id: requires_build | |
run: | | |
if [ "${{ steps.pathsFilter.outputs.src }}" = "true" ] || \ | |
[ "${{ github.event.inputs.force_build }}" = "true" ] || \ | |
[ "${{ github.event.inputs.force_publish }}" = "true" ]; then | |
result=true | |
else | |
result=false | |
fi | |
echo "result=$result" >> $GITHUB_OUTPUT | |
- name: evaluate - requires_build_push | |
id: requires_build_push | |
run: | | |
if [ "${{ steps.requires_build.outputs.result }}" = "false" ]; then | |
result=true | |
else | |
result=false | |
fi | |
echo "result=$result" >> $GITHUB_OUTPUT | |
build: | |
name: build | |
# if: ${{ needs.discovery.outputs.requiresBuild == 'true' }} | |
needs: [discovery] | |
runs-on: ubuntu-latest | |
env: | |
# operator_credentials: ${{ needs.discovery.outputs.operator_credentials }} | |
# image_registry: ${{ needs.discovery.outputs.image_registry }} | |
# build_push: ${{ needs.discovery.outputs.build_push }} | |
# build_configuration: ${{ needs.discovery.outputs.build_configuration }} | |
# SERVICE_NAME: ${{ matrix.service.name }} | |
# SERVICE_DIR: ${{ matrix.service.dir }} | |
# SOLUTION_FILE: ${{ matrix.service.solution }} | |
# HELM_CHART: ${{ matrix.service.helmChart }} | |
# HELM_CHART_DIR: ${{ matrix.service.helmChartDir }} | |
gitVersion_SemVer: ${{ needs.discovery.outputs.gitVersion_SemVer }} | |
gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: tools - kubectl - install | |
uses: azure/setup-kubectl@v4 | |
- name: tools - helm - install | |
uses: azure/setup-helm@v4 | |
- name: tools - helm - login - ghcr | |
if: ${{ needs.discovery.outputs.requiresBuildPush == 'true' }} | |
run: | | |
echo "${{ secrets.ES_GITHUB_PAT }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: tools - docker - login ghcr.io | |
if: ${{ needs.discovery.outputs.requiresBuildPush == 'true' }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.ES_GITHUB_PAT }} | |
- name: tools - docker - register QEMU | |
run: | | |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
- name: tools - docker - setup buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver: docker-container # REQUIRED for multi-platform builds | |
- name: artifacts - prepare directories | |
run: | | |
mkdir -p .artifacts/helm | |
mkdir -p .artifacts/kubectl | |
- name: helm - import README | |
run: cp README.md ${{ env.helmChartDir }}/README.md | |
- name: helm - package chart | |
run: helm package --destination .artifacts/helm --version ${{ env.gitVersion_SemVer }} --app-version ${{ env.gitVersion_SemVer }} ${{ env.helmChartDir }} | |
- name: helm - template chart | |
run: helm template --namespace kube-system ${{ env.helmChart }} .artifacts/helm/${{ env.helmChart }}-${{ env.gitVersion_SemVer }}.tgz > .artifacts/kubectl/${{ env.helmChart }}-${{ env.gitVersion_SemVer }}.yaml | |
- name: docker - build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ env.containerImageBuildContext }} | |
file: ${{ env.containerImageBuildDockerfile }} | |
push: ${{ needs.discovery.outputs.requiresBuildPush == 'true' }} | |
provenance: false | |
platforms: linux/amd64,linux/arm/v7,linux/arm64 | |
labels: | | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.url=https://github.com/${{ github.repository }} | |
org.opencontainers.image.vendor=${{ github.repository_owner }} | |
org.opencontainers.image.version=${{ env.gitVersion_SemVer }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
tags: | | |
${{ env.containerImageRegistry }}/${{ env.containerImage }}:${{ env.gitVersion_SemVer }} | |
- name: helm - push - ghcr.io | |
run: helm push .artifacts/helm/${{ env.helmChart }}-${{ env.gitVersion_SemVer }}.tgz oci://ghcr.io/${{ github.repository_owner }}/helm-charts | |
- name: "artifacts - upload - helm chart" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: helm | |
path: .artifacts/helm | |
- name: "artifacts - upload - artifacthub" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: artifacthub | |
path: src/helm/artifacthub-repo.yaml | |
- name: "artifacts - upload - kubectl manifests" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: kubectl | |
path: .artifacts/kubectl | |