Browse Source

Preparado para k8s

politica
Celestino Rey 1 year ago
parent
commit
cd3297f05d
23 changed files with 77 additions and 110 deletions
  1. +1
    -0
      Finanzas/.dockerignore
  2. +1
    -1
      Finanzas/Dockerfile
  3. +3
    -3
      Finanzas/K8S/Makefile
  4. +9
    -4
      Finanzas/K8S/finanzas-deployment.yaml
  5. +18
    -3
      Finanzas/K8S/finanzas-prod-persistentvolumeclaim.yaml
  6. +17
    -2
      Finanzas/K8S/pv-local-finanzas.yaml
  7. +1
    -1
      Finanzas/K8S/verImg.sh
  8. +1
    -1
      Finanzas/README.md
  9. +1
    -0
      Finanzas/finanzas/.dockerignore
  10. +0
    -1
      Finanzas/finanzas/apuntes/admin.py
  11. +0
    -42
      Finanzas/finanzas/apuntes/migrations/0001_initial.py
  12. +0
    -0
      Finanzas/finanzas/apuntes/migrations/__init__.py
  13. +4
    -1
      Finanzas/finanzas/apuntes/models.py
  14. +1
    -1
      Finanzas/finanzas/apuntes/views.py
  15. +9
    -6
      Finanzas/finanzas/finanzas/settings.py
  16. +1
    -2
      Finanzas/finanzas/finanzas/urls.py
  17. +1
    -0
      Finanzas/finanzas/reymotausers/admin.py
  18. +1
    -0
      Finanzas/finanzas/reymotausers/forms.py
  19. +0
    -34
      Finanzas/finanzas/reymotausers/migrations/0001_initial.py
  20. +0
    -0
      Finanzas/finanzas/reymotausers/migrations/__init__.py
  21. +1
    -1
      Finanzas/finanzas/reymotausers/models.py
  22. +2
    -2
      Finanzas/nginx/Makefile
  23. +5
    -5
      Finanzas/nginx/nginx.conf

+ 1
- 0
Finanzas/.dockerignore View File

@ -2,3 +2,4 @@ Dockerfile
Makefile Makefile
volcadossql/ volcadossql/
venv/ venv/
migrations/

+ 1
- 1
Finanzas/Dockerfile View File

@ -67,7 +67,7 @@ COPY . $APP_HOME
# change to the app user # change to the app user
#USER app #USER app
WORKDIR $APP_HOME/vehiculos
WORKDIR $APP_HOME/finanzas
# run entrypoint.sh # run entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]

+ 3
- 3
Finanzas/K8S/Makefile View File

@ -1,7 +1,7 @@
export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
#export REGISTRY=registry.cube.local #export REGISTRY=registry.cube.local
export REGISTRY=registry.reymota.es export REGISTRY=registry.reymota.es
export IMG_VERSION = 1.16
export IMG_VERSION = 0.3
export IMG_NGINX_VERSION = 1.0 export IMG_NGINX_VERSION = 1.0
# limpia todo # limpia todo
@ -18,8 +18,8 @@ install:
-kubectl create -f pv-local-finanzas.yaml -kubectl create -f pv-local-finanzas.yaml
-kubectl create -f finanzas-prod-persistentvolumeclaim.yaml -kubectl create -f finanzas-prod-persistentvolumeclaim.yaml
-kubectl create -f static-volume-persistentvolumeclaim.yaml
-kubectl create -f postgres-data-persistentvolumeclaim.yaml -kubectl create -f postgres-data-persistentvolumeclaim.yaml
-kubectl create -f static-volume-persistentvolumeclaim.yaml
-kubectl create -f db-deployment.yaml -kubectl create -f db-deployment.yaml
-kubectl create -f db-service.yaml -kubectl create -f db-service.yaml
@ -39,8 +39,8 @@ clean:
-kubectl delete -f env-prod-configmap.yaml -kubectl delete -f env-prod-configmap.yaml
-kubectl delete -f env-prod-db-configmap.yaml -kubectl delete -f env-prod-db-configmap.yaml
-kubectl delete -f postgres-data-persistentvolumeclaim.yaml
-kubectl delete -f static-volume-persistentvolumeclaim.yaml -kubectl delete -f static-volume-persistentvolumeclaim.yaml
-kubectl delete -f postgres-data-persistentvolumeclaim.yaml
-kubectl delete -f finanzas-prod-persistentvolumeclaim.yaml -kubectl delete -f finanzas-prod-persistentvolumeclaim.yaml
-kubectl delete -f pv-local-finanzas.yaml -kubectl delete -f pv-local-finanzas.yaml
-kubectl delete -f reg-secret.yaml -kubectl delete -f reg-secret.yaml


