1.6.0 Updates

- Front envvars supplied by .env.production for vite build
- Backend API is now prefixed at /v1/api
- New push-all builds both backend and frontend images
- helm chart adds a postgres database with services and a persistent volume using nfs
master
Drew Bednar 3 years ago
parent 55e0a10d01
commit 310da309e2

@ -1,27 +1,37 @@
REGISTRY_NAME=registry.runcible.io REGISTRY_NAME=registry.runcible.io
FRONTEND_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-frontend FRONTEND_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-frontend
FRONTEND_IMAGE_VERSION=1.4.0-dev FRONTEND_IMAGE_VERSION=1.6.0
API_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-api API_IMAGE_NAME=$(REGISTRY_NAME)/demo-helm-api
API_IMAGE_VERSION=1.4.0-dev API_IMAGE_VERSION=1.6.0
push-all: push-app-image push-api-image
.PHONY: push-all
push-app-image: build-app-image push-app-image: build-app-image
docker push $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) docker push $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION)
.PHONY: push-app-image
build-app-image: build-app-image:
docker build -t $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) ./app docker build -t $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) ./app
.PHONY: build-app-image
push-api-image: build-api-image push-api-image: build-api-image
docker push $(API_IMAGE_NAME):$(API_IMAGE_VERSION) docker push $(API_IMAGE_NAME):$(API_IMAGE_VERSION)
.PHONY: push-api-image
build-api-image: build-api-image:
docker build -t $(API_IMAGE_NAME):$(API_IMAGE_VERSION) ./api docker build -t $(API_IMAGE_NAME):$(API_IMAGE_VERSION) ./api
.PHONY: build-api-image
update-API-deps: update-API-deps:
pip-compile -o api/requirements.txt api/requirements.in pip-compile -o api/requirements.txt api/requirements.in
.PHONY: update-API-deps
sync-virtualenv: sync-virtualenv:
pip-sync dev_requirements.txt api/requirements.txt pip-sync dev_requirements.txt api/requirements.txt
.PHONY: sync-virtualenv
check-images: check-images:
echo $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION) echo $(FRONTEND_IMAGE_NAME):$(FRONTEND_IMAGE_VERSION)
echo $(API_IMAGE_NAME):$(API_IMAGE_VERSION) echo $(API_IMAGE_NAME):$(API_IMAGE_VERSION)
.PHONY: check-images

@ -66,6 +66,13 @@ Then you need to specify the secret in your deployment spec like so:
- name: regcred - name: regcred
``` ```
## Creating the Database password as a secret
```
kubectl -n <your namespace> create secret generic database_secret \
--from-literal=password=<your secret>
```
[The k8s docs](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line) [The k8s docs](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line)
# References # References

@ -3,7 +3,7 @@ from flask import Blueprint, jsonify
from .models import Cookie from .models import Cookie
main_blueprint = Blueprint("main", __name__) main_blueprint = Blueprint("main", __name__, url_prefix='/v1/api')
__version__ = "1.2.0" __version__ = "1.2.0"

@ -0,0 +1 @@
VITE_BACKEND_URI = "https://lab.runcible.io/v1/api"

1
app/.gitignore vendored

@ -3,3 +3,4 @@ node_modules
dist dist
dist-ssr dist-ssr
*.local *.local
.env.local

@ -1,7 +1,7 @@
import axios from 'axios' import axios from 'axios'
const apiClient = axios.create({ const apiClient = axios.create({
baseURL: 'http://backend.runcible.io', baseURL: import.meta.env.VITE_BACKEND_URI,
withCredentials: false, withCredentials: false,
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',

@ -1,7 +1,7 @@
--- ---
apiVersion: v2 apiVersion: v2
name: demo-helm name: demo-helm
appVersion: 1.2.0 appVersion: 1.6.0
description: A Helm chart to practice helm description: A Helm chart to practice helm
version: 0.3.0 version: 0.4.0
type: application type: application

@ -6,6 +6,7 @@ metadata:
labels: labels:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service
namespace: {{ .Values.namespace }}
spec: spec:
ports: ports:
- protocol: 'TCP' - protocol: 'TCP'

@ -5,9 +5,11 @@ metadata:
# This allows us to ensure we have a unique config name. Which means we could have two of the same service # This allows us to ensure we have a unique config name. Which means we could have two of the same service
# in the same namespace. # in the same namespace.
name: {{ .Release.Name }}-{{ .Chart.Name}}-backend name: {{ .Release.Name }}-{{ .Chart.Name}}-backend
namespace: {{ .Values.namespace }}
labels: labels:
app: {{ .Release.Name }}-{{ .Chart.Name}}-backend app: {{ .Release.Name }}-{{ .Chart.Name}}-backend
spec: spec:
# TODO add probes for health and wellness
{{- with .Values.services.backend }} {{- with .Values.services.backend }}
replicas: {{ .replicas }} replicas: {{ .replicas }}
selector: selector:
@ -33,6 +35,32 @@ spec:
configMapKeyRef: configMapKeyRef:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap
key: random_data key: random_data
- name: POSTGRES_HOST
# Should resolve to the DNS name of the database service
value: {{ $.Release.Name }}-{{ $.Chart.Name }}-database-service
- name: POSTGRES_APP_DATABASE
valueFrom:
configMapKeyRef:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap
key: database_name
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap
key: database_user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $.Values.services.database.database_secret }}
key: {{ $.Values.services.database.database_passwd_key }}
- name: POSTGRES_PORT
valueFrom:
configMapKeyRef:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap
key: database_port
- name: SQLALCHEMY_URI
# This works because https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#envvar-v1-core
value: "postgresql://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_APP_DATABASE)"
imagePullSecrets: imagePullSecrets:
- name: {{ $.Values.image_pull_secret }} - name: {{ $.Values.image_pull_secret }}
{{- end }} {{- end }}

@ -2,5 +2,9 @@ apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap name: {{ $.Release.Name }}-{{ $.Chart.Name}}-configmap
namespace: {{ .Values.namespace }}
data: data:
random_data: {{ .Values.random | quote }} random_data: {{ .Values.random | quote }}
database_name: {{ .Values.services.database.database_name | quote }}
database_port: {{ .Values.services.database.database_port | default "5432" | quote }}
database_user: {{ .Values.services.database.database_user | default "postgres" | quote }}

@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-database-service
namespace: {{ .Values.namespace }}
spec:
ports:
- port: 5432
protocol: TCP
selector:
app: {{ .Release.Name }}-{{ .Chart.Name }}-database

@ -0,0 +1,55 @@
# This is a singleton postgres pod with a Persistent Volume Claim to an
# NFS backed volume. See nfs-volume.yaml and nfs-volume-claim.yaml
# It will be exposed as a service to the runcible namespace in mypostgres-service.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-database
namespace: {{ .Values.namespace }}
labels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-database
spec:
# Since this is a singleton
replicas: 1
selector:
matchLabels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-database
template:
metadata:
labels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-database
spec:
containers:
- name: {{ .Release.Name }}-{{ .Chart.Name }}-database
image: {{ .Values.services.database.image_name }}
# This is a dev server effectively
resources:
requests:
cpu: 1
memory: 2Gi
env:
# Convert this over to use secrets instead
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.services.database.database_secret }}
key: {{ .Values.services.database.database_passwd_key }}
- name: POSTGRES_USER
value: {{ .Values.services.database.database_user }}
- name: POSTGRES_DB
value: {{ .Values.services.database.database_name }}
livenessProbe:
tcpSocket:
port: 5432
initialDelaySeconds: 180
periodSeconds: 10
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
# The name of our pvc
claimName: {{ .Values.services.database.persistent_volume_claim }}

