Browse Source

Listo para producción

Celestino Rey 1 year ago
parent
commit
a83418ea25
7 changed files with 62 additions and 56 deletions
  1. 25 20
      Dockerfile.oc
  2. 1 1
      K8S/Makefile.OC
  3. 1 1
      K8S/env-prod-configmap.yaml
  4. 2 13
      K8S/jugaralpadel-deployment.yaml
  5. 0 20
      entrypoint.sh
  6. 32 0
      nginx/default.conf
  7. 1 1
      src/config/entrypoint.sh

+ 25 - 20
Dockerfile.oc

@@ -1,32 +1,37 @@
-FROM python:3.11
-
-ENV APP_HOME=/app
-RUN mkdir -p $APP_HOME
-
-WORKDIR $APP_HOME
+FROM python:3.11-slim
 
 # install system dependencies
-RUN apt-get update && apt-get install -y nginx sqlite3 netcat-traditional vim curl jq 
+RUN apt-get update && apt-get install nginx netcat-openbsd curl vim jq rsync libpango-1.0-0 libpangocairo-1.0-0 libcairo2 -y
 
-COPY ./src/requirements.txt .
+# copy our nginx configuration to overwrite nginx defaults
+RUN rm /etc/nginx/sites-enabled/default
+RUN rm /etc/nginx/sites-available/default
+COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
 
-RUN pip install --upgrade pip
-RUN pip install --no-cache-dir --no-deps -r requirements.txt
+# link nginx logs to container stdout
+RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
 
-# copia fichero de configuración de nginx
+# copy the django code
+COPY ./src ./app
 
-COPY ./nginx/nginx.conf /etc/nginx/
+# change our working directory to the django projcet roo
+WORKDIR /app
 
-# enlace los logs de nginx a stdout
-RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
+# create virtual env (notice the location?)
+# update pip
+# install requirements
+RUN python -m venv /opt/venv && \
+    /opt/venv/bin/python -m pip install pip --upgrade && \
+    /opt/venv/bin/python -m pip install -r requirements.txt
 
-COPY ./entrypoint.sh .
+# Añade path a .bashrc
 
-COPY . $APP_HOME
+RUN echo "export PATH=/opt/venv/bin/:$PATH" >> /root/.bashrc
 
-RUN chmod +x /app/entrypoint.sh
+# make our entrypoint.sh executable
+RUN chmod +x config/entrypoint.sh
 
-WORKDIR $APP_HOME/src
+#EXPOSE 8080
 
-# run entrypoint.sh
-ENTRYPOINT  ["/app/entrypoint.sh"]
+# execute our entrypoint.sh file
+CMD ["./config/entrypoint.sh"]

+ 1 - 1
K8S/Makefile.OC

@@ -1,7 +1,7 @@
 export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
 export REGISTRY=registry.reymota.es
 
-export IMG_VERSION = 0.90.23
+export IMG_VERSION = 0.90.26
 
 # limpia todo
 all: ayuda

+ 1 - 1
K8S/env-prod-configmap.yaml

@@ -1,7 +1,7 @@
 apiVersion: v1
 data:
   DEBUG: "False"
-  APP_VERSION: 16.0.3
+  APP_VERSION: 16.0.6
   SQL_DATABASE: reymota
   SQL_ENGINE: django.db.backends.postgresql
   SQL_HOST: postgresql

+ 2 - 13
K8S/jugaralpadel-deployment.yaml

@@ -1,25 +1,14 @@
 apiVersion: v1
 kind: Service
-metadata:
-  name: nginx
-  namespace: jugaralpadel
-spec:
-  ports:
-    - name: "1337"
-      port: 1337
-      targetPort: 80
-  selector:
-    app: jugaralpadel
----
-apiVersion: v1
-kind: Service
 metadata:
   name: jugaralpadel
   namespace: jugaralpadel
 spec:
+  type: NodePort
   ports:
     - name: "8000"
       port: 8000
+      nodePort: 30342
       targetPort: 8000
   selector:
     app: jugaralpadel

+ 0 - 20
entrypoint.sh

@@ -1,20 +0,0 @@
-#!/bin/bash
-
-if [ "$DATABASE" = "postgres" ]
-then
-    echo "Waiting for postgres..."
-
-    while ! nc -z $SQL_HOST $SQL_PORT; do
-      sleep 0.1
-    done
-
-    echo "PostgreSQL started"
-else
-    echo "la base de datos no es postgres: '$DATABASE'"
-fi
-
-python manage.py collectstatic --noinput
-
-nginx -g 'daemon off;' &
-
-python manage.py runserver 0.0.0.0:8000 --noreload

+ 32 - 0
nginx/default.conf

@@ -0,0 +1,32 @@
+upstream django_project {
+    server localhost:8000;
+}
+
+error_log /var/log/nginx/error.log;
+
+server {
+    listen       8080;
+
+    access_log /var/log/nginx/access.log;
+
+    location / {
+        proxy_pass http://django_project;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header Host $host;
+        proxy_redirect off;
+        client_max_body_size 100M;
+    }
+
+    location /static/ {
+        alias /app/staticfiles/;
+    }
+
+    location /media/ {
+        alias /app/mediafiles/;
+    }
+
+    error_page   500 502 503 504  /50x.html;
+    location = /50x.html {
+        root   /usr/share/nginx/html;
+    }
+}

+ 1 - 1
src/config/entrypoint.sh

@@ -16,7 +16,7 @@ then
 	/opt/venv/bin/python manage.py migrate --no-input
 	/opt/venv/bin/python manage.py collectstatic --no-input
 
-	/opt/venv/bin/gunicorn misfinanzas.wsgi:application --bind "0.0.0.0:${RUN_PORT}" --daemon
+	/opt/venv/bin/gunicorn gestion_reservas.wsgi:application --bind "0.0.0.0:${RUN_PORT}" --daemon
 
 	nginx -g 'daemon off;'
 else