forked from Fediversity/Fediversity
Compare commits
16 commits
772901085b
...
fba4ab090c
Author | SHA1 | Date | |
---|---|---|---|
fba4ab090c | |||
df833063e2 | |||
d5fdc35e75 | |||
081a38eb6e | |||
dfcb18d7e7 | |||
92016a74c0 | |||
97c293e890 | |||
caef7e737e | |||
bc44d7fe05 | |||
a52f7ce648 | |||
4d950e2b38 | |||
ad00dcbc0f | |||
71abfb141c | |||
e07576b65e | |||
67ecaf3e27 | |||
a5107a2862 |
5 changed files with 87 additions and 41 deletions
panel/src/panel
|
@ -3,3 +3,24 @@ body
|
|||
margin: 0
|
||||
font-family: sans-serif
|
||||
box-sizing: border-box
|
||||
|
||||
.loader
|
||||
width: 48px
|
||||
height: 48px
|
||||
border: 5px solid #000
|
||||
border-bottom-color: #F34508
|
||||
border-radius: 50%
|
||||
box-sizing: border-box
|
||||
animation: rotation 1s linear infinite
|
||||
display: inline-block
|
||||
|
||||
@keyframes rotation
|
||||
0% { transform: rotate(0deg) }
|
||||
100% { transform: rotate(360deg) }
|
||||
|
||||
#spinner-container
|
||||
position: absolute
|
||||
top: 50%
|
||||
left: 50%
|
||||
transform: translate(-50%, -50%)
|
||||
display: block
|
|
@ -5,6 +5,7 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
|
||||
|
||||
{% load compress %}
|
||||
{% compress css %}
|
||||
|
|
|
@ -4,8 +4,21 @@
|
|||
{% csrf_token %}
|
||||
|
||||
{{ form.as_p }}
|
||||
<button id="deploy-button" class="button"
|
||||
hx-post="{% url 'deployment_status' %}"
|
||||
hx-trigger="click"
|
||||
hx-indicator="#spinner-container"
|
||||
hx-disabled-elt="this"
|
||||
hx-swap="none"
|
||||
name="deploy"
|
||||
>
|
||||
Deploy
|
||||
</button>
|
||||
|
||||
<button class="button" type="submit" name="deploy">Deploy</button>
|
||||
<button class="button" type="submit" name="save">Save</button>
|
||||
|
||||
<div id="spinner-container" class="htmx-indicator">
|
||||
<span class="loader"></span>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -26,4 +26,5 @@ urlpatterns = [
|
|||
path("account/", views.AccountDetail.as_view(), name='account_detail'),
|
||||
path("services/", views.ServiceList.as_view(), name='service_list'),
|
||||
path("configuration/", views.ConfigurationForm.as_view(), name='configuration_form'),
|
||||
path("deployment/status/", views.DeploymentStatus.as_view(), name='deployment_status'),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from enum import Enum
|
||||
import json
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
@ -11,7 +12,6 @@ from django.views.generic.edit import FormView
|
|||
from panel import models, settings
|
||||
from panel.configuration import forms
|
||||
|
||||
|
||||
class Index(TemplateView):
|
||||
template_name = 'index.html'
|
||||
|
||||
|
@ -33,51 +33,12 @@ class ConfigurationForm(LoginRequiredMixin, FormView):
|
|||
success_url = reverse_lazy('configuration_form')
|
||||
form_class = forms.Form
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
return context
|
||||
|
||||
def get_object(self):
|
||||
"""Get or create the configuration object for the current user"""
|
||||
obj, created = models.Configuration.objects.get_or_create(
|
||||
operator=self.request.user,
|
||||
)
|
||||
|
||||
# Check for deploy button
|
||||
if "deploy" in self.request.POST.keys():
|
||||
submission = obj.parsed_value.model_dump_json()
|
||||
# FIXME: let the user specify these from the form (#190)
|
||||
dummy_user = {
|
||||
"initialUser": {
|
||||
"displayName": "Testy McTestface",
|
||||
"username": "test",
|
||||
"password": "testtest",
|
||||
"email": "test@test.com",
|
||||
},
|
||||
}
|
||||
# serialize back and forth now we still need to manually inject the dummy user
|
||||
deployment = json.dumps(dummy_user | json.loads(submission))
|
||||
env = {
|
||||
"PATH": settings.nix_bin_dir,
|
||||
# pass in form info to our deployment
|
||||
"DEPLOYMENT": deployment,
|
||||
}
|
||||
cmd = [
|
||||
"nix",
|
||||
"develop",
|
||||
# workaround to pass in info to nixops4 thru env vars, tho impure :(
|
||||
"--extra-experimental-features",
|
||||
"configurable-impure-env",
|
||||
"--command",
|
||||
"nixops4",
|
||||
"apply",
|
||||
"test",
|
||||
]
|
||||
subprocess.run(
|
||||
cmd,
|
||||
cwd=settings.repo_dir,
|
||||
env=env,
|
||||
)
|
||||
return obj
|
||||
|
||||
# TODO(@fricklerhandwerk):
|
||||
|
@ -120,9 +81,58 @@ class ConfigurationForm(LoginRequiredMixin, FormView):
|
|||
initial.update(self.convert_enums_to_names(config_dict))
|
||||
return initial
|
||||
|
||||
class Save(ConfigurationForm):
|
||||
def form_valid(self, form):
|
||||
obj = self.get_object()
|
||||
obj.value = form.to_python().model_dump_json()
|
||||
obj.save()
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
class DeploymentStatus(ConfigurationForm):
|
||||
def form_valid(self, form):
|
||||
obj = self.get_object()
|
||||
obj.value = form.to_python().model_dump_json()
|
||||
obj.save()
|
||||
|
||||
# Check for deploy button
|
||||
if "deploy" in self.request.POST.keys():
|
||||
self.deployment(obj)
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
def deployment(self, obj):
|
||||
submission = obj.parsed_value.model_dump_json()
|
||||
# FIXME: let the user specify these from the form (#190)
|
||||
dummy_user = {
|
||||
"initialUser": {
|
||||
"displayName": "Testy McTestface",
|
||||
"username": "test",
|
||||
"password": "testtest",
|
||||
"email": "test@test.com",
|
||||
},
|
||||
}
|
||||
# serialize back and forth now we still need to manually inject the dummy user
|
||||
deployment = json.dumps(dummy_user | json.loads(submission))
|
||||
env = {
|
||||
"PATH": settings.nix_bin_dir,
|
||||
# pass in form info to our deployment
|
||||
"DEPLOYMENT": deployment,
|
||||
}
|
||||
cmd = [
|
||||
"nix",
|
||||
"develop",
|
||||
"--extra-experimental-features",
|
||||
"configurable-impure-env",
|
||||
"--command",
|
||||
"nixops4",
|
||||
"apply",
|
||||
"test",
|
||||
]
|
||||
deployment_result = subprocess.run(
|
||||
cmd,
|
||||
cwd=settings.repo_dir,
|
||||
env=env,
|
||||
)
|
||||
print(deployment_result)
|
||||
return deployment_result
|
Loading…
Add table
Reference in a new issue