Cleanup: get uncloud running again

This commit is contained in:
Nico Schottelius 2021-12-26 20:36:31 +01:00
parent bf81ded5bf
commit 33d56bf083
10 changed files with 147 additions and 95 deletions

View File

@ -1,4 +1,4 @@
from django.apps import AppConfig
from django.apps import AppConfig
class MatrixhostingConfig(AppConfig):

View File

@ -1,5 +1,5 @@
# Django basics
Django==3.2.4
Django==4.0
djangorestframework
django-auth-ldap
fontawesome-free

View File

@ -1,10 +1,9 @@
ACTIVE_APP=nextcloud
ALLOWED_HOSTS=
ALLOWED_HOSTS='*'
STRIPE_KEY=
STRIPE_PUBLIC_KEY=
DATABASE_ENGINE=django.db.backends.sqlite3
DATABASE_NAME=
DATABASE_HOST=
DATABASE_NAME=uncloud
DATABASE_HOST=localhost
DATABASE_PORT=
DATABASE_USER=
DATABASE_PASSWORD=
@ -29,4 +28,4 @@ AUTH_LDAP_BIND_PASSWORD=
LDAP_ADMIN_DN=
LDAP_ADMIN_PASSWORD=
LDAP_CUSTOMER_GROUP_ID=
LDAP_CUSTOMER_DN=
LDAP_CUSTOMER_DN=

View File