+ 9
- 4
Finanzas/K8S/finanzas-deployment.yaml View File

@ -104,8 +104,10 @@ spec:
volumeMounts: volumeMounts:
- mountPath: /app/finanzas/mediafiles - mountPath: /app/finanzas/mediafiles
name: finanzas-media name: finanzas-media
- mountPath: /app/finanzas/repostajes/migrations
name: finanzas-migrations
- mountPath: /app/finanzas/apuntes/migrations
name: apuntes-migrations
- mountPath: /app/finanzas/reymotausers/migrations
name: reymotausers-migrations
- mountPath: /app/finanzas/staticfiles - mountPath: /app/finanzas/staticfiles
name: static-volume name: static-volume
imagePullSecrets: imagePullSecrets:
@ -115,9 +117,12 @@ spec:
- name: finanzas-media - name: finanzas-media
persistentVolumeClaim: persistentVolumeClaim:
claimName: finanzas-media claimName: finanzas-media
- name: finanzas-migrations
- name: apuntes-migrations
persistentVolumeClaim: persistentVolumeClaim:
claimName: finanzas-migrations
claimName: apuntes-migrations
- name: reymotausers-migrations
persistentVolumeClaim:
claimName: reymotausers-migrations
- name: static-volume - name: static-volume
persistentVolumeClaim: persistentVolumeClaim:
claimName: static-volume claimName: static-volume


+ 18
- 3
Finanzas/K8S/finanzas-prod-persistentvolumeclaim.yaml View File

@ -19,8 +19,24 @@ kind: PersistentVolumeClaim
metadata: metadata:
creationTimestamp: null creationTimestamp: null
labels: labels:
io.kompose.service: finanzas-migrations
name: finanzas-migrations
io.kompose.service: apuntes-migrations
name: apuntes-migrations
namespace: finanzas
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
status: {}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: reymotausers-migrations
name: reymotausers-migrations
namespace: finanzas namespace: finanzas
spec: spec:
accessModes: accessModes:
@ -29,4 +45,3 @@ spec:
requests: requests:
storage: 50Mi storage: 50Mi
status: {} status: {}

+ 17
- 2
Finanzas/K8S/pv-local-finanzas.yaml View File

@ -16,7 +16,7 @@ spec:
apiVersion: v1 apiVersion: v1
kind: PersistentVolume kind: PersistentVolume
metadata: metadata:
name: finanzas-migrations-folder
name: apuntes-migrations-folder
namespace: finanzas namespace: finanzas
labels: labels:
app: finanzas app: finanzas
@ -26,7 +26,22 @@ spec:
accessModes: accessModes:
- ReadWriteOnce - ReadWriteOnce
hostPath: hostPath:
path: "/mnt/Externo/finanzas/migrations"
path: "/mnt/Externo/finanzas/migrations/apuntes"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: reymotausers-migrations-folder
namespace: finanzas
labels:
app: finanzas
spec:
capacity:
storage: 50Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/Externo/finanzas/migrations/reymotausers"
--- ---
apiVersion: v1 apiVersion: v1
kind: PersistentVolume kind: PersistentVolume


+ 1
- 1
Finanzas/K8S/verImg.sh View File

@ -1 +1 @@
docker run -it registry.reymota.es/apuntes:1.19 bash
docker run -it registry.reymota.es/finanzas-x86_64:0.2 bash

+ 1
- 1
Finanzas/README.md View File

@ -17,7 +17,7 @@ Con la shell entraPsql.sh:
\l para listar las BD \l para listar las BD
\c vehiculos para usar nuestra db
\c finanzas para usar nuestra db
\dt para ver las tablas \dt para ver las tablas
# De dónde cogí ideas # De dónde cogí ideas


+ 1
- 0
Finanzas/finanzas/.dockerignore View File

@ -0,0 +1 @@
db.sqlite3

+ 0
- 1
Finanzas/finanzas/apuntes/admin.py View File

