From 15844e680a372ae628ad57f64c47d422780d7b33 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sat, 25 Feb 2023 12:19:00 +0100 Subject: [PATCH] Update chart --- .dockerignore | 2 + Dockerfile | 13 +--- chart/templates/deployment.yaml | 84 ++++++++++++++++------- chart/templates/nginx-config-cm.yaml | 17 +++++ chart/templates/rclone-config-sec.yaml | 8 +++ chart/templates/virtual-service.yaml | 21 ++++++ chart/values.yaml | 93 +++++++++++++++++--------- 7 files changed, 167 insertions(+), 71 deletions(-) create mode 100644 chart/templates/nginx-config-cm.yaml create mode 100644 chart/templates/rclone-config-sec.yaml create mode 100644 chart/templates/virtual-service.yaml diff --git a/.dockerignore b/.dockerignore index 3c3629e..e3e8e9e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ node_modules +static + diff --git a/Dockerfile b/Dockerfile index b383c9c..43bbe70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,5 @@ -FROM alpine:latest AS builder +FROM klakegg/hugo WORKDIR /src COPY . /src -ARG GOHUGO_LINK=https://github.com/gohugoio/hugo/releases/download/v0.110.0/hugo_0.110.0_linux-amd64.tar.gz -RUN apk update && apk add curl tar -RUN curl -LJO ${GOHUGO_LINK} && tar -xf hugo_0.110.0_linux-amd64.tar.gz -RUN mv /src/hugo /usr/local/bin/hugo -RUN chmod +x /usr/local/bin/hugo RUN hugo -FROM nginx:stable-alpine -COPY --from=builder /src/public /var/www -COPY configs/nginx.conf /etc/nginx/conf.d/default.conf -EXPOSE 80 -CMD [ "nginx", "-g", "daemon off;" ] - diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 14f79af..8e3552f 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -24,35 +24,67 @@ spec: labels: {{- include "badhouseplants-net.selectorLabels" . | nindent 8 }} spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} + initContainers: + - name: {{ .Values.rclone.container.name }} + image: "{{ .Values.rclone.image.repository}}:{{ .Values.rclone.image.tag}}" + imagePullPolicy: {{ .Values.rclone.image.pullPolicy }} + env: + - name: RCLONE_CONFIG + value: /tmp/rclone.conf + command: + - sh + args: + - "-c" + - "rclone copy -P badhouseplants-public:/badhouseplants-static /static" + volumeMounts: + - name: rclone-config + mountPath: "/tmp" + readOnly: true + - name: {{ .Values.volumes.rclone }} + mountPath: /static + readOnly: false + resources: + {{- toYaml .Values.rclone.container.resources | nindent 12 }} + - name: {{ .Values.hugo.container.name }} + volumeMounts: + - name: {{ .Values.volumes.rclone.name }} + mountPath: /src/static + readOnly: true + - name: {{ .Values.volumes.public.name }} + mountPath: /src/public + readOnly: false + image: "{{ .Values.hugo.image.repository}}:{{ .Values.hugo.image.tag}}" + imagePullPolicy: {{ .Values.hugo.image.pullPolicy }} + resources: + {{- toYaml .Values.hugo.container.resources | nindent 12 }} containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + - name: {{ .Values.nginx.container.name }} + image: "{{ .Values.nginx.image.repository}}:{{ .Values.nginx.image.tag}}" + imagePullPolicy: {{ .Values.nginx.image.pullPolicy }} ports: - name: http containerPort: {{ .Values.service.port }} protocol: TCP resources: - {{- toYaml .Values.resources | nindent 12 }} - command: -{{ toYaml .Values.command | indent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- toYaml .Values.nginx.container.resources | nindent 12 }} + volumeMounts: + - name: {{ .Values.volumes.public.name }} + mountPath: /var/www + readOnly: true + - name: nginx-config + mountPath: /etc/nginx/conf.d + readOnly: true + volumes: + - name: rclone-config + secret: + secretName: rclone-config + - name: {{ .Values.volumes.rclone.name }} + emptyDir: + sizeLimit: {{ .Values.volumes.rclone.sizeLimit }} + - name: {{ .Values.volumes.public.name }} + emptyDir: + sizeLimit: {{ .Values.volumes.public.sizeLimit }} + - name: nginx-config + configMap: + name: nginx-config + diff --git a/chart/templates/nginx-config-cm.yaml b/chart/templates/nginx-config-cm.yaml new file mode 100644 index 0000000..2bcdf48 --- /dev/null +++ b/chart/templates/nginx-config-cm.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: nginx-config +data: + default.conf: | + server { + listen 80; + listen [::]:80; + server_name ~.; + root /var/www; + index index.html; + location / { + try_files $uri $uri/ =404; + } + } + diff --git a/chart/templates/rclone-config-sec.yaml b/chart/templates/rclone-config-sec.yaml new file mode 100644 index 0000000..7f0e023 --- /dev/null +++ b/chart/templates/rclone-config-sec.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: rclone-config +type: generic +data: + # the data is abbreviated in this example + rclone.conf: {{ .Values.rclone.config | b64enc }} diff --git a/chart/templates/virtual-service.yaml b/chart/templates/virtual-service.yaml new file mode 100644 index 0000000..7ed54b4 --- /dev/null +++ b/chart/templates/virtual-service.yaml @@ -0,0 +1,21 @@ +{{- if .Values.istio.enabled -}} +apiVersion: networking.istio.io/v1beta1 +kind: VirtualService +metadata: + annotations: + labels: + name: blog-virtual-service +spec: + gateways: + - istio-system/badhouseplants-net + hosts: {{ .Values.istio.hosts }} + http: + - match: + - uri: + prefix: {{ .Values.istio.prefix }} + route: + - destination: + host: {{ include "badhouseplants-net.fullname" . }} + port: + number: {{ .Values.service.port }} +{{- end }} diff --git a/chart/values.yaml b/chart/values.yaml index 7b69c68..66b5d4d 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,10 +1,66 @@ replicaCount: 1 -image: - repository: git.badhouseplants.net/allanger/badhouseplants-net - pullPolicy: Always - tag: latest +nginx: + container: + name: nginx + resources: {} + image: + repository: nginx + pullPolicy: Always + tag: latest + +rclone: + container: + name: rclone + resources: {} + image: + repository: rclone/rclone + pullPolicy: Always + tag: latest + config: |- + [badhouseplants-public] + type = s3 + provider = Minio + region = us-west-1 + endpoint = s3.badhouseplants.net + location_constraint = us-west-1 +hugo: + container: + name: badhouseplants-net + resources: {} + image: + repository: git.badhouseplants.net/allanger/badhouseplants-net + pullPolicy: Always + tag: latest + +istio: + enabled: true + hosts: + - badhouseplants.net + - www.badhouseplants.net + prefix: / + +volumes: + # ---------------------------------------------- + # -- An emptydir volume where hugo should + # -- put the static content + # ---------------------------------------------- + public: + name: public-content + sizeLimit: 1gi + # ---------------------------------------------- + # -- An emptydir volume where rclone should + # -- download pictures + # ---------------------------------------------- + rclone: + name: s3-data + sizeLimit: 1Gi + +# ------------------------------------- +# -- Default values that I haven't +# -- touched +# ------------------------------------- imagePullSecrets: [] nameOverride: "" fullnameOverride: "" @@ -30,29 +86,6 @@ service: ingress: enabled: false - annotations: - kubernetes.io/ingress.class: istio - hosts: - - host: badhouseplants.net - paths: - - path: / - pathType: Prefix - tls: - - secretName: badhouseplants-wildcard-tls - hosts: - - badhouseplants.net - -resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi autoscaling: enabled: false @@ -60,9 +93,3 @@ autoscaling: maxReplicas: 100 targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 - -nodeSelector: {} - -tolerations: [] - -affinity: {}