@ -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
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
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
@ -73,12 +61,12 @@ INSTALLED_APPS = [
'django.contrib.sites',
'django.contrib.staticfiles',
'django_extensions',
'mathfilters',
'compressor',
'wkhtmltopdf',
# 'mathfilters',
# 'compressor',
# 'wkhtmltopdf',
'rest_framework',
'django_q',
'notifications',
# 'notifications',
'uncloud',
'uncloud_auth',
'uncloud_net',
@ -86,13 +74,15 @@ INSTALLED_APPS = [
'uncloud_vm',
'uncloud_service',
'opennebula',
env('ACTIVE_APP'),
# env('ACTIVE_APP'),
'uncloud_pay', # should be after the active app to load the templates from the active app first
'allauth',
'allauth.account',
'allauth.socialaccount',
# 'allauth',
# 'allauth.account',
# 'allauth.socialaccount',
]
DEFAULT_AUTO_FIELD='django.db.models.AutoField'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@ -104,7 +94,7 @@ MIDDLEWARE = [
]
ROOT_URLCONF = 'uncloud.urls'
WKHTMLTOPDF_CMD = env('WKHTMLTOPDF_CMD')
#WKHTMLTOPDF_CMD = env('WKHTMLTOPDF_CMD')
TEMPLATES = [
{
@ -185,14 +175,14 @@ LDAP_MAX_UID_FILE_PATH = os.environ.get('LDAP_MAX_UID_FILE_PATH',
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend",
'allauth.account.auth_backends.AuthenticationBackend',
# 'allauth.account.auth_backends.AuthenticationBackend',
]
AUTH_USER_MODEL = 'uncloud_auth.User'
ACCOUNT_FORMS = {
'signup': 'uncloud_auth.forms.MySignupForm',
'signup': 'uncloud_auth.forms.MySignupForm',
'change_password': 'uncloud_auth.forms.MyChangePasswordForm',
'set_password': 'uncloud_auth.forms.MySetPasswordForm',
'reset_password_from_key': 'uncloud_auth.forms.MyResetPasswordKeyForm',
@ -258,7 +248,7 @@ MIN_PER_TRANSACTION = 5
# The django 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
CHROME_PATH = '/usr/bin/chromium-browser'

View File

@ -16,7 +16,7 @@ from rest_framework.schemas import get_schema_view
from uncloud_net import views as netviews
from uncloud_pay import views as payviews
from uncloud_vm import views as vmviews
import notifications.urls
#import notifications.urls
router = routers.DefaultRouter()
@ -56,14 +56,15 @@ urlpatterns = [
), name='openapi-schema'),
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('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')),
#
#
]
if env('ACTIVE_APP') == 'nextcloud':
urlpatterns.append(path('', include('nextcloud.urls', namespace='nextcloud')))
elif env('ACTIVE_APP') == 'matrixhosting':
urlpatterns.append(path('', include('matrixhosting.urls', namespace='matrix')))
# if env('ACTIVE_APP') == 'nextcloud':
# urlpatterns.append(path('', include('nextcloud.urls', namespace='nextcloud')))
# elif env('ACTIVE_APP') == 'matrixhosting':
# urlpatterns.append(path('', include('matrixhosting.urls', namespace='matrix')))

View File

@ -1,6 +1,6 @@
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.conf import settings
from django.utils.translation import gettext_lazy as _

View File

@ -2,7 +2,6 @@ from django.contrib import admin
from django.template.response import TemplateResponse
from django.urls import path
from django.shortcuts import render
from django.conf.urls import url
from hardcopy import bytestring_to_pdf
from django.core.files.temp import NamedTemporaryFile
@ -20,72 +19,72 @@ class RecurringPeriodInline(admin.TabularInline):
class ProductAdmin(admin.ModelAdmin):
inlines = [ RecurringPeriodInline ]
class BillAdmin(admin.ModelAdmin):
inlines = [ BillRecordInline ]
# class BillAdmin(admin.ModelAdmin):
# inlines = [ BillRecordInline ]
def get_urls(self):
"""
Create URLs for PDF view
"""
# def get_urls(self):
# """
# Create URLs for PDF view
# """
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__))
# 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__))
url_patterns = [
pat(r'^([0-9]+)/as_pdf/$', self.as_pdf),
pat(r'^([0-9]+)/as_html/$', self.as_html),
] + super().get_urls()
# url_patterns = [
# pat(r'^([0-9]+)/as_pdf/$', self.as_pdf),
# pat(r'^([0-9]+)/as_html/$', self.as_html),
# ] + super().get_urls()
return url_patterns
# return url_patterns
def as_pdf(self, request, object_id):
bill = self.get_object(request, object_id=object_id)
print(bill)
# def as_pdf(self, request, object_id):
# bill = self.get_object(request, object_id=object_id)
# print(bill)
if bill is None:
raise self._get_404_exception(object_id)
# if bill is None:
# raise self._get_404_exception(object_id)
output_file = NamedTemporaryFile()
bill_html = render_to_string(
"uncloud_pay/bill.html.j2",
{
'bill': bill,
'bill_records': bill.bill_records.all()
}
)
# output_file = NamedTemporaryFile()
# bill_html = render_to_string(
# "uncloud_pay/bill.html.j2",
# {
# 'bill': bill,
# 'bill_records': bill.bill_records.all()
# }
# )
bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
response = FileResponse(output_file, content_type="application/pdf")
response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
# bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
# response = FileResponse(output_file, content_type="application/pdf")
# response['Content-Disposition'] = f'filename="bill_{bill}.pdf"'
return response
# return response
def as_html(self, request, object_id):
bill = self.get_object(request, object_id=object_id)
# def as_html(self, request, object_id):
# bill = self.get_object(request, object_id=object_id)
if bill is None:
raise self._get_404_exception(object_id)
# if bill is None:
# raise self._get_404_exception(object_id)
return render(request, 'uncloud_pay/bill.html.j2',
{'bill': bill,
'bill_records': bill.bill_records.all()
})
# return render(request, 'uncloud_pay/bill.html.j2',
# {'bill': bill,
# 'bill_records': bill.bill_records.all()
# })
bill_html = render_to_string("bill.html.j2", {'bill': bill,
'bill_records': bill.bill_records.all()
})
# bill_html = render_to_string("bill.html.j2", {'bill': bill,
# 'bill_records': bill.bill_records.all()
# })
bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
response = FileResponse(output_file, content_type="application/pdf")
# bytestring_to_pdf(bill_html.encode('utf-8'), output_file)
# 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 response
# return HttpResponse(template.render(context, request))
# return response
admin.site.register(Bill, BillAdmin)
#admin.site.register(Bill, BillAdmin)
admin.site.register(Product, ProductAdmin)
for m in [

View File

@ -18,7 +18,7 @@ from django.core.files.temp import NamedTemporaryFile
from django.views.generic.list import ListView
from django.http import FileResponse, HttpResponseRedirect
from django.template.loader import render_to_string
from wkhtmltopdf.views import PDFTemplateResponse
#from wkhtmltopdf.views import PDFTemplateResponse
from copy import deepcopy
import json
@ -35,7 +35,7 @@ import uncloud_pay.stripe as uncloud_stripe
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.http import JsonResponse
import stripe
import stripe
logger = logging.getLogger(__name__)
@ -47,14 +47,14 @@ class PricingView(View):
address = False
selected_country = request.GET.get('country', False)
if self.request.user and self.request.user.is_authenticated:
address = get_billing_address_for_user(self.request.user)
address = get_billing_address_for_user(self.request.user)
if address and (address.country == selected_country or not selected_country):
vat_rate = VATRate.get_vat_rate(address)
vat_validation_status = "verified" if address.vat_number_validated_on and address.vat_number_verified else False
elif selected_country:
vat_rate = VATRate.get_vat_rate_for_country(selected_country)
vat_validation_status = False
pricing = get_order_total_with_vat(
request.GET.get('cores'),
request.GET.get('memory'),
@ -104,13 +104,13 @@ class OrderSuccessView(DetailView):
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
def get(self, request, *args, **kwargs):
if ('order' not in request.session or ('bill_id' not in request.session)):
return HttpResponseRedirect(reverse('nextcloud:index'))
return HttpResponseRedirect(reverse('nextcloud:index'))
context = {
'order': self.request.session.get('order'),
'bill_id': self.request.session['bill_id'],
'balance': get_balance_for_user(self.request.user)
'balance': get_balance_for_user(self.request.user)
}
return render(request, self.template_name, context)
return render(request, self.template_name, context)
class InvoiceDownloadView(View):
template = 'uncloud_pay/invoice.html'

30
uncloud_v3/Dockerfile Normal file
View 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
View 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