forked from fediversity/fediversity
Compare commits
14 commits
2ed7f3ebe5
...
caa497c4a2
| Author | SHA1 | Date | |
|---|---|---|---|
| caa497c4a2 | |||
| 659a3593b5 | |||
| 7e24b9e478 | |||
| 7048058d6b | |||
| ed63b582ed | |||
| f04e1d0f40 | |||
| 2365d9a044 | |||
| ecc41a7dfd | |||
| 0419ec38f5 | |||
| 65bba16d83 | |||
| 264fbf8729 | |||
| 65159cdc18 | |||
| 6bb5768ddc | |||
| 88674c8efc |
3 changed files with 44 additions and 13 deletions
|
|
@ -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 %}
|
||||
|
|
@ -10,10 +10,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'
|
||||
|
||||
|
|
@ -83,6 +84,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()
|
||||
|
|
@ -91,6 +93,7 @@ class Save(ConfigurationForm):
|
|||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class DeploymentStatus(ConfigurationForm):
|
||||
def form_valid(self, form):
|
||||
obj = self.get_object()
|
||||
|
|
@ -99,23 +102,34 @@ 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",
|
||||
},
|
||||
"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 = dummy_user | json.loads(submission)
|
||||
deployment_params = dummy_user | json.loads(submission)
|
||||
env = {
|
||||
"PATH": settings.bin_path,
|
||||
# used in nixos-anywhere for ssh-copy-id
|
||||
|
|
@ -124,7 +138,7 @@ class DeploymentStatus(ConfigurationForm):
|
|||
} | {
|
||||
# pass in form info to our deployment
|
||||
# FIXME: ensure sensitive info is protected
|
||||
f"TF_VAR_{k}": v if isinstance(v, str) else json.dumps(v) for k, v in deployment.items()
|
||||
f"TF_VAR_{k}": v if isinstance(v, str) else json.dumps(v) for k, v in deployment_params.items()
|
||||
}
|
||||
cwd = f"{settings.repo_dir}/launch"
|
||||
# FIXME: move init to packaging phase
|
||||
|
|
@ -138,4 +152,4 @@ class DeploymentStatus(ConfigurationForm):
|
|||
]
|
||||
deployment_result = subprocess.run(cmd, cwd=cwd, env=env)
|
||||
print(deployment_result)
|
||||
return deployment_result
|
||||
return deployment_result, deployment_params
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue