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

Automate webtop environment deployment using Jinja2 templating #399

Open
4 of 9 tasks
ThomasCardin opened this issue Oct 18, 2024 · 0 comments
Open
4 of 9 tasks

Automate webtop environment deployment using Jinja2 templating #399

ThomasCardin opened this issue Oct 18, 2024 · 0 comments
Assignees
Labels

Comments

@ThomasCardin
Copy link
Member

ThomasCardin commented Oct 18, 2024

Executive summary

The goal of this project is to streamline the deployment process for Webtop environments, facilitating rapid setup for new team members and existing team members needing development environments. By utilizing templating and automation, we can ensure consistent, efficient rollouts of these instances.

Users will be able to choose from the following instances for their Webtop deployment (source):

TODO

Exemples

templates/webtop-deployment.yaml.j2

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ name }}-webtop
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ name }}-webtop
  template:
    metadata:
      labels:
        app: {{ name }}-webtop
    spec:
      containers:
      - name: webtop
        image: linuxserver/webtop:ubuntu-kde
        ports:
        - containerPort: 3000
        envFrom:
        - secretRef:
            name: webtop-secrets
        volumeMounts:
        - name: config
          mountPath: /config
      volumes:
      - name: config
        persistentVolumeClaim:
          claimName: webtop-config-pvc

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

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ name }}-webtop-config-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

generete-template.py

import sys
from jinja2 import Environment, FileSystemLoader

def render_template(name):
    file_loader = FileSystemLoader('templates')
    env = Environment(loader=file_loader)
    
    template_name = 'webtop-deployment.yaml.j2'
    template = env.get_template(template_name)
    rendered_content = template.render(
        name=name,
    )
    
    output_filename = template_name.replace('.j2', '')
    with open(output_filename, 'w') as f:
        f.write(rendered_content)

if __name__ == '__main__':
    name = sys.argv[1]
    render_template(name)

webtop-deployment.yaml (template outcome):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: thomas-webtop
spec:
  replicas: 1
  selector:
    matchLabels:
      app: thomas-webtop
  template:
    metadata:
      labels:
        app: thomas-webtop
    spec:
      containers:
      - name: webtop
        image: linuxserver/webtop:ubuntu-kde
        ports:
        - containerPort: 3000
        envFrom:
        - secretRef:
            name: webtop-secrets
        volumeMounts:
        - name: config
          mountPath: /config
      volumes:
      - name: config
        persistentVolumeClaim:
          claimName: webtop-config-pvc

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

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: thomas-webtop-config-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
@ThomasCardin ThomasCardin self-assigned this Oct 18, 2024
ThomasCardin added a commit that referenced this issue Oct 18, 2024
ThomasCardin added a commit that referenced this issue Oct 22, 2024
ThomasCardin added a commit that referenced this issue Oct 23, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 25, 2024
ThomasCardin added a commit that referenced this issue Oct 30, 2024
@ThomasCardin ThomasCardin moved this to In Progress in DevSecOps Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Paused
Development

No branches or pull requests

1 participant