@ -6,6 +6,7 @@ metadata:
labels: labels:
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-frontend-service name: {{ $.Release.Name }}-{{ $.Chart.Name}}-frontend-service
name: {{ $.Release.Name }}-{{ $.Chart.Name}}-frontend-service name: {{ $.Release.Name }}-{{ $.Chart.Name}}-frontend-service
namespace: {{ .Values.namespace }}
spec: spec:
ports: ports:
- protocol: 'TCP' - protocol: 'TCP'

@ -5,9 +5,11 @@ metadata:
# This allows us to ensure we have a unique config name. Which means we could have two of the same service # This allows us to ensure we have a unique config name. Which means we could have two of the same service
# in the same namespace. # in the same namespace.
name: {{ .Release.Name }}-{{ .Chart.Name }}-frontend name: {{ .Release.Name }}-{{ .Chart.Name }}-frontend
namespace: {{ .Values.namespace }}
labels: labels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-frontend app: {{ .Release.Name }}-{{ .Chart.Name }}-frontend
spec: spec:
# TODO add probes for health and wellness
{{- with .Values.services.frontend }} {{- with .Values.services.frontend }}
replicas: {{ .replicas }} replicas: {{ .replicas }}
selector: selector:

@ -4,6 +4,7 @@ kind: Ingress
# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata # https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
metadata: metadata:
name: {{ .Release.Name }}-{{ .Chart.Name}}-backend-ingress name: {{ .Release.Name }}-{{ .Chart.Name}}-backend-ingress
namespace: {{ .Values.namespace }}
spec: spec:
rules: rules:
- host: backend.runcible.io - host: backend.runcible.io
@ -22,6 +23,7 @@ kind: Ingress
# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata # https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
metadata: metadata:
name: {{ .Release.Name }}-{{ .Chart.Name}}-frontend-ingress name: {{ .Release.Name }}-{{ .Chart.Name}}-frontend-ingress
namespace: {{ .Values.namespace }}
spec: spec:
rules: rules:
- host: frontend.runcible.io - host: frontend.runcible.io

@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .Values.services.database.persistent_volume }}
namespace: {{ .Values.namespace }}
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: {{ .Values.services.database.nfs_server }}
path: {{ .Values.services.database.nfs_path }}

@ -0,0 +1,15 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.services.database.persistent_volume_claim }}
namespace: {{ .Values.namespace }}
spec:
# By specifying a PersistentVolume in a PersistentVolumeClaim, you declare a binding between that specific PV and PVC.
volumeName: {{ .Values.services.database.persistent_volume }}
accessModes:
- ReadWriteMany
# Empty string must be explicitly set otherwise default StorageClass will be set
storageClassName: ''
resources:
requests:
storage: 10Gi

@ -1,12 +1,24 @@
--- ---
image_pull_secret: regcred image_pull_secret: "regcred"
namespace: "demo-helm"
services: services:
frontend: frontend:
image_name: "registry.runcible.io/demo-helm-frontend" image_name: "registry.runcible.io/demo-helm-frontend"
image_version: "1.4.0" image_version: "1.6.0"
replicas: 1 replicas: 1
backend: backend:
image_name: "registry.runcible.io/demo-helm-api" image_name: "registry.runcible.io/demo-helm-api"
image_version: "1.4.0" image_version: "1.6.0"
replicas: 1 replicas: 1
database:
database_name: "demo_helm"
database_user: "toor"
database_secret: "database-secret"
database_passwd_key: "password"
image_name: "postgres:12-alpine"
nfs_path: "/volume1/expanse/demo_helm"
nfs_server: "nas1.runcible.io"
persistent_volume: "demo-helm-db-pv"
persistent_volume_claim: "demo-helm-db-pvc"
random: "tis-random-default" random: "tis-random-default"
Loading…
Cancel
Save