Compare commits
26
Commits
a4a704305a
...
view
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80a75a445e | ||
|
|
385d42d0be | ||
|
|
2514603962 | ||
|
|
d071b135e7 | ||
|
|
433185df3e | ||
|
|
ccad16f38c | ||
|
|
c7e5afc750 | ||
|
|
80877663a9 | ||
|
|
ceaf0f0ef6 | ||
|
|
d6135402c2 | ||
|
|
fa365f956e | ||
|
|
82ed5d12e1 | ||
|
|
a9b6c92864 | ||
|
|
cc2d9e1b14 | ||
|
|
3dd8fdb7ca | ||
|
|
db20b291e3 | ||
|
|
096a71a7fc | ||
|
|
83d346b632 | ||
|
|
202797aed5 | ||
|
|
0cb583de09 | ||
|
|
bf19250116 | ||
|
|
e59e7b439d | ||
|
|
83e2ba5be2 | ||
|
|
7cc8891533 | ||
|
|
8a0cd24d69 | ||
|
|
1cb49c3127 |
@@ -1,6 +1,13 @@
|
|||||||
name: Gitea Actions Demo
|
name: Gitea Actions Demo
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
paths:
|
||||||
|
- 'dockerfile'
|
||||||
|
tags-ignore:
|
||||||
|
- '*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Explore-Gitea-Actions:
|
Explore-Gitea-Actions:
|
||||||
@@ -30,10 +37,4 @@ jobs:
|
|||||||
tags: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
tags: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
||||||
|
|
||||||
|
|
||||||
- name: Perform kubectl tasks
|
|
||||||
uses: actions-hub/kubectl@master
|
|
||||||
env:
|
|
||||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
|
||||||
with:
|
|
||||||
args: apply -f .
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: Gitea Actions Demo
|
||||||
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Explore-Gitea-Actions:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||||
|
- name: List files in the repository
|
||||||
|
run: |
|
||||||
|
ls ${{ gitea.workspace }}
|
||||||
|
|
||||||
|
- name: Perform kubectl tasks
|
||||||
|
uses: actions-hub/kubectl@master
|
||||||
|
env:
|
||||||
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
with:
|
||||||
|
args: apply -f .
|
||||||
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
*/__pycache__/*
|
||||||
@@ -20,8 +20,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: django-python
|
- name: django-python
|
||||||
# image: localhost:31795/django-python
|
image: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
||||||
image: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:1.0.0
|
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
=======
|
=======
|
||||||
# Django_kube
|
# Django_kube
|
||||||
|
test
|
||||||
|
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
{% load bootstrap5 %}
|
||||||
|
{% bootstrap_css %}
|
||||||
|
{% bootstrap_javascript %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1 class="display-1">Welcome to my website!</h1>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="list-group">
|
||||||
|
{% if thislist %}
|
||||||
|
<ul>
|
||||||
|
{% for question in thislist %}
|
||||||
|
<a href="#" class="list-group-item">{{ question }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No polls are available.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>My Website</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to my website!</h1>
|
||||||
|
{% if thislist %}
|
||||||
|
<ul>
|
||||||
|
{% for question in thislist %}
|
||||||
|
<h1>{{ question }}</h1>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No polls are available.</p>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
def home(request):
|
||||||
|
thislist = ["apple", "banana", "cherry"]
|
||||||
|
return render(request, 'home.html',{'thislist': thislist})
|
||||||
|
|
||||||
|
def about(request):
|
||||||
|
thislist = ["apple", "banana", "cherry"]
|
||||||
|
return render(request, 'about.html',{'thislist': thislist})
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-71%)_#e#o9-dl2o^6mfud-*rw+4+8vy-nd*bzeier&(34ap-p9
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['reverse.tryton.geeraert.eu','192.168.4.100','django.tryton.geeraert.eu']
|
ALLOWED_HOSTS = ['reverse.tryton.geeraert.eu','192.168.4.100','django.tryton.geeraert.eu','localhost']
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'bootstrap5',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -54,7 +55,8 @@ ROOT_URLCONF = 'django_code.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
#'DIRS': ["/code/django_code/templates","/code/django_code/dashboard/templates/"],
|
||||||
|
'DIRS': [BASE_DIR / "templates","django_code/dashboard/templates/"],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@@ -121,3 +123,4 @@ STATIC_URL = 'static/'
|
|||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
#
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ from django.urls import path
|
|||||||
from random_simpsons import apps as random_simpsons
|
from random_simpsons import apps as random_simpsons
|
||||||
from paperless_django import apps as paperless_django
|
from paperless_django import apps as paperless_django
|
||||||
from onenote import apps as onenote
|
from onenote import apps as onenote
|
||||||
from dashboard import apps as dashboard
|
from dashboard import apps as dashboardapp
|
||||||
|
from dashboard import views as dashboardview
|
||||||
|
from kubernetes_connection import apps as kubernetes_connection
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path('admin/', admin.site.urls),
|
# path('admin/', admin.site.urls),
|
||||||
@@ -38,9 +40,19 @@ urlpatterns = [
|
|||||||
path('onenote/hello/', onenote.hello),
|
path('onenote/hello/', onenote.hello),
|
||||||
|
|
||||||
################### onenote ###################
|
################### onenote ###################
|
||||||
path('dashboard/hello/', dashboard.hello),
|
path('dashboard/hello/', dashboardapp.hello),
|
||||||
|
path('dashboard/view/about', dashboardview.about),
|
||||||
|
path('dashboard/view/home', dashboardview.home),
|
||||||
|
|
||||||
|
|
||||||
|
################## kubernetes_connection#####
|
||||||
|
path('kubernetes_connection/hello/', kubernetes_connection.hello),
|
||||||
|
path('kubernetes_connection/nodes/', kubernetes_connection.nodes),
|
||||||
|
path('kubernetes_connection/backup_job/', kubernetes_connection.backup_job),
|
||||||
|
path('kubernetes_connection/backup_job_yaml/', kubernetes_connection.backup_job_yaml),
|
||||||
|
path('kubernetes_connection/scale_up/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_up),
|
||||||
|
path('kubernetes_connection/scale_down/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_down),
|
||||||
|
|
||||||
# path('bookstack/', docker_connection.apps.hello),
|
# path('bookstack/', docker_connection.apps.hello),
|
||||||
# path('test/', docker_connection.apps.http_call_test),
|
# path('test/', docker_connection.apps.http_call_test),
|
||||||
# path('proxmox/', docker_connection.apps.proxmox),
|
# path('proxmox/', docker_connection.apps.proxmox),
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
|
from django.core.files import File
|
||||||
|
from kubernetes import client, config
|
||||||
|
|
||||||
|
#from django.template.loader import render_to_string
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import mimetypes
|
||||||
|
import ruamel.yaml
|
||||||
|
import yaml
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
def hello(request):
|
||||||
|
return HttpResponse('<h1>Hello k8s!</h1>')
|
||||||
|
|
||||||
|
def scale_up(request,namespace_name,deploy_name):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
api = client.AppsV1Api()
|
||||||
|
deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name)
|
||||||
|
deployment.spec.replicas = 2
|
||||||
|
resp = api.patch_namespaced_deployment(
|
||||||
|
name=deploy_name, namespace=namespace_name, body=deployment);
|
||||||
|
return HttpResponse('<h1>Scaled up !</h1>')
|
||||||
|
|
||||||
|
|
||||||
|
def scale_down(request,namespace_name,deploy_name):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
api = client.AppsV1Api()
|
||||||
|
deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name)
|
||||||
|
deployment.spec.replicas = 0
|
||||||
|
resp = api.patch_namespaced_deployment(
|
||||||
|
name=deploy_name, namespace=namespace_name, body=deployment);
|
||||||
|
return HttpResponse('<h1>Scaled down !</h1>')
|
||||||
|
|
||||||
|
def nodes(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
v1 = client.CoreV1Api()
|
||||||
|
# v1.list_node()
|
||||||
|
pod_manifest = {
|
||||||
|
'apiVersion': 'v1',
|
||||||
|
'kind': 'Pod',
|
||||||
|
'metadata': {
|
||||||
|
'labels': {
|
||||||
|
'bot': 'current-bot'
|
||||||
|
},
|
||||||
|
'name': 'podname',
|
||||||
|
'namespace': 'echo-server'
|
||||||
|
|
||||||
|
},
|
||||||
|
'spec': {
|
||||||
|
|
||||||
|
'containers': [{
|
||||||
|
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
|
# 'pod-running-timeout': '5m0s',
|
||||||
|
'name': 'testpython',
|
||||||
|
'env': [
|
||||||
|
{'name': 'env_variable', 'value': 'env_value'},
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
'restartPolicy': 'Always',
|
||||||
|
# 'serviceAccountName': 'bots-service-account'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# print(f'POD MANIFEST:\n{pod_manifest}')
|
||||||
|
api_response = v1.create_namespaced_pod(body=pod_manifest,namespace='echo-server')
|
||||||
|
return HttpResponse(api_response)
|
||||||
|
|
||||||
|
def backup_job(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
v1 = client.CoreV1Api()
|
||||||
|
#v1 = client.BatchV1Api()
|
||||||
|
# v1.list_node()
|
||||||
|
pod_manifest_job = {
|
||||||
|
'apiVersion': 'batch/v1',
|
||||||
|
'kind': 'Job',
|
||||||
|
'metadata': {
|
||||||
|
'name': 'bitwarden-backup-django',
|
||||||
|
'namespace': 'bwbackup'
|
||||||
|
|
||||||
|
},
|
||||||
|
'spec': {
|
||||||
|
'template': {
|
||||||
|
'spec': {
|
||||||
|
|
||||||
|
'containers': [{
|
||||||
|
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
|
'name': 'testpython',
|
||||||
|
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
||||||
|
'env': [
|
||||||
|
{'name': 'env_variable', 'value': 'env_value'},
|
||||||
|
],
|
||||||
|
'volumeMounts': [
|
||||||
|
{'name': 'scripts', 'configMap': [{'name':'bitwarden-export-scripts'},]},
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
'restartPolicy': 'Always',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api_response = v1.create_namespaced_job(body=pod_manifest_job)
|
||||||
|
return HttpResponse(api_response)
|
||||||
|
|
||||||
|
|
||||||
|
#help with yaml import
|
||||||
|
#https://github.com/kubernetes-client/python/issues/589
|
||||||
|
|
||||||
|
def backup_job_yaml(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
v1 = client.BatchV1Api()
|
||||||
|
|
||||||
|
with urllib.request.urlopen(https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/pod.yaml") as manifest_url:
|
||||||
|
|
||||||
|
# with open('/code/pod.yaml') as :
|
||||||
|
job = yaml.safe_load(manifest_url)
|
||||||
|
v1.create_namespaced_job(
|
||||||
|
job['metadata']['namespace'], job, pretty=True
|
||||||
|
)
|
||||||
|
return HttpResponse(job['metadata']['namespace'])
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<h1>Hello template!</h1>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
def hello(request):
|
||||||
|
return HttpResponse('<h1>Hello Django!</h1>')
|
||||||
Binary file not shown.
@@ -2,9 +2,26 @@ from django.apps import AppConfig
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
import time
|
#from django.template.loader import render_to_string
|
||||||
import random
|
from django.template import loader
|
||||||
|
#import time
|
||||||
|
#import random
|
||||||
|
|
||||||
def hello(request):
|
def hello(request):
|
||||||
return HttpResponse('<h1>Hello onenote! <h1>')
|
# htmlContent = '
|
||||||
|
#<!DOCTYPE html>
|
||||||
|
#<html lang="en">
|
||||||
|
#<body>
|
||||||
|
#<strong>Hello World from const</strong>
|
||||||
|
#</body>
|
||||||
|
#</html>
|
||||||
|
#'
|
||||||
|
# response = "coucou"
|
||||||
|
# context = {'response': HttpResponse(response)}
|
||||||
|
# return HttpResponse(htmlContent)
|
||||||
|
# return HttpResponse('<h1>Hello onenote! <h1>')
|
||||||
|
# return render(request, 'hello.html', context)
|
||||||
|
|
||||||
|
template = loader.get_template('onenote/hello.html')
|
||||||
|
# template = loader.get_template('onenote/Roser.mht')
|
||||||
|
return HttpResponse(template.render())
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<strong>Hello World</strong>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -63,6 +63,6 @@ def simpsons(request):
|
|||||||
final_url = simpsons_url+str(random_seasons)+ "-episode-"+str(random_episode)#
|
final_url = simpsons_url+str(random_seasons)+ "-episode-"+str(random_episode)#
|
||||||
print(final_url)
|
print(final_url)
|
||||||
|
|
||||||
# return HttpResponse(str(final_url))
|
return HttpResponse(str(final_url))
|
||||||
# time.sleep(10)
|
# time.sleep(10)
|
||||||
return redirect(str(final_url))
|
# return redirect(str(final_url))
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<strong>Hello World template</strong>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -5,7 +5,9 @@ WORKDIR /code/
|
|||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
COPY django_code ./
|
COPY django_code ./
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN python django_code/manage.py migrate
|
||||||
|
|
||||||
CMD [ "python","django_code/manage.py","runserver","0.0.0.0:8000" ]
|
CMD [ "python","django_code/manage.py","runserver","0.0.0.0:8000" ]
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user