Add metadata output #43
Workflow file for this run
This file contains 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: ci | |
on: push | |
# https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#comments-and-annotations | |
permissions: | |
contents: read | |
pull-requests: read | |
checks: write | |
jobs: | |
# https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#how-to-use | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: false | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: v1.54 | |
args: --timeout=10m | |
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- run: go mod download | |
- run: make test | |
- run: make build | |
# https://docs.docker.com/build/ci/github-actions/multi-platform/ | |
build: | |
# Do not build Docker images for forked repositories since Docker Hub secrets are not available: | |
# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow | |
if: ${{ ! github.event.pull_request.head.repo.fork }} | |
# Make sure the tests have passed before building | |
needs: | |
- lint | |
- test | |
runs-on: ubuntu-latest | |
outputs: | |
metadata: ${{ steps.build.outputs.metadata }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
id: build | |
env: | |
# https://github.com/github/docs/issues/15319#issuecomment-1662257301 | |
BRANCH: ${{ github.event.pull_request && github.head_ref || github.ref_name }} | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/cost-manager:${{ env.BRANCH == 'main' && 'latest' || env.BRANCH }} | |
# https://docs.docker.com/build/ci/github-actions/cache/#github-cache | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
kind: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: azure/setup-helm@v3 | |
with: | |
version: v3.12.1 | |
- name: Helm lint | |
run: helm lint --strict ./charts/cost-manager | |
- uses: helm/[email protected] | |
- name: Install CRDs | |
run: kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/5469d7912072c1070eedc680c89e27d46b8f4f82/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml | |
- name: Write Docker build result metadata to disk | |
run: echo "${METADATA}" > metadata.json | |
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable | |
env: | |
# https://github.com/docker/build-push-action#outputs | |
METADATA: ${{ needs.build.outputs.metadata }} | |
- name: Install cost-manager | |
# Use bash shell to set pipefail option: | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell | |
shell: bash | |
run: | | |
kubectl create namespace cost-manager | |
# If we push multiple tags then this will not work because they will be space delimited | |
REPOSITORY="$(jq -er '."image.name"' metadata.json)" | |
helm template ./charts/cost-manager \ | |
-n cost-manager \ | |
--set image.repository="${REPOSITORY}" \ | |
--set iam.gcp.serviceAccount=cost-manager@example.iam.gserviceaccount.com \ | |
--set vpa.enabled=true | kubectl apply -f - | |
kubectl wait --for=condition=Available=true deployment/cost-manager -n cost-manager --timeout=10m |