Skip to content

feat: change docker to use "coder" user and add basic Helm chart #2746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,19 @@ jobs:
- name: ls artifacts
run: ls artifacts

- name: Publish Helm
run: |
set -euxo pipefail
./scripts/helm.sh --push
mv ./dist/*.tgz ./artifacts/

- name: Publish Release
run: |
./scripts/publish_release.sh \
${{ (github.event.inputs.dry_run || github.event.inputs.snapshot) && '--dry-run' }} \
./artifacts/*.zip \
./artifacts/*.tar.gz \
./artifacts/*.tgz \
./artifacts/*.apk \
./artifacts/*.deb \
./artifacts/*.rpm
Expand Down
23 changes: 23 additions & 0 deletions helm/.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/
27 changes: 27 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v2
name: coder
description: Remote development environments on your infrastructure.
home: https://github.com/coder/coder

# version and appVersion are injected at release.
type: application
version: "0.1.0"
appVersion: "0.1.0"

# Coder has a hard requirement on Kubernetes 1.19, as this version introduced
# the networking.k8s.io/v1 API for the Ingress and NetworkPolicy resources.
#
# Additionally, the NOTES.txt file emits a warning if the cluster version is
# outside our soft requirement, in accordance with our official support policy.
kubeVersion: ">= 1.19.0-0"

keywords:
- coder
- terraform
sources:
- https://github.com/coder/coder/tree/main/helm
icon: https://helm.coder.com/coder_logo_black.png
maintainers:
- name: Coder Technologies, Inc.
email: support@coder.com
url: https://coder.com/contact
16 changes: 16 additions & 0 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if not (semverCompare ">= 1.21.0-0" .Capabilities.KubeVersion.Version) -}}
============================== KUBERNETES SUPPORT ==============================

NOTICE: Coder follows the Kubernetes upstream version support policy, and the
latest stable release version of Coder supports the previous two minor releases
as well as the current release of Kubernetes at time of publication.

Your Kubernetes version is: {{ .Capabilities.KubeVersion }}

Coder {{ .Chart.AppVersion }} requires Kubernetes >= 1.21

Coder cannot provide any guarantees of compatibility nor technical support for
this version of Kubernetes.

============================== KUBERNETES SUPPORT ==============================
{{- end -}}
33 changes: 33 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{/*
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 }}

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

{{/*
Selector labels
*/}}
{{- define "coder.selectorLabels" -}}
app.kubernetes.io/name: {{ include "coder.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
50 changes: 50 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: coder
labels:
{{- include "coder.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.coder.replicaCount }}
selector:
matchLabels:
{{- include "coder.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "coder.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: Always
terminationGracePeriodSeconds: 300
containers:
- name: coder
image: "{{ .Values.coder.image.repo }}:{{ .Values.coder.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.coder.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
- name: CODER_ADDRESS
value: "0.0.0.0:80"
{{- if .Values.coder.tls.secretName }}
- name: CODER_TLS_ENABLE
value: "true"
- name: CODER_TLS_CERT_FILE
value: /etc/ssl/certs/coder/tls.crt
- name: CODER_TLS_KEY_FILE
value: /etc/ssl/certs/coder/tls.key
{{- end }}
{{- with .Values.coder.env -}}
{{ toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: 80
protocol: TCP
readinessProbe:
httpGet:
path: /
port: http
livenessProbe:
httpGet:
path: /
port: http
32 changes: 32 additions & 0 deletions helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.coder.ingress.enable }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to provide an ingress? Would a service be enough? I think @f0ssel had some thoughts here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ingress is useful for customers who don't want to expose coder directly with a LoadBalancer Service but instead want to run it through their own ingress controller like the nginx one. Turning on the ingress does not create an ingress controller for you like it did in v1 at one point, the customer needs to supply their own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be simpler to exclude that resource for now, as customers can really easily add their own Ingress?

My intent is to minimize the surface area and knowledge of Kubernetes that we need to have. Reducing resources that some devs may not understand can be helpful there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, I'm down to remove it if you're fine with that in the name of simplicity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with that if you feel it's not necessary, I don't have a full understanding, I'm just tryna simplify ;p

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f0ssel you chill with me removing ingress?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ultra chill 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be required for us to document the step of optionally creating an ingress on setup instructions since it will be a super common ask, but I'm fine with it not being a part of coder chart. This will also mean "rolling out changes" to an ingress will also be more complicated to instruct users, but I don't see that being something we really need to worry about imo.

metadata:
name: coder
labels:
{{- include "coder.labels" . | nindent 4 }}
spec:
{{- if .Values.coder.ingress.className }}
{{/* If this is set to an empty string it fails validation on K8s */}}
ingressClassName: {{ .Values.coder.ingress.className | quote }}
{{- end }}
rules:
- host: {{ .Values.coder.ingress.host | quote }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: coder
port:
name: http

{{- if .Values.coder.ingress.tls.enable }}
tls:
- hosts:
- {{ .Values.coder.ingress.host | quote }}
secretName: {{ .Values.coder.ingress.tls.secretName | quote}}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: coder
labels:
{{- include "coder.labels" . | nindent 4 }}
spec:
type: {{ .Values.coder.service.type }}
ports:
- name: http
port: 80
targetPort: http
protocol: TCP
- name: https
port: 443
targetPort: https
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we change the deployment port we listen on, so we can't route to 443 here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably fix that and provide a second listen address for https traffic. I'll open an issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protocol: TCP
selector:
{{- include "coder.selectorLabels" . | nindent 4 }}
81 changes: 81 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# coder -- Primary configuration for `coder server`.
coder:
# coder.replicaCount -- The number of Kubernetes deployment replicas.
replicaCount: 1

# coder.image -- The image to use for Coder.
image:
# coder.image.repo -- The repository of the image.
repo: "ghcr.io/coder/coder"
# coder.image.tag -- The tag of the image, defaults to the same version as
# the chart.
tag: "{{.Release.Version}}"
# coder.image.pullPolicy -- The pull policy to use for the image. See:
# https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
pullPolicy: IfNotPresent

# coder.service -- The Service object to expose for Coder.
service:
# coder.service.type -- The type of service to expose. See:
# https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
type: LoadBalancer
# coder.service.externalTrafficPolicy -- The external traffic policy to use.
# On AWS EKS you may need to change this to "Cluster". See:
# https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip
externalTrafficPolicy: Local
# coder.service.loadBalancerIP -- The IP address of the LoadBalancer. If not
# specified, a new IP will be generated each time the load balancer is
# recreated. It is recommended to manually create a static IP address in
# your cloud and specify it here in production to avoid accidental IP
# address changes.
loadBalancerIP: ""

# coder.ingress -- The Ingress object to expose for Coder.
ingress:
# coder.ingress.enable -- Whether to enable the Ingress.
enable: false
# coder.ingress.className -- The name of the Ingress class to use.
className: ""
# coder.ingress.host -- The hostname to match on.
host: "coder.example.com"
# coder.ingress.tls -- The TLS configuration to use for the Ingress.
tls:
# coder.ingress.tls.enable -- Whether to enable TLS on the Ingress.
enable: false
# coder.ingress.tls.secretName -- The name of the TLS secret to use.
secretName: ""

# coder.tls -- The TLS configuration for Coder.
tls:
# coder.tls.secretName -- The name of the secret containing the TLS
# certificate. The secret should exist in the same namespace as the Helm
# deployment and should be of type "kubernetes.io/tls". The secret will be
# automatically mounted into the pod if specified, and the correct
# "CODER_TLS_*" environment variables will be set for you.
secretName: ""

# coder.resources -- The resources to request for Coder. These are optional
# and are not set by default.
resources: {}
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# coder.env -- The environment variables to set for Coder. These can be used
# to configure all aspects of `coder server`. Please see `coder server --help`
# for information about what environment variables can be set.
#
# Note: The following environment variables are set by default and cannot be
# overridden:
# - CODER_ADDRESS: set to 0.0.0.0:80 and cannot be changed.
# - CODER_TLS_ENABLE: set if tls.secretName is not empty.
# - CODER_TLS_CERT_FILE: set if tls.secretName is not empty.
# - CODER_TLS_KEY_FILE: set if tls.secretName is not empty.
env:
- name: CODER_ACCESS_URL
value: "https://coder.example.com"
- name: CODER_PG_CONNECTION_URL
value: "postgres://coder:password@postgres:5432/coder?sslmode=disable"
87 changes: 87 additions & 0 deletions scripts/helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash

# This script creates a Helm package for the given version. It will output a
# .tgz file at the specified path, and may optionally push it to the Coder OSS
# repo.
#
# ./helm.sh [--version 1.2.3] [--output path/to/coder.tgz] [--push]
#
# If no version is specified, defaults to the version from ./version.sh.
#
# If no output path is specified, defaults to
# "$repo_root/dist/coder_helm_$version.tgz".
#
# If the --push parameter is specified, the resulting artifact will be published
# to the Coder OSS repo. This requires `gsutil` to be installed and configured.

set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

version=""
output_path=""
push=0

args="$(getopt -o "" -l version:,output:,push -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
--version)
version="$2"
shift 2
;;
--output)
output_path="$(realpath "$2")"
shift 2
;;
--push)
push="1"
shift
;;
--)
shift
break
;;
*)
error "Unrecognized option: $1"
;;
esac
done

# Remove the "v" prefix.
version="${version#v}"
if [[ "$version" == "" ]]; then
version="$(execrelative ./version.sh)"
fi

if [[ "$output_path" == "" ]]; then
cdroot
mkdir -p dist
output_path="$(realpath "dist/coder_helm_$version.tgz")"
fi

# Check dependencies
dependencies helm

# Make a destination temporary directory, as you cannot fully control the output
# path of `helm package` except for the directory name :/
cdroot
temp_dir="$(mktemp -d)"

cdroot
cd ./helm
log "--- Packaging helm chart for version $version ($output_path)"
helm package \
--version "$version" \
--app-version "$version" \
--destination "$temp_dir" \
. 1>&2

log "Moving helm chart to $output_path"
cp "$temp_dir"/*.tgz "$output_path"
rm -rf "$temp_dir"

if [[ "$push" == 1 ]]; then
log "--- Publishing helm chart..."
# TODO: figure out how/where we want to publish the helm chart
fi