Skip to content

Commit

Permalink
issue #61: create pull request to howard repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCardin committed Oct 30, 2024
1 parent fe54d82 commit dfa4b60
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
47 changes: 45 additions & 2 deletions webtop-template/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import sys
import os
from dotenv import load_dotenv

from jinja2 import Environment, FileSystemLoader
from github import Github

REPO_NAME = 'ai-cfia/howard'
FOLDER_PATH = 'templates'
TEMPLATES_NAMES = ['webtop-deployment.yaml.j2', 'webtop-ingress.yaml.j2', 'webtop-secrets.yaml.j2', 'kustomization.yaml.j2']
HOWARD_DUMB_FILE_FOLDER = 'kubernetes/aks/apps/webtop'
TEMPLATES_NAMES = ['webtop-deployment.yaml.j2', 'webtop-ingress.yaml.j2', 'webtop-secrets.yaml.j2']

def render_template(username):
file_loader = FileSystemLoader(FOLDER_PATH)
Expand All @@ -23,6 +28,44 @@ def render_template(username):
with open(output_filename, 'w') as f:
f.write(rendered_content)

def create_github_pr(username, gh_access_token):
g = Github(gh_access_token)
repo = g.get_repo(REPO_NAME)

branch_name = f"{username}-webtop-instance"

source = repo.get_branch('main')
repo.create_git_ref(ref=f'refs/heads/{branch_name}', sha=source.commit.sha)

for root, _, files in os.walk(username):
for file in files:
file_path = os.path.join(root, file)
with open(file_path, 'r') as file_content:
content = file_content.read()
repo_file_path = os.path.relpath(file_path, username)
repo_file_path = os.path.join(HOWARD_DUMB_FILE_FOLDER, file)
repo.create_file(
path=repo_file_path,
message=f'Adding {repo_file_path}',
content=content,
branch=branch_name
)

pr = repo.create_pull(
title=f'Adding new webtop instance for {username}',
body=f'Adding new webtop instance for {username}',
head=branch_name,
base='main'
)

print(f"Pull request created: {pr.html_url}")

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

load_dotenv()

gh_access_token = os.getenv("GITHUB_ACCESS_TOKEN")

render_template(username)
create_github_pr(username, gh_access_token)
4 changes: 3 additions & 1 deletion webtop-template/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
jinja2
jinja2
PyGithub
python-dotenv
8 changes: 0 additions & 8 deletions webtop-template/templates/kustomization.yaml.j2

This file was deleted.

24 changes: 23 additions & 1 deletion webtop-template/templates/webtop-deployment.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,41 @@ spec:
spec:
containers:
- name: webtop
image: linuxserver/webtop:ubuntu-kde
image: ghcr.io/ai-cfia/webtop-ubuntu-kde:main
ports:
- containerPort: 3000
env:
- name: DOCKER_HOST
value: "tcp://localhost:2375"
- name: DOCKER_TLS_CERTDIR
value: ""
envFrom:
- secretRef:
name: {{ username }}-webtop-secrets
volumeMounts:
- name: config
mountPath: /config
- name: docker-dind
image: docker:dind
securityContext:
privileged: true
ports:
- containerPort: 2375
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- "--host=tcp://0.0.0.0:2375"
- "--tls=false"
volumeMounts:
- name: docker-graph-storage
mountPath: /var/lib/docker
volumes:
- name: config
persistentVolumeClaim:
claimName: {{ username }}-webtop-config-pvc
- name: docker-graph-storage
emptyDir: {}

---
apiVersion: v1
Expand Down

0 comments on commit dfa4b60

Please sign in to comment.