@ -8,4 +8,3 @@ from .models import Apunte, Cuenta, Tipo
admin.site.register(Apunte) admin.site.register(Apunte)
admin.site.register(Cuenta) admin.site.register(Cuenta)
admin.site.register(Tipo) admin.site.register(Tipo)

+ 0
- 42
Finanzas/finanzas/apuntes/migrations/0001_initial.py View File

@ -1,42 +0,0 @@
# Generated by Django 4.2 on 2024-09-03 14:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Tipo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tipo', models.TextField(max_length=10)),
],
),
migrations.CreateModel(
name='Cuenta',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.TextField(max_length=20)),
('saldo_inicial', models.DecimalField(decimal_places=2, max_digits=10)),
('saldo_actual', models.DecimalField(decimal_places=2, max_digits=10)),
('tipo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='apuntes.tipo')),
],
),
migrations.CreateModel(
name='Apunte',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('fecha', models.DateField()),
('importe', models.DecimalField(decimal_places=2, max_digits=10)),
('cta_destino', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='destino', to='apuntes.cuenta')),
('cta_origen', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='origen', to='apuntes.cuenta')),
],
),
]

+ 0
- 0
Finanzas/finanzas/apuntes/migrations/__init__.py View File


+ 4
- 1
Finanzas/finanzas/apuntes/models.py View File

@ -1,11 +1,13 @@
from django.db import models from django.db import models
class Tipo(models.Model): class Tipo(models.Model):
tipo = models.TextField(max_length=10) tipo = models.TextField(max_length=10)
def __str__(self): def __str__(self):
return self.tipo return self.tipo
class Cuenta(models.Model): class Cuenta(models.Model):
nombre = models.TextField(max_length=20) nombre = models.TextField(max_length=20)
saldo_inicial = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True) saldo_inicial = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
@ -14,7 +16,8 @@ class Cuenta(models.Model):
def __str__(self): def __str__(self):
return self.nombre return self.nombre
class Apunte(models.Model): class Apunte(models.Model):
fecha = models.DateField() fecha = models.DateField()
cta_origen = models.ForeignKey(Cuenta, on_delete=models.CASCADE, related_name='origen') cta_origen = models.ForeignKey(Cuenta, on_delete=models.CASCADE, related_name='origen')


+ 1
- 1
Finanzas/finanzas/apuntes/views.py View File

@ -1,4 +1,3 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
@ -6,6 +5,7 @@ from django.shortcuts import render, get_object_or_404, redirect
from .models import Cuenta, Apunte from .models import Cuenta, Apunte
from .forms import CuentaForm, ApunteForm from .forms import CuentaForm, ApunteForm
@login_required @login_required
def principal(request): def principal(request):
cuentas = Cuenta.objects.all() cuentas = Cuenta.objects.all()


+ 9
- 6
Finanzas/finanzas/finanzas/settings.py View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
""" """
from pathlib import Path from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -58,7 +59,7 @@ ROOT_URLCONF = 'finanzas.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ BASE_DIR / 'templates' ],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -74,7 +75,6 @@ TEMPLATES = [
}, },
] ]
print("Directorio de templates: ", TEMPLATES[0]['DIRS'])
WSGI_APPLICATION = 'finanzas.wsgi.application' WSGI_APPLICATION = 'finanzas.wsgi.application'
@ -83,13 +83,16 @@ WSGI_APPLICATION = 'finanzas.wsgi.application'
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases # https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = { DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("SQL_DATABASE", BASE_DIR / "db.sqlite3"),
"USER": os.environ.get("SQL_USER", "user"),
"PASSWORD": os.environ.get("SQL_PASSWORD", "password"),
"HOST": os.environ.get("SQL_HOST", "localhost"),
"PORT": os.environ.get("SQL_PORT", "5432"),
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators


+ 1
- 2
Finanzas/finanzas/finanzas/urls.py View File

@ -22,7 +22,7 @@ from django.views.generic.base import TemplateView # new
urlpatterns = [ urlpatterns = [
path('obreros/', admin.site.urls), path('obreros/', admin.site.urls),
path('apuntes/', include('apuntes.urls')), path('apuntes/', include('apuntes.urls')),
path("accounts/", include("accounts.urls")), # new path("accounts/", include("accounts.urls")), # new
@ -32,4 +32,3 @@ urlpatterns = [
path("", TemplateView.as_view(template_name="apuntes/index.html"), path("", TemplateView.as_view(template_name="apuntes/index.html"),
name="principal"), # new name="principal"), # new
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

+ 1
- 0
Finanzas/finanzas/reymotausers/admin.py View File

@ -7,6 +7,7 @@ from django.contrib.auth.admin import UserAdmin
from reymotausers.models import ReyMotaUser from reymotausers.models import ReyMotaUser
from reymotausers.forms import ReyMotaUserCreationForm, ReyMotaUserChangeForm from reymotausers.forms import ReyMotaUserCreationForm, ReyMotaUserChangeForm
class ReyMotaUserAdmin(UserAdmin): class ReyMotaUserAdmin(UserAdmin):
add_form = ReyMotaUserCreationForm add_form = ReyMotaUserCreationForm
form = ReyMotaUserChangeForm form = ReyMotaUserChangeForm


+ 1
- 0
Finanzas/finanzas/reymotausers/forms.py View File

@ -3,6 +3,7 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import ReyMotaUser from .models import ReyMotaUser
class ReyMotaUserCreationForm(UserCreationForm): class ReyMotaUserCreationForm(UserCreationForm):
class Meta: class Meta:


+ 0
- 34
Finanzas/finanzas/reymotausers/migrations/0001_initial.py View File

@ -1,34 +0,0 @@
# Generated by Django 4.2 on 2024-09-03 14:49
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='ReyMotaUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
('foto', models.ImageField(blank=True, default='profile_images/default.jpg', upload_to='profile_images')),
('is_staff', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('nombre', models.CharField(blank=True, max_length=200, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'abstract': False,
},
),
]

+ 0
- 0
Finanzas/finanzas/reymotausers/migrations/__init__.py View File


+ 1
- 1
Finanzas/finanzas/reymotausers/models.py View File

@ -7,6 +7,7 @@ from .managers import ReyMotaUserManager
# Create your models here. # Create your models here.
class ReyMotaUser(AbstractBaseUser, PermissionsMixin): class ReyMotaUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(_("email address"), unique=True) email = models.EmailField(_("email address"), unique=True)
foto = models.ImageField(upload_to="profile_images", default="profile_images/default.jpg", blank=True) foto = models.ImageField(upload_to="profile_images", default="profile_images/default.jpg", blank=True)
@ -21,4 +22,3 @@ class ReyMotaUser(AbstractBaseUser, PermissionsMixin):
def __str__(self): def __str__(self):
return self.email return self.email

+ 2
- 2
Finanzas/nginx/Makefile View File

@ -2,7 +2,7 @@ install:
echo "Creando imagen con version '${IMG_NGINX_VERSION}' para la arquitectura '${ARQUITECTURA}' en el registry '${REGISTRY}'" echo "Creando imagen con version '${IMG_NGINX_VERSION}' para la arquitectura '${ARQUITECTURA}' en el registry '${REGISTRY}'"
docker build --no-cache -t ${REGISTRY}/nginx-vehiculos-${ARQUITECTURA}:${IMG_NGINX_VERSION} .
docker push ${REGISTRY}/nginx-vehiculos-${ARQUITECTURA}:${IMG_NGINX_VERSION}
docker build --no-cache -t ${REGISTRY}/nginx-finanzas-${ARQUITECTURA}:${IMG_NGINX_VERSION} .
docker push ${REGISTRY}/nginx-finanzas-${ARQUITECTURA}:${IMG_NGINX_VERSION}

+ 5
- 5
Finanzas/nginx/nginx.conf View File

@ -1,5 +1,5 @@
upstream vehiculos {
server vehiculos:8000;
upstream finanzas {
server finanzas:8000;
} }
server { server {
@ -7,7 +7,7 @@ server {
listen 80; listen 80;
location / { location / {
proxy_pass http://vehiculos;
proxy_pass http://finanzas;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_redirect off; proxy_redirect off;
@ -15,11 +15,11 @@ server {
} }
location /static/ { location /static/ {
alias /app/vehiculos/staticfiles/;
alias /app/finanzas/staticfiles/;
} }
location /media/ { location /media/ {
alias /app/vehiculos/mediafiles/;
alias /app/finanzas/mediafiles/;
} }
} }

Loading…
Cancel
Save