Skip to content

Instantly share code, notes, and snippets.

@youcefguichi
Last active March 24, 2023 19:01
Show Gist options
  • Save youcefguichi/1e1109a99972bcb4f059627aa423c51d to your computer and use it in GitHub Desktop.
Save youcefguichi/1e1109a99972bcb4f059627aa423c51d to your computer and use it in GitHub Desktop.
{{- $websiteDirectory := regexFind "([^\\/]+$)" .Values.staticSite.gitCloneUrl | replace ".git" "" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "static-site.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "static-site.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "static-site.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "static-site.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: static-files
emptyDir: {}
initContainers:
- name: init-con
image: {{ .Values.staticSite.buildImage }}:{{ .Values.staticSite.buildTag}}
{{- if .Values.staticSite.buildCommand}}
command:
- sh
- -c
- |
git clone {{ .Values.staticSite.gitCloneUrl}} &&
cd {{ $websiteDirectory }} &&
{{ .Values.staticSite.buildCommand}} &&
mkdir -p /usr/share/nginx/html &&
cp -r ./public/. /usr/share/nginx/html
{{- end }}
volumeMounts:
- name: static-files
mountPath: /usr/share/nginx/html
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: static-files
mountPath: /usr/share/nginx/html
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
---
# custo-values.yaml
staticSite:
gitCloneUrl: https://github.com/YoucefGuichi/gatspy-site.git
buildImage: node
buildTag: latest
buildCommand:
"npm install &&
npm install -g gatsby-cli &&
gatsby build"
builtAssets: public/
@laszlocph
Copy link

laszlocph commented Mar 24, 2023

  • both static-site and staticSite are used in var names. I guess only one of them, staticSite should be
  • name: {{ .Chart.Name }}, name: {{ .Release.Name }} can you copy the same naming approach that we use in onechart? I don't think .Chart.Name is used.
  • builtAssets is not used in the implementation. I think that needs to be configurable as build scripts output dir vary
  • I would have used the same configmap approach as with the onechart solution. Gives a nicer separation, it would also handle multiline commands. Not sure if needed though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment