Skip to content

Build and sign

Build and sign #386

Workflow file for this run

name: Build and sign
on:
schedule:
- cron: '0 14 * * *'
workflow_dispatch:
jobs:
build-and-sign:
name: "Build and sign kubectl"
runs-on: ubuntu-latest
permissions:
packages: write
id-token: write
steps:
-
name: Find latest kubectl version
run: |
KUBECTL_VER="$(curl https://storage.googleapis.com/kubernetes-release/release/stable-1.27.txt)"
echo "kubectl_ver=${KUBECTL_VER}" >> $GITHUB_ENV
-
run: echo "kubectl binary is at version ${{ env.kubectl_ver }}"
-
name: Stop if ${{ github.repository_owner }}/kubectl:${{ env.kubectl_ver }} in repo already
id: check-in-repo
run: |
# fake no-op token, image is public
TOKEN=$(curl https://ghcr.io/token\?scope\="repository:${{ github.repository_owner }}/kubectl:pull" | jq .token | tr -d \")
if curl -H "Authorization: Bearer $TOKEN" https://ghcr.io/v2/${{ github.repository_owner }}/kubectl/tags/list \
| grep \"${{ env.kubectl_ver }}\";
then
echo "${{ github.repository_owner }}/kubectl:${{ env.kubectl_ver }} is in repo already"
echo "image-exists=true" >> $GITHUB_ENV
fi
-
uses: sigstore/cosign-installer@v3
if: env.image-exists != 'true'
-
name: Checkout code
if: env.image-exists != 'true'
uses: actions/checkout@v3
-
name: Download and verify kubectl
if: env.image-exists != 'true'
run: ./download-kubectl.sh ${{ env.kubectl_ver }}
-
name: Set up QEMU
if: env.image-exists != 'true'
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64'
-
name: Set up Docker Buildx
if: env.image-exists != 'true'
uses: docker/setup-buildx-action@v2
-
name: Login to GitHub Container Registry
if: env.image-exists != 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push tagged container image
id: build-image
if: env.image-exists != 'true'
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64, linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/kubectl:${{ env.kubectl_ver }}
-
name: Sign the image
if: env.image-exists != 'true'
run: |
cosign sign --yes \
ghcr.io/${{ github.repository_owner }}/kubectl@${{ steps.build-image.outputs.digest }}