Skip to content

Build and publish to MCR #16

Build and publish to MCR

Build and publish to MCR #16

# This Github action builds and publishes image to Azure Container Registry (ACR),
# from where it is automatically propagated to Microsoft Container Registry (MCR).
name: Build and publish to MCR
on:
workflow_dispatch:
inputs:
releaseTag:
description: 'Release tag to publish, defaults to the latest one'
type: string
permissions:
contents: read
env:
REGISTRY_REPO: unlisted/aks/karpenter
jobs:
prepare-variables:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.vars.outputs.release_tag }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: 'Set output variables'
id: vars
run: |
RELEASE_TAG=${{ inputs.releaseTag }}
if [ -z "$RELEASE_TAG" ]; then
RELEASE_TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
echo "The user input release tag is empty, will use the latest tag $RELEASE_TAG."
fi
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
publish-images:
permissions:
contents: read
id-token: write # This is required for requesting the JWT
runs-on: ubuntu-latest
needs: prepare-variables
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ needs.prepare-variables.outputs.release_tag }}
- uses: ./.github/actions/install-deps
# reference: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-azure
- name: Login to Azure
uses: azure/login@cb79c773a3cfa27f31f25eb3f677781210c9ce3d # v1.6.1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Build and publish image
env:
KO_DOCKER_REPO: ${{ secrets.AZURE_REGISTRY }}/${{ env.REGISTRY_REPO }}
run: |
az acr login -n ${{ secrets.AZURE_REGISTRY }}
cat >.ko.yaml <<EOF
builds:
- id: controller
main: ./cmd/controller
flags: ['-tags','ccp']
EOF
ko build github.com/Azure/karpenter-provider-azure/cmd/controller \
--platform linux/amd64,linux/arm64 \
--base-import-paths \
--sbom none \
--tags ${{ needs.prepare-variables.outputs.release_tag }}-aks