Skip to content
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

Webtop template with workflow integration #62

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions webtop-template/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import os
from jinja2 import Environment, FileSystemLoader

FOLDER_PATH = 'templates'
TEMPLATES_NAMES = ['webtop-deployment.yaml.j2', 'webtop-ingress.yaml.j2', 'webtop-secrets.yaml.j2', 'kustomization.yaml.j2']

def render_template(username):
file_loader = FileSystemLoader(FOLDER_PATH)
env = Environment(loader=file_loader)
Dismissed Show dismissed Hide dismissed

os.makedirs(username, exist_ok=True)

for i in TEMPLATES_NAMES:
template_name = i
template = env.get_template(template_name)
rendered_content = template.render(
username=username,
)

base_name = template_name.replace('.j2', '')
output_filename = os.path.join(username, f"{username}-{base_name}")
with open(output_filename, 'w') as f:
f.write(rendered_content)

if __name__ == '__main__':
username = sys.argv[1]
render_template(username)
1 change: 1 addition & 0 deletions webtop-template/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jinja2
8 changes: 8 additions & 0 deletions webtop-template/templates/kustomization.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- {{ username }}-webtop-deployment.yaml
- {{ username }}-webtop-ingress.yaml
- {{ username }}-webtop-secrets.yaml
55 changes: 55 additions & 0 deletions webtop-template/templates/webtop-deployment.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ username }}-webtop
spec:
replicas: 1
selector:
matchLabels:
app: {{ username }}-webtop
template:
metadata:
labels:
app: {{ username }}-webtop
spec:
containers:
- name: webtop
image: linuxserver/webtop:ubuntu-kde
ports:
- containerPort: 3000
envFrom:
- secretRef:
name: {{ username }}-webtop-secrets
volumeMounts:
- name: config
mountPath: /config
volumes:
- name: config
persistentVolumeClaim:
claimName: webtop-config-pvc

---
apiVersion: v1
kind: Service
metadata:
name: {{ username }}-webtop-service
spec:
type: ClusterIP
selector:
app: webtop
ports:
- protocol: TCP
port: 3000
targetPort: 3000

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ username }}-webtop-config-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
32 changes: 32 additions & 0 deletions webtop-template/templates/webtop-ingress.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# For more information check https://github.com/nginxinc/kubernetes-ingress/issues/323
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ username }}-webtop-ingress
annotations:
nginx.ingress.kubernetes.io/whitelist-source-range: 205.194.32.0/24,10.244.0.0/16,192.197.71.0/24
external-dns.alpha.kubernetes.io/target: inspection.alpha.canada.ca
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/add-base-url: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/client_max_body_size: "200m"
nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
ingress.kubernetes.io/force-ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- {{ username }}-webtop.inspection.alpha.canada.ca
secretName: webtop-tls
rules:
- host: {{ username }}-webtop.inspection.alpha.canada.ca
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ username }}-webtop-service
port:
number: 3000
14 changes: 14 additions & 0 deletions webtop-template/templates/webtop-secrets.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: Secret
apiVersion: v1
metadata:
name: {{ username }}-webtop-secrets
annotations:
avp.kubernetes.io/path: "kv/data/webtop/test"
avp.kubernetes.io/secret-version: "1"
stringData:
PUID: <PUID>
PGID: <PGID>
TZ: <TZ>
TITLE: <TITLE>
CUSTOM_USER: <CUSTOM_USER>
PASSWORD: <PASSWORD>
Loading