Skip to content

Commit

Permalink
Add chart and rollout fasit feature on commit to main
Browse files Browse the repository at this point in the history
In order to implement proper CD for elector we need a way to propagate the newly built image to naiserator.
This feature will install a configmap in the cluster which we then can refer to in naiserator.
Combined with config reloading on update, we should get proper CD for elector.
  • Loading branch information
mortenlj committed Nov 6, 2023
1 parent 7dbb78b commit 9b67156
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,76 @@ jobs:
- name: Verify runner image
run: cosign verify --certificate-identity ${{ env.RUNNERIMG_IDENTITY }} --certificate-oidc-issuer ${{ env.RUNNERIMG_ISSUER }} ${{ env.RUNNER_IMG }}
- uses: nais/platform-build-push-sign@2a0a82c67a7bda6d954542edf187dde0c868983c # ratchet:nais/platform-build-push-sign@main
id: build-push-sign
with:
name: elector
dockerfile: Dockerfile
google_service_account: gh-elector
push: ${{ github.actor != 'dependabot[bot]' }}
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
cache_from: type=gha
cache_to: type=gha,mode=max
outputs:
version: "${{ steps.build-push-sign.outputs.version }}"

chart:
permissions:
contents: 'read'
id-token: 'write'
name: Build and push chart
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4 # ratchet:actions/checkout@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
if: github.ref == 'refs/heads/main'
uses: 'google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033' # ratchet:google-github-actions/auth@v1.1.1
with:
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
service_account: 'gh-elector@nais-io.iam.gserviceaccount.com'
token_format: 'access_token'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b' # ratchet:google-github-actions/setup-gcloud@v1
- name: 'Log in to Google Artifact Registry'
if: github.ref == 'refs/heads/main'
run: |-
echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://${{ env.GOOGLE_REGISTRY }}
- uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # ratchet:azure/setup-helm@v3
name: 'Setup Helm'
with:
version: '3.8.0'
- name: Set versions
run: |-
for chart in charts/*; do
yq e '.version = "${{ needs.build.outputs.version }}"' --inplace "${chart}/Chart.yaml"
yq e '.image.tag = "${{ needs.build.outputs.version }}"' --inplace "${chart}/values.yaml"
done
- name: Build Chart
run: |-
for chart in charts/*; do
helm package "$chart"
done
- name: Push Chart
if: github.ref == 'refs/heads/main'
run: |-
for chart in *.tgz; do
helm push "$chart" oci://${{ env.GOOGLE_REGISTRY }}/nais-io/nais/feature
done
rollout:
name: Rollout
if: github.actor != 'dependabot[bot]' && github.ref == 'refs/heads/main'
needs:
- build
- chart
runs-on: fasit-deploy
permissions:
id-token: write
steps:
- uses: nais/fasit-deploy@badff0705af8a57bcf0ab172895273da09ae5959 # ratchet:nais/fasit-deploy@v2
with:
chart: oci://${{ env.GOOGLE_REGISTRY }}/nais-io/nais/feature/elector
version: ${{ needs.build.outputs.version }}
feature_name: elector
23 changes: 23 additions & 0 deletions charts/elector/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
7 changes: 7 additions & 0 deletions charts/elector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: elector
description: Providing elector configuration for naiserator
type: application
version: invalid
sources:
- https://github.com/nais/elector/tree/main/charts
12 changes: 12 additions & 0 deletions charts/elector/Feature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencies:
- allOf:
- naiserator
environmentKinds:
- tenant
- onprem
- legacy
values:
image.tag:
displayName: Image tag
config:
type: string
62 changes: 62 additions & 0 deletions charts/elector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "elector.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "elector.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "elector.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "elector.labels" -}}
helm.sh/chart: {{ include "elector.chart" . }}
{{ include "elector.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "elector.selectorLabels" -}}
app.kubernetes.io/name: {{ include "elector.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "elector.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "elector.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/elector/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "elector.fullname" . }}
labels:
{{- include "elector.labels" . | nindent 4 }}
data:
elector_image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
8 changes: 8 additions & 0 deletions charts/elector/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Default values for elector.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
repository: europe-north1-docker.pkg.dev/nais-io/nais/images/elector
pullPolicy: IfNotPresent
tag: latest

0 comments on commit 9b67156

Please sign in to comment.