diff --git a/README.md b/README.md index 71ae051..9488fdb 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,14 @@ # Versión para openshift -## permitir a nginx correr con privilegios - -### esto se hace una vez dentro del proyecto. - -oc adm policy add-scc-to-user -z default anyuid - ## Instalación Crear un proyecto y luego añadir una app desde Agregar, importar desde git. -Tal y como está la estructura de directorios, deberia detectar automáticamente una compilación Python + oc new-app http://gitea.reymota.es/creylopez/ReyMotaAppsOC.git -e DEBUG="False" -e VERSION=11.0 --name='reymota' +Tal y como está la estructura de directorios, deberia detectar automáticamente una compilación Python -Desde la línea de comandos, sería: -oc new-app http://gitea.reymota.es/creylopez/ReyMotaAppsOC.git -e DEBUG=True @@ -65,29 +58,3 @@ ALTER SEQUENCE tablename_id_seq RESTART WITH nn; esto se hace cuando restauro un volcado de la bd sobre una instalación nueva. Si hay índices ya creados, hay que reinciar a partir del último. - -## Copiar ficheros al contenedor - -Copy local directory to a pod directory -oc rsync /home/user/source devpod1234:/src - -# Copy pod directory to a local directory -oc rsync devpod1234:/src /home/user/source - -## Para que git no pida credenciales - -git config --global credential.helper store - - -la siguiente vez que se haga el push nos la pedirá una última vez - -## Persistent Volume Claims y sus rutas de montaje - - - mountPath: /app/lyrics/migrations - name: reymota-lyrics-migrations - - mountPath: /app/repostajes/migrations - name: reymota-repostajes-migrations - - mountPath: /app/reymotausers/migrations - name: reymota-reymotausers-migrations - - mountPath: /app/staticfiles - name: static-volume \ No newline at end of file diff --git a/Yamls/env-prod-db-configmap.yaml b/Yamls/env-prod-db-configmap.yaml new file mode 100644 index 0000000..d871dce --- /dev/null +++ b/Yamls/env-prod-db-configmap.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + POSTGRES_DB: reymota + POSTGRES_PASSWORD: Dsa-0213 + POSTGRES_USER: creylopez +kind: ConfigMap +metadata: + labels: + io.kompose.service: db-env-prod-db + name: env-prod-db + namespace: reymota diff --git a/postgres-deployment.yaml b/Yamls/postgresql-deployment.yaml similarity index 88% rename from postgres-deployment.yaml rename to Yamls/postgresql-deployment.yaml index d09457e..86f8c0a 100644 --- a/postgres-deployment.yaml +++ b/Yamls/postgresql-deployment.yaml @@ -5,14 +5,14 @@ metadata: kompose.cmd: kompose convert kompose.version: 1.34.0 (cbf2835db) labels: - io.kompose.service: db - name: db + io.kompose.service: postgresql + name: postgresql namespace: reymota spec: replicas: 1 selector: matchLabels: - io.kompose.service: db + io.kompose.service: postgresql strategy: type: Recreate template: @@ -21,7 +21,7 @@ spec: kompose.cmd: kompose convert kompose.version: 1.34.0 (cbf2835db) labels: - io.kompose.service: db + io.kompose.service: postgresql spec: containers: - env: @@ -41,7 +41,7 @@ spec: key: POSTGRES_USER name: env-prod-db image: postgres:15 - name: db + name: postgresql volumeMounts: - mountPath: /var/lib/postgresql/data name: postgresql diff --git a/Yamls/postgresql-service.yaml b/Yamls/postgresql-service.yaml new file mode 100644 index 0000000..f7fc05d --- /dev/null +++ b/Yamls/postgresql-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + kompose.cmd: kompose convert + kompose.version: 1.34.0 (cbf2835db) + labels: + io.kompose.service: postgresql + name: postgresql + namespace: reymota +spec: + ports: + - name: "5432" + port: 5432 + targetPort: 5432 + selector: + io.kompose.service: postgresql diff --git a/Yamls/pvc-postgresql.yaml b/Yamls/pvc-postgresql.yaml new file mode 100644 index 0000000..534b19d --- /dev/null +++ b/Yamls/pvc-postgresql.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + finalizers: + - kubernetes.io/pvc-protection + labels: + template: postgresql-persistent-template + name: postgresql + namespace: reymota +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: lvms-vg1 + volumeMode: Filesystem diff --git a/pvc.yaml b/Yamls/pvc.yaml similarity index 100% rename from pvc.yaml rename to Yamls/pvc.yaml diff --git a/Yamls/reymota-development.yaml b/Yamls/reymota-development.yaml new file mode 100644 index 0000000..2bde992 --- /dev/null +++ b/Yamls/reymota-development.yaml @@ -0,0 +1,27 @@ + volumeMounts: + - mountPath: /app/lyrics/migrations + name: reymota-lyrics-migrations + - mountPath: /app/mediafiles + name: reymota-media + - mountPath: /app/repostajes/migrations + name: reymota-repostajes-migrations + - mountPath: /app/reymotausers/migrations + name: reymota-reymotausers-migrations + - mountPath: /app/staticfiles + name: static-volume + volumes: + - name: reymota-lyrics-migrations + persistentVolumeClaim: + claimName: reymota-lyrics-migrations + - name: reymota-media + persistentVolumeClaim: + claimName: reymota-media + - name: reymota-repostajes-migrations + persistentVolumeClaim: + claimName: reymota-repostajes-migrations + - name: reymota-reymotausers-migrations + persistentVolumeClaim: + claimName: reymota-reymotausers-migrations + - name: static-volume + persistentVolumeClaim: + claimName: static-volume diff --git a/src/repostajes/management/commands/importar_repostajes.py b/src/repostajes/management/commands/importar_repostajes.py index e3bccd1..ea690d8 100644 --- a/src/repostajes/management/commands/importar_repostajes.py +++ b/src/repostajes/management/commands/importar_repostajes.py @@ -26,10 +26,10 @@ class Command(BaseCommand): repostajes_creados = 0 for repostaje_data in datos: try: - vehiculo = Vehiculo.objects.get(id=repostaje_data["vehiculo"]) + vehiculo = Vehiculo.objects.get(matricula=repostaje_data["vehiculo_matricula"]) creado = Repostaje.objects.create( - vehiculo_id=vehiculo.id, + vehiculo=vehiculo, fecha=repostaje_data['fecha'], kms=repostaje_data['kms'], litros=repostaje_data['litros'], @@ -43,7 +43,7 @@ class Command(BaseCommand): repostajes_creados += 1 except Vehiculo.DoesNotExist: - self.stderr.write(self.style.ERROR(f"Vehiculo '{repostaje_data['vehiculo']}' no encontrado.")) + self.stderr.write(self.style.ERROR(f"Vehiculo con matrícula '{repostaje_data['vehiculo_matricula']}' no encontrado.")) self.stdout.write(self.style.SUCCESS(f'Se importaron {repostajes_creados} repostajes correctamente.')) diff --git a/src/repostajes/management/commands/importar_vehiculos.py b/src/repostajes/management/commands/importar_vehiculos.py index 861cf2c..e3ae66b 100644 --- a/src/repostajes/management/commands/importar_vehiculos.py +++ b/src/repostajes/management/commands/importar_vehiculos.py @@ -26,7 +26,6 @@ class Command(BaseCommand): vehiculos_creados = 0 for vehiculo_data in datos: creado = Vehiculo.objects.create( - id=vehiculo_data['id'], marca=vehiculo_data['marca'], modelo=vehiculo_data['modelo'], matricula=vehiculo_data['matricula'], diff --git a/src/repostajes/serializers.py b/src/repostajes/serializers.py index 82cc100..194c512 100644 --- a/src/repostajes/serializers.py +++ b/src/repostajes/serializers.py @@ -9,6 +9,7 @@ class VehiculoSerializer(serializers.ModelSerializer): class RepostajeSerializer(serializers.ModelSerializer): + vehiculo_matricula = serializers.CharField(source='vehiculo.matricula', read_only=True) class Meta: model = Repostaje - fields = '__all__' # Incluir todos los campos del modelo + fields = [ 'id', 'fecha', 'kms', 'litros', 'descuento', 'importe', 'precioxlitro', 'kmsrecorridos', 'consumo', 'vehiculo', 'vehiculo_matricula']