forked from Fediversity/Fediversity
Show if deployment succeeded (#283)
Show which services deployed and if so, the urls Co-authored-by: kevin <kevin@procolix.com> Reviewed-on: Fediversity/Fediversity#283 Reviewed-by: kiara Grouwstra <kiara@procolix.eu> Co-authored-by: lois <lois@procolix.eu> Co-committed-by: lois <lois@procolix.eu>
This commit is contained in:
parent
e25ff10872
commit
88674c8efc
3 changed files with 42 additions and 11 deletions
panel/src/panel
|
@ -9,7 +9,8 @@
|
|||
hx-trigger="click"
|
||||
hx-indicator="#spinner-container"
|
||||
hx-disabled-elt="this"
|
||||
hx-swap="none"
|
||||
hx-target="#deployment-result"
|
||||
hx-swap="innerHTML"
|
||||
name="deploy">
|
||||
Deploy
|
||||
</button>
|
||||
|
@ -19,5 +20,8 @@
|
|||
<div id="spinner-container" class="htmx-indicator">
|
||||
<span class="loader"></span>
|
||||
</div>
|
||||
|
||||
<div id="deployment-result">
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
13
panel/src/panel/templates/partials/deployment_result.html
Normal file
13
panel/src/panel/templates/partials/deployment_result.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% if deployment_status %}
|
||||
<p>{{ deployment_status }}</p>
|
||||
|
||||
<ul>
|
||||
{% for service, state in services.items %}
|
||||
{% if state %}
|
||||
<li>
|
||||
✓ {{ service }}
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
|
@ -9,10 +9,11 @@ from django.contrib.auth.models import User
|
|||
from django.views.generic import TemplateView, DetailView
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
from django.shortcuts import render
|
||||
from panel import models, settings
|
||||
from panel import models
|
||||
from panel.configuration import forms
|
||||
|
||||
|
||||
class Index(TemplateView):
|
||||
template_name = 'index.html'
|
||||
|
||||
|
@ -82,6 +83,7 @@ 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()
|
||||
|
@ -90,6 +92,7 @@ class Save(ConfigurationForm):
|
|||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class DeploymentStatus(ConfigurationForm):
|
||||
def form_valid(self, form):
|
||||
obj = self.get_object()
|
||||
|
@ -98,27 +101,38 @@ class DeploymentStatus(ConfigurationForm):
|
|||
|
||||
# Check for deploy button
|
||||
if "deploy" in self.request.POST.keys():
|
||||
self.deployment(obj)
|
||||
deployment_result, deployment_params = self.deployment(obj)
|
||||
if deployment_result.returncode == 0:
|
||||
deployment_status = "Deployment Succeeded"
|
||||
else:
|
||||
deployment_status = "Deployment Failed"
|
||||
|
||||
return super().form_valid(form)
|
||||
return render(self.request, "partials/deployment_result.html", {
|
||||
"deployment_status": deployment_status,
|
||||
"services": {
|
||||
"peertube": deployment_params['peertube']['enable'],
|
||||
"pixelfed": deployment_params['pixelfed']['enable'],
|
||||
"mastodon": deployment_params['mastodon']['enable']
|
||||
}
|
||||
})
|
||||
|
||||
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",
|
||||
"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))
|
||||
deployment_params = json.dumps(dummy_user | json.loads(submission))
|
||||
env = {
|
||||
"PATH": settings.bin_path,
|
||||
# pass in form info to our deployment
|
||||
"DEPLOYMENT": deployment,
|
||||
"DEPLOYMENT": deployment_params,
|
||||
}
|
||||
cmd = [
|
||||
"nix",
|
||||
|
@ -135,4 +149,4 @@ class DeploymentStatus(ConfigurationForm):
|
|||
cwd=settings.repo_dir,
|
||||
env=env,
|
||||
)
|
||||
return deployment_result
|
||||
return deployment_result, json.loads(deployment_params)
|
||||
|
|
Loading…
Add table
Reference in a new issue