Files
coder/helm/libcoder/templates/_helpers.tpl
T
Dean Sheather 368fddf1d6 feat: deploy dogfood by pulled digest instead of CI push (#32253)
Switches dogfood from push-based deploys to pull-based, digest-pinned
deploys with Flux image automation (SEC-863):

- **Remove the push deploy.** Deletes `deploy.yaml` and
`scripts/should_deploy.sh`, and drops the `deploy` job from
`build.yaml`. CI no longer assumes the AWS deploy role, fetches EKS
credentials, runs `flux reconcile` or `kubectl rollout restart`, or
retags `:dogfood`, which nothing consumes. `build.yaml` now has no
cluster access, and only the signing job's existing `id-token: write`
remains.
- **`coder.image.digest`** in the `coder`, `provisioner` and
`ai-gateway` charts. When set, the image renders as `repo:tag@digest`.
Empty (the default) keeps today's output, and existing golden files are
unchanged.
- **Sortable main tag.** `build.yaml` pushes an extra `main-<commit unix
time>-<12 char sha>` tag for every main build, which the Flux
`ImagePolicy` orders on. The `prune` job already prunes `^main-` tags
older than 30 days.

Companion PR: coder/dogfood#857, which installs the image controllers
and pins dogfood-cdr by digest. **Merge this one first**: the ai-gateway
chart's schema rejects unknown keys, so dogfood's new `digest` value
would fail on the current chart.

Merging this before dogfood#857 doesn't regress anything. The
`dogfood-coder-repo-ci` role's trust was disabled during containment, so
the deploy job currently fails at OIDC role assumption on every main
build and only sends a failure alert to Slack. Until dogfood#857 is
live, dogfood stays on its current image.

<details>
<summary>Design notes and decision log</summary>

- **Delete the deploy instead of keeping a Flux webhook ping.** A ping
would only cut latency. Flux scans the registry every 2m, so any trigger
can be added later as a notification-controller `Receiver` without
giving CI cluster credentials.
- **Separate digest value instead of `tag: x@sha256:...`.** Flux's
`:tag` and `:digest` setters write separate fields, and no setter writes
`tag@digest` into a single field. A dedicated chart value is the
documented Flux pattern for HelmReleases and is useful to customers who
pin by digest.
- **Commit timestamp in the tag.** `git log -1 --format=%ct` makes the
tag sort by commit time, which Flux's `numerical` policy selects on. The
sha suffix keeps tags unique and traceable.
- **Not done here:**
- Making the cosign and GitHub attestation steps required. They're still
`continue-on-error`. Admission-time signature verification is a separate
SEC-863 step.
- Removing the AWS role itself and the `AWS_DOGFOOD_*` repo variables.
Those are settings outside the repo, and they become unused once this
merges.

</details>

Verified: `go test ./helm/...`, `make lint/helm`, `make lint/actions`. I
also rendered the dogfood-cdr values against this branch's charts, and
the server, provisioner and ai-gateway images all come out as
`ghcr.io/coder/coder-preview:<tag>@sha256:<digest>`.

Refs SEC-863

> Generated by Coder Agents on behalf of @deansheather.
2026-11-16 21:38:23 +11:00

250 lines
6.1 KiB
Smarty

{{/*
Expand the name of the chart.
*/}}
{{- define "coder.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "coder.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Selector labels
!!!!! DO NOT ADD ANY MORE SELECTORS. IT IS A BREAKING CHANGE !!!!!
*/}}
{{- define "coder.selectorLabels" -}}
app.kubernetes.io/name: {{ include "coder.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "coder.labels" -}}
helm.sh/chart: {{ include "coder.chart" . }}
{{ include "coder.selectorLabels" . }}
app.kubernetes.io/part-of: {{ include "coder.name" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Coder Docker image URI
*/}}
{{- define "coder.image" -}}
{{- if and (eq .Values.coder.image.tag "") (eq .Chart.AppVersion "0.1.0") -}}
{{ fail "You must specify the coder.image.tag value if you're installing the Helm chart directly from Git." }}
{{- end -}}
{{ .Values.coder.image.repo }}:{{ .Values.coder.image.tag | default (printf "v%v" .Chart.AppVersion) }}
{{- with .Values.coder.image.digest }}@{{ . }}{{ end }}
{{- end }}
{{/*
Coder TLS enabled.
*/}}
{{- define "coder.tlsEnabled" -}}
{{- if hasKey .Values.coder "tls" -}}
{{- if .Values.coder.tls.secretNames -}}
true
{{- else -}}
false
{{- end -}}
{{- else -}}
false
{{- end -}}
{{- end }}
{{/*
Coder TLS environment variables.
*/}}
{{- define "coder.tlsEnv" }}
{{- if eq (include "coder.tlsEnabled" .) "true" }}
- name: CODER_TLS_ENABLE
value: "true"
- name: CODER_TLS_ADDRESS
value: "0.0.0.0:8443"
- name: CODER_TLS_CERT_FILE
value: "{{ range $idx, $secretName := .Values.coder.tls.secretNames -}}{{ if $idx }},{{ end }}/etc/ssl/certs/coder/{{ $secretName }}/tls.crt{{- end }}"
- name: CODER_TLS_KEY_FILE
value: "{{ range $idx, $secretName := .Values.coder.tls.secretNames -}}{{ if $idx }},{{ end }}/etc/ssl/certs/coder/{{ $secretName }}/tls.key{{- end }}"
{{- end }}
{{- end }}
{{/*
Coder default access URL
*/}}
{{- define "coder.defaultAccessURL" }}
{{- if eq (include "coder.tlsEnabled" .) "true" -}}
https
{{- else -}}
http
{{- end -}}
://coder.{{ .Release.Namespace }}.svc.cluster.local
{{- end }}
{{/*
Coder volume definitions.
*/}}
{{- define "coder.volumeList" }}
{{- if hasKey .Values.coder "tls" -}}
{{- range $secretName := .Values.coder.tls.secretNames }}
- name: "tls-{{ $secretName }}"
secret:
secretName: {{ $secretName | quote }}
{{ end -}}
{{- end }}
{{ range $secret := .Values.coder.certs.secrets -}}
- name: "ca-cert-{{ $secret.name }}"
secret:
secretName: {{ $secret.name | quote }}
{{ end -}}
{{ if gt (len .Values.coder.volumes) 0 -}}
{{ toYaml .Values.coder.volumes }}
{{ end -}}
{{- end }}
{{/*
Coder volumes yaml.
*/}}
{{- define "coder.volumes" }}
{{- if trim (include "coder.volumeList" .) -}}
volumes:
{{- include "coder.volumeList" . -}}
{{- else -}}
volumes: []
{{- end -}}
{{- end }}
{{/*
Coder volume mounts.
*/}}
{{- define "coder.volumeMountList" }}
{{- if hasKey .Values.coder "tls" }}
{{ range $secretName := .Values.coder.tls.secretNames -}}
- name: "tls-{{ $secretName }}"
mountPath: "/etc/ssl/certs/coder/{{ $secretName }}"
readOnly: true
{{ end -}}
{{- end }}
{{ range $secret := .Values.coder.certs.secrets -}}
- name: "ca-cert-{{ $secret.name }}"
mountPath: "/etc/ssl/certs/{{ $secret.name }}.crt"
subPath: {{ $secret.key | quote }}
readOnly: true
{{ end -}}
{{ if gt (len .Values.coder.volumeMounts) 0 -}}
{{ toYaml .Values.coder.volumeMounts }}
{{ end -}}
{{- end }}
{{/*
Coder volume mounts yaml.
*/}}
{{- define "coder.volumeMounts" }}
{{- if trim (include "coder.volumeMountList" .) -}}
volumeMounts:
{{- include "coder.volumeMountList" . -}}
{{- else -}}
volumeMounts: []
{{- end -}}
{{- end }}
{{/*
Coder ingress wildcard hostname with the wildcard suffix stripped.
*/}}
{{- define "coder.ingressWildcardHost" -}}
{{/* This regex replace is required as the original input including the suffix
* is not a legal ingress host. We need to remove the suffix and keep the
* wildcard '*'.
*
* - '\\*' Starts with '*'
* - '[^.]*' Suffix is 0 or more characters, '-suffix'
* - '(' Start domain capture group
* - '\\.' The domain should be separated with a '.' from the subdomain
* - '.*' Rest of the domain.
* - ')' $1 is the ''.example.com'
*/}}
{{- regexReplaceAll "\\*[^.]*(\\..*)" .Values.coder.ingress.wildcardHost "*${1}" -}}
{{- end }}
{{/*
Fail on fully deprecated values or deprecated value combinations. This is
included at the top of coder.yaml.
*/}}
{{- define "coder.verifyDeprecated" }}
{{/*
Deprecated value coder.tls.secretName must not be used.
*/}}
{{- if .Values.coder.tls.secretName }}
{{ fail "coder.tls.secretName is deprecated, use coder.tls.secretNames instead." }}
{{- end }}
{{- end }}
{{/*
Renders a value that contains a template.
Usage:
{{ include "coder.renderTemplate" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "coder.renderTemplate" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
{{- define "libcoder.rbac.rules.basic" -}}
- apiGroups: [""]
resources: ["pods"]
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
{{- end }}
{{- define "libcoder.rbac.rules.deployments" -}}
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
{{- end }}
{{/*
Component annotation for pod metadata.
This should be overridden in each chart to specify the component type.
*/}}
{{- define "coder.componentAnnotation" -}}
{{- end }}