Cleanup: get uncloud running again
This commit is contained in:
parent
bf81ded5bf
commit
33d56bf083
10 changed files with 147 additions and 95 deletions
|
@ -1,4 +1,4 @@
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class MatrixhostingConfig(AppConfig):
|
class MatrixhostingConfig(AppConfig):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Django basics
|
# Django basics
|
||||||
Django==3.2.4
|
Django==4.0
|
||||||
djangorestframework
|
djangorestframework
|
||||||
django-auth-ldap
|
django-auth-ldap
|
||||||
fontawesome-free
|
fontawesome-free
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
ACTIVE_APP=nextcloud
|
ACTIVE_APP=nextcloud
|
||||||
ALLOWED_HOSTS=
|
ALLOWED_HOSTS='*'
|
||||||
STRIPE_KEY=
|
STRIPE_KEY=
|
||||||
STRIPE_PUBLIC_KEY=
|
STRIPE_PUBLIC_KEY=
|
||||||
DATABASE_ENGINE=django.db.backends.sqlite3
|
DATABASE_NAME=uncloud
|
||||||
DATABASE_NAME=
|
DATABASE_HOST=localhost
|
||||||
DATABASE_HOST=
|
|
||||||
DATABASE_PORT=
|
DATABASE_PORT=
|
||||||
DATABASE_USER=
|
DATABASE_USER=
|
||||||
DATABASE_PASSWORD=
|
DATABASE_PASSWORD=
|
||||||
|
|
|
@ -42,18 +42,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': env('DATABASE_ENGINE'),
|
|
||||||
'NAME': env('DATABASE_NAME') if env('DATABASE_NAME') else os.path.join(BASE_DIR, 'db.sqlite3'),
|
|
||||||
'USER': env('DATABASE_USER'),
|
|
||||||
'PASSWORD': env('DATABASE_PASSWORD'),
|
|
||||||
'HOST': env('DATABASE_HOST'),
|
|
||||||
'PORT': env('DATABASE_PORT'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||||
|
|
||||||
|
@ -73,12 +61,12 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
'mathfilters',
|
# 'mathfilters',
|
||||||
'compressor',
|
# 'compressor',
|
||||||
'wkhtmltopdf',
|
# 'wkhtmltopdf',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'django_q',
|
'django_q',
|
||||||
'notifications',
|
# 'notifications',
|
||||||
'uncloud',
|
'uncloud',
|
||||||
'uncloud_auth',
|
'uncloud_auth',
|
||||||
'uncloud_net',
|
'uncloud_net',
|
||||||
|
@ -86,13 +74,15 @@ INSTALLED_APPS = [
|
||||||
'uncloud_vm',
|
'uncloud_vm',
|
||||||
'uncloud_service',
|
'uncloud_service',
|
||||||
'opennebula',
|
'opennebula',
|
||||||
env('ACTIVE_APP'),
|
# env('ACTIVE_APP'),
|
||||||
'uncloud_pay', # should be after the active app to load the templates from the active app first
|
'uncloud_pay', # should be after the active app to load the templates from the active app first
|
||||||
'allauth',
|
# 'allauth',
|
||||||
'allauth.account',
|
# 'allauth.account',
|
||||||
'allauth.socialaccount',
|
# 'allauth.socialaccount',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
@ -104,7 +94,7 @@ MIDDLEWARE = [
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'uncloud.urls'
|
ROOT_URLCONF = 'uncloud.urls'
|
||||||
WKHTMLTOPDF_CMD = env('WKHTMLTOPDF_CMD')
|
#WKHTMLTOPDF_CMD = env('WKHTMLTOPDF_CMD')
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
|
@ -185,7 +175,7 @@ LDAP_MAX_UID_FILE_PATH = os.environ.get('LDAP_MAX_UID_FILE_PATH',
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
"django_auth_ldap.backend.LDAPBackend",
|
"django_auth_ldap.backend.LDAPBackend",
|
||||||
"django.contrib.auth.backends.ModelBackend",
|
"django.contrib.auth.backends.ModelBackend",
|
||||||
'allauth.account.auth_backends.AuthenticationBackend',
|
# 'allauth.account.auth_backends.AuthenticationBackend',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,7 +248,7 @@ MIN_PER_TRANSACTION = 5
|
||||||
# The django secret key
|
# The django secret key
|
||||||
SECRET_KEY=get_random_secret_key()
|
SECRET_KEY=get_random_secret_key()
|
||||||
|
|
||||||
ALLOWED_HOSTS = env('ALLOWED_HOSTS')
|
ALLOWED_HOSTS = ''
|
||||||
|
|
||||||
# required for hardcopy / pdf rendering: https://github.com/loftylabs/django-hardcopy
|
# required for hardcopy / pdf rendering: https://github.com/loftylabs/django-hardcopy
|
||||||
CHROME_PATH = '/usr/bin/chromium-browser'
|
CHROME_PATH = '/usr/bin/chromium-browser'
|
||||||
|
|
|
@ -16,7 +16,7 @@ from rest_framework.schemas import get_schema_view
|
||||||
from uncloud_net import views as netviews
|
from uncloud_net import views as netviews
|
||||||
from uncloud_pay import views as payviews
|
from uncloud_pay import views as payviews
|
||||||
from uncloud_vm import views as vmviews
|
from uncloud_vm import views as vmviews
|
||||||
import notifications.urls
|
#import notifications.urls
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
||||||
|
@ -56,14 +56,15 @@ urlpatterns = [
|
||||||
), name='openapi-schema'),
|
), name='openapi-schema'),
|
||||||
|
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('accounts/', include('allauth.urls')),
|
#path('accounts/', include('allauth.urls')),
|
||||||
path('pricing/<slug:name>/calculate/', payviews.PricingView.as_view(), name='pricing_calculator'),
|
path('pricing/<slug:name>/calculate/', payviews.PricingView.as_view(), name='pricing_calculator'),
|
||||||
path('cc/reg/', payviews.RegisterCard.as_view(), name="cc_register"),
|
path('cc/reg/', payviews.RegisterCard.as_view(), name="cc_register"),
|
||||||
path('inbox/notifications/', include(notifications.urls, namespace='notifications')),
|
# path('inbox/notifications/', include(notifications.urls, namespace='notifications')),
|
||||||
path('payments/', include('uncloud_pay.urls', namespace='payments')),
|
path('payments/', include('uncloud_pay.urls', namespace='payments')),
|
||||||
#
|
#
|
||||||
]
|
]
|
||||||
if env('ACTIVE_APP') == 'nextcloud':
|
|
||||||
urlpatterns.append(path('', include('nextcloud.urls', namespace='nextcloud')))
|
# if env('ACTIVE_APP') == 'nextcloud':
|
||||||
elif env('ACTIVE_APP') == 'matrixhosting':
|
# urlpatterns.append(path('', include('nextcloud.urls', namespace='nextcloud')))
|
||||||
urlpatterns.append(path('', include('matrixhosting.urls', namespace='matrix')))
|
# elif env('ACTIVE_APP') == 'matrixhosting':
|
||||||
|
# urlpatterns.append(path('', include('matrixhosting.urls', namespace='matrix')))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from allauth.account.forms import SignupForm, ChangePasswordForm, ResetPasswordKeyForm, SetPasswordForm
|
#from allauth.account.forms import SignupForm, ChangePasswordForm, ResetPasswordKeyForm, SetPasswordForm
|
||||||
from django import forms as d_forms
|
from django import forms as d_forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
|
@ -2,7 +2,6 @@ from django.contrib import admin
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.conf.urls import url
|
|
||||||
|
|
||||||
from hardcopy import bytestring_to_pdf
|
from hardcopy import bytestring_to_pdf
|
||||||
from django.core.files.temp import NamedTemporaryFile
|
from django.core.files.temp import NamedTemporaryFile
|
||||||
|
@ -20,72 +19,72 @@ class RecurringPeriodInline(admin.TabularInline):
|
||||||
class ProductAdmin(admin.ModelAdmin):
|
class ProductAdmin(admin.ModelAdmin):
|
||||||
inlines = [ RecurringPeriodInline ]
|
inlines = [ RecurringPeriodInline ]
|
||||||
|
|
||||||
class BillAdmin(admin.ModelAdmin):
|
# class BillAdmin(admin.ModelAdmin):
|
||||||
inlines = [ BillRecordInline ]
|
# inlines = [ BillRecordInline ]
|
||||||
|
|
||||||
def get_urls(self):
|
# def get_urls(self):
|
||||||
"""
|
# """
|
||||||
Create URLs for PDF view
|
# Create URLs for PDF view
|
||||||
"""
|
# """
|
||||||
|
|
||||||
info = "%s_%s" % (self.model._meta.app_label, self.model._meta.model_name)
|
# info = "%s_%s" % (self.model._meta.app_label, self.model._meta.model_name)
|
||||||
pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
|
# pat = lambda regex, fn: url(regex, self.admin_site.admin_view(fn), name='%s_%s' % (info, fn.__name__))
|
||||||
|
|
||||||
url_patterns = [
|
# url_patterns = [
|
||||||
pat(r'^([0-9]+)/as_pdf/$', self.as_pdf),
|
# pat(r'^([0-9]+)/as_pdf/$', self.as_pdf),
|
||||||
pat(r'^([0-9]+)/as_html/$', self.as_html),
|
# pat(r'^([0-9]+)/as_html/$', self.as_html),
|
||||||
] + super().get_urls()
|
# ] + super().get_urls()
|
||||||
|
|
||||||
return url_patterns
|
# return url_patterns
|
||||||
|
|
||||||
def as_pdf(self, request, object_id):
|
# def as_pdf(self, request, object_id):
|
||||||
bill = self.get_object(request, object_id=object_id)
|
# bill = self.get_object(request, object_id=object_id)
|
||||||
print(bill)
|
# print(bill)
|
||||||
|
|
||||||
if bill is None:
|
# if bill is None:
|
||||||
raise self._get_404_exception(object_id)
|
# raise self._get_404_exception(object_id)
|
||||||
|
|
||||||
output_file = NamedTemporaryFile()
|
# output_file = NamedTemporaryFile()
|
||||||
bill_html = render_to_string(
|
# bill_html = render_to_string(
|
||||||
"uncloud_pay/bill.html.j2",
|
# "uncloud_pay/bill.html.j2",
|
||||||
{
|
# {
|
||||||
'bill': bill,
|
# 'bill': bill,
|
||||||
'bill_records': bill.bill_records.all()
|
# 'bill_records': bill.bill_records.all()
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
|
|
||||||
bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
|
# bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
|
||||||
response = FileResponse(output_file, content_type="application/pdf")
|
# response = FileResponse(output_file, content_type="application/pdf")
|
||||||
response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
|
# response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
|
||||||
|
|
||||||
return response
|
# return response
|
||||||
|
|
||||||
def as_html(self, request, object_id):
|
# def as_html(self, request, object_id):
|
||||||
bill = self.get_object(request, object_id=object_id)
|
# bill = self.get_object(request, object_id=object_id)
|
||||||
|
|
||||||
if bill is None:
|
# if bill is None:
|
||||||
raise self._get_404_exception(object_id)
|
# raise self._get_404_exception(object_id)
|
||||||
|
|
||||||
return render(request, 'uncloud_pay/bill.html.j2',
|
# return render(request, 'uncloud_pay/bill.html.j2',
|
||||||
{'bill': bill,
|
# {'bill': bill,
|
||||||
'bill_records': bill.bill_records.all()
|
# 'bill_records': bill.bill_records.all()
|
||||||
})
|
# })
|
||||||
|
|
||||||
|
|
||||||
bill_html = render_to_string("bill.html.j2", {'bill': bill,
|
# bill_html = render_to_string("bill.html.j2", {'bill': bill,
|
||||||
'bill_records': bill.bill_records.all()
|
# 'bill_records': bill.bill_records.all()
|
||||||
})
|
# })
|
||||||
|
|
||||||
bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
|
# bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
|
||||||
response = FileResponse(output_file, content_type="application/pdf")
|
# response = FileResponse(output_file, content_type="application/pdf")
|
||||||
|
|
||||||
response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
|
# response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
|
||||||
|
|
||||||
return HttpResponse(template.render(context, request))
|
# return HttpResponse(template.render(context, request))
|
||||||
return response
|
# return response
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Bill, BillAdmin)
|
#admin.site.register(Bill, BillAdmin)
|
||||||
admin.site.register(Product, ProductAdmin)
|
admin.site.register(Product, ProductAdmin)
|
||||||
|
|
||||||
for m in [
|
for m in [
|
||||||
|
|
|
@ -18,7 +18,7 @@ from django.core.files.temp import NamedTemporaryFile
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
from django.http import FileResponse, HttpResponseRedirect
|
from django.http import FileResponse, HttpResponseRedirect
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from wkhtmltopdf.views import PDFTemplateResponse
|
#from wkhtmltopdf.views import PDFTemplateResponse
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
30
uncloud_v3/Dockerfile
Normal file
30
uncloud_v3/Dockerfile
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Currently not working due do ldap:
|
||||||
|
#
|
||||||
|
# /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lldap_r
|
||||||
|
#
|
||||||
|
# While trying to install python-ldap
|
||||||
|
|
||||||
|
FROM python:3.10.0-alpine3.15
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# FIX https://github.com/python-ldap/python-ldap/issues/432
|
||||||
|
RUN echo 'INPUT ( libldap.so )' > /usr/lib/libldap_r.so
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
# OS requirements for building wheel and for operating uncloud
|
||||||
|
RUN apk update && apk add \
|
||||||
|
gcc \
|
||||||
|
git \
|
||||||
|
libxml2-dev \
|
||||||
|
libxslt-dev \
|
||||||
|
libffi-dev \
|
||||||
|
openldap-dev \
|
||||||
|
postgresql-dev \
|
||||||
|
python3-dev \
|
||||||
|
musl-dev \
|
||||||
|
nginx \
|
||||||
|
wireguard-tools-wg
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
33
uncloud_v3/build.sh
Executable file
33
uncloud_v3/build.sh
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
name=uncloud:$(git describe)
|
||||||
|
docker build -t ${name} .
|
||||||
|
|
||||||
|
# check for args
|
||||||
|
if [ $# -ge 1 ]; then
|
||||||
|
target=$1; shift
|
||||||
|
else
|
||||||
|
target=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$target" in
|
||||||
|
dev)
|
||||||
|
url=harbor.default.svc.c2.k8s.ooo/ungleich-public
|
||||||
|
docker tag $name ${url}/${name}
|
||||||
|
docker push ${url}/${name}
|
||||||
|
;;
|
||||||
|
prod)
|
||||||
|
url=harbor.ungleich.svc.p10.k8s.ooo/ungleich-public
|
||||||
|
docker tag $name ${url}/${name}
|
||||||
|
docker push ${url}/${name}
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
echo "Not pushing anywhere"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument $target, ignoring"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
Loading…
Reference in a new issue