diff --git a/Dockerfile b/Dockerfile index 69317b0..abcc4fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,33 @@ -FROM python:3.11.4-slim-buster +# yup, python 3.11! +FROM python:3.11-slim -# Añadir usuario y un grupo USER 0 - -RUN addgroup --system app && adduser --system --group app - -# Add application sources with correct permissions for OpenShift -ENV APP_HOME=/app -RUN mkdir -p $APP_HOME/datos -ADD . $APP_HOME - - -# Install the dependencies -RUN apt-get update && apt-get install -y sqlite3 - -RUN pip install -U "pip>=19.3.1" && \ - pip install -r $APP_HOME/requirements.txt && \ -# python manage.py collectstatic --noinput && \ - python $APP_HOME/manage.py migrate - -WORKDIR $APP_HOME -RUN chown -R app:0 ./ -USER app - -EXPOSE 8080 -# Run the application -CMD python manage.py runserver 0.0.0.0:8080 +# install nginx +RUN apt-get update && apt-get install nginx -y +# copy our nginx configuration to overwrite nginx defaults +COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf +# 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 + +# copy the django code +COPY ./src ./app + +RUN chgrp -R 0 ./app && chmod -R g=u ./app +RUN chgrp -R 0 /var/lib/nginx && chmod -R g=u /var/lib/nginx + +# change our working directory to the django projcet roo +WORKDIR /app + +# 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 + +# make our entrypoint.sh executable +RUN chmod +x config/entrypoint.sh +RUN chmod u+s /usr/sbin/nginx + +# execute our entrypoint.sh file +CMD ["./config/entrypoint.sh"] diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..fe37be0 --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,24 @@ + upstream django_project { + server localhost:8000; +} + +error_log /var/log/nginx/error.log; + +server { + listen 80; + server_name reymota.lag *.reymota.lab; + root /www/data/; + 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; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/openshift/scripts/run-in-container.sh b/openshift/scripts/run-in-container.sh deleted file mode 100755 index 7219bfe..0000000 --- a/openshift/scripts/run-in-container.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# Use this script to run one-off commands inside a container of a pod where your -# Python application code lives in. - -# You can accomplish the same results by using regular commands from OpenShift. -# This script is just wrapping calls to `oc` to make it a little more -# convenient to use. In the future, the `oc` cli tool might incorporate changes -# that make this script obsolete. - -# Related GitHub issues: -# - https://github.com/GoogleCloudPlatform/kubernetes/issues/8876 -# - https://github.com/openshift/origin/issues/2001 - - -# Usage examples: -# -# ./run-in-container.sh ./manage.py migrate -# ./run-in-container.sh ./manage.py createsuperuser -# ./run-in-container.sh ./manage.py shell -# -# If your Python pods are labeled with a name other than "django", you can use: -# -# POD_NAME=name ./run-in-container.sh ./manage.py check -# -# If there is more than one replica, you can also specify a POD by index: -# -# POD_INDEX=1 ./run-in-container.sh ./manage.py shell -# -# Or both together: -# -# POD_NAME=frontend POD_INDEX=2 ./run-in-container.sh ./manage.py shell - - -# Get name of a currently deployed pod by label and index -POD_INSTANCE_NAME=`oc get pods \ - -l "name=${POD_NAME:-django-frontend}" \ - -t "{{ with index .items ${POD_INDEX:-0} }}{{ .metadata.name }}{{ end }}"` - -# Run command in a container of the specified pod: -oc exec -p "$POD_INSTANCE_NAME" -it -- bash -c "${@:-echo}" diff --git a/openshift/templates/django-postgresql-persistent.json b/openshift/templates/django-postgresql-persistent.json deleted file mode 100644 index 9b0e257..0000000 --- a/openshift/templates/django-postgresql-persistent.json +++ /dev/null @@ -1,524 +0,0 @@ -{ - "kind": "Template", - "apiVersion": "template.openshift.io/v1", - "metadata": { - "name": "django-psql-persistent", - "annotations": { - "openshift.io/display-name": "Django + PostgreSQL", - "description": "An example Django application with a PostgreSQL database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/django-ex/blob/master/README.md.", - "tags": "quickstart,python,django", - "iconClass": "icon-python", - "openshift.io/long-description": "This template defines resources needed to develop a Django based application, including a build configuration, application deployment configuration, and database deployment configuration.", - "openshift.io/provider-display-name": "Red Hat, Inc.", - "openshift.io/documentation-url": "https://github.com/sclorg/django-ex", - "openshift.io/support-url": "https://access.redhat.com", - "template.openshift.io/bindable": "false" - } - }, - "message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/django-ex/blob/master/README.md.", - "labels": { - "template": "django-psql-persistent", - "app": "django-psql-persistent" - }, - "objects": [ - { - "kind": "Secret", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}" - }, - "stringData" : { - "database-user" : "${DATABASE_USER}", - "database-password" : "${DATABASE_PASSWORD}", - "django-secret-key" : "${DJANGO_SECRET_KEY}" - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Exposes and load balances the application pods", - "service.alpha.openshift.io/dependencies": "[{\"name\": \"${DATABASE_SERVICE_NAME}\", \"kind\": \"Service\"}]" - } - }, - "spec": { - "ports": [ - { - "name": "web", - "port": 8080, - "targetPort": 8080 - } - ], - "selector": { - "name": "${NAME}" - } - } - }, - { - "kind": "Route", - "apiVersion": "route.openshift.io/v1", - "metadata": { - "name": "${NAME}" - }, - "spec": { - "host": "${APPLICATION_DOMAIN}", - "to": { - "kind": "Service", - "name": "${NAME}" - } - } - }, - { - "kind": "ImageStream", - "apiVersion": "image.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Keeps track of changes in the application image" - } - } - }, - { - "kind": "BuildConfig", - "apiVersion": "build.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to build the application", - "template.alpha.openshift.io/wait-for-ready": "true" - } - }, - "spec": { - "source": { - "type": "Git", - "git": { - "uri": "${SOURCE_REPOSITORY_URL}", - "ref": "${SOURCE_REPOSITORY_REF}" - }, - "contextDir": "${CONTEXT_DIR}" - }, - "strategy": { - "type": "Source", - "sourceStrategy": { - "from": { - "kind": "ImageStreamTag", - "namespace": "${NAMESPACE}", - "name": "python:${PYTHON_VERSION}" - }, - "env": [ - { - "name": "PIP_INDEX_URL", - "value": "${PIP_INDEX_URL}" - } - ] - } - }, - "output": { - "to": { - "kind": "ImageStreamTag", - "name": "${NAME}:latest" - } - }, - "triggers": [ - { - "type": "ImageChange" - }, - { - "type": "ConfigChange" - }, - { - "type": "GitHub", - "github": { - "secret": "${GITHUB_WEBHOOK_SECRET}" - } - } - ], - "postCommit": { - "script": "./manage.py test" - } - } - }, - { - "kind": "Deployment", - "apiVersion": "apps/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to deploy the application server", - "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" - } - }, - "spec": { - "strategy": { - "type": "Recreate" - }, - "replicas": 1, - "selector": { - "matchLabels":{ - "name": "${NAME}" - } - }, - "template": { - "metadata": { - "name": "${NAME}", - "labels": { - "name": "${NAME}" - } - }, - "spec": { - "containers": [ - { - "name": "django-psql-persistent", - "image": " ", - "ports": [ - { - "containerPort": 8080 - } - ], - "readinessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 3, - "httpGet": { - "path": "/health", - "port": 8080 - } - }, - "livenessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 30, - "httpGet": { - "path": "/health", - "port": 8080 - } - }, - "env": [ - { - "name": "DATABASE_SERVICE_NAME", - "value": "${DATABASE_SERVICE_NAME}" - }, - { - "name": "DATABASE_ENGINE", - "value": "${DATABASE_ENGINE}" - }, - { - "name": "DATABASE_NAME", - "value": "${DATABASE_NAME}" - }, - { - "name": "DATABASE_USER", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-user" - } - } - }, - { - "name": "DATABASE_PASSWORD", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-password" - } - } - }, - { - "name": "APP_CONFIG", - "value": "${APP_CONFIG}" - }, - { - "name": "DJANGO_SECRET_KEY", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "django-secret-key" - } - } - } - ], - "resources": { - "limits": { - "memory": "${MEMORY_LIMIT}" - } - } - } - ] - } - } - } - }, - { - "kind": "PersistentVolumeClaim", - "apiVersion": "v1", - "metadata": { - "name": "${DATABASE_SERVICE_NAME}" - }, - "spec": { - "accessModes": [ - "ReadWriteOnce" - ], - "resources": { - "requests": { - "storage": "${VOLUME_CAPACITY}" - } - } - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "annotations": { - "description": "Exposes the database server" - } - }, - "spec": { - "ports": [ - { - "name": "postgresql", - "port": 5432, - "targetPort": 5432 - } - ], - "selector": { - "name": "${DATABASE_SERVICE_NAME}" - } - } - }, - { - "kind": "Deployment", - "apiVersion": "apps/v1", - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "annotations": { - "description": "Defines how to deploy the database", - "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" - } - }, - "spec": { - "strategy": { - "type": "Recreate" - }, - "replicas": 1, - "selector": { - "matchLabels":{ - "name": "${DATABASE_SERVICE_NAME}" - } - }, - "template": { - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "labels": { - "name": "${DATABASE_SERVICE_NAME}" - } - }, - "spec": { - "volumes": [ - { - "name": "${DATABASE_SERVICE_NAME}-data", - "persistentVolumeClaim": { - "claimName": "${DATABASE_SERVICE_NAME}" - } - } - ], - "containers": [ - { - "name": "postgresql", - "image": " ", - "ports": [ - { - "containerPort": 5432 - } - ], - "env": [ - { - "name": "POSTGRESQL_USER", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-user" - } - } - }, - { - "name": "POSTGRESQL_PASSWORD", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-password" - } - } - }, - { - "name": "POSTGRESQL_DATABASE", - "value": "${DATABASE_NAME}" - } - ], - "volumeMounts": [ - { - "name": "${DATABASE_SERVICE_NAME}-data", - "mountPath": "/var/lib/pgsql/data" - } - ], - "readinessProbe": { - "timeoutSeconds": 1, - "initialDelaySeconds": 5, - "exec": { - "command": [ "/usr/libexec/check-container" ] - } - }, - "livenessProbe": { - "timeoutSeconds": 10, - "initialDelaySeconds": 120, - "exec": { - "command": [ "/usr/libexec/check-container", "--live" ] - } - }, - "resources": { - "limits": { - "memory": "${MEMORY_POSTGRESQL_LIMIT}" - } - } - } - ] - } - } - } - } - ], - "parameters": [ - { - "name": "NAME", - "displayName": "Name", - "description": "The name assigned to all of the frontend objects defined in this template.", - "required": true, - "value": "django-psql-persistent" - }, - { - "name": "NAMESPACE", - "displayName": "Namespace", - "required": true, - "description": "The OpenShift Namespace where the ImageStream resides.", - "value": "openshift" - }, - { - "name": "PYTHON_VERSION", - "displayName": "Version of Python Image", - "description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi7, 3.8-ubi8, or latest).", - "value": "3.8-ubi8", - "required": true - }, - { - "name": "POSTGRESQL_VERSION", - "displayName": "Version of PostgreSQL Image", - "description": "Version of PostgreSQL image to be used (10-el8, 12-el8, or latest).", - "value": "12-el8", - "required": true - }, - { - "name": "MEMORY_LIMIT", - "displayName": "Memory Limit", - "required": true, - "description": "Maximum amount of memory the Django container can use.", - "value": "512Mi" - }, - { - "name": "MEMORY_POSTGRESQL_LIMIT", - "displayName": "Memory Limit (PostgreSQL)", - "required": true, - "description": "Maximum amount of memory the PostgreSQL container can use.", - "value": "512Mi" - }, - { - "name": "VOLUME_CAPACITY", - "displayName": "Volume Capacity", - "description": "Volume space available for data, e.g. 512Mi, 2Gi", - "value": "1Gi", - "required": true - }, - { - "name": "SOURCE_REPOSITORY_URL", - "displayName": "Git Repository URL", - "required": true, - "description": "The URL of the repository with your application source code.", - "value": "https://github.com/sclorg/django-ex.git" - }, - { - "name": "SOURCE_REPOSITORY_REF", - "displayName": "Git Reference", - "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." - }, - { - "name": "CONTEXT_DIR", - "displayName": "Context Directory", - "description": "Set this to the relative path to your project if it is not in the root of your repository." - }, - { - "name": "APPLICATION_DOMAIN", - "displayName": "Application Hostname", - "description": "The exposed hostname that will route to the Django service, if left blank a value will be defaulted.", - "value": "" - }, - { - "name": "GITHUB_WEBHOOK_SECRET", - "displayName": "GitHub Webhook Secret", - "description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", - "generate": "expression", - "from": "[a-zA-Z0-9]{40}" - }, - { - "name": "DATABASE_SERVICE_NAME", - "displayName": "Database Service Name", - "required": true, - "value": "postgresql" - }, - { - "name": "DATABASE_ENGINE", - "displayName": "Database Engine", - "required": true, - "description": "Database engine: postgresql, mysql or sqlite (default).", - "value": "postgresql" - }, - { - "name": "DATABASE_NAME", - "displayName": "Database Name", - "required": true, - "value": "default" - }, - { - "name": "DATABASE_USER", - "displayName": "Database Username", - "required": true, - "value": "django" - }, - { - "name": "DATABASE_PASSWORD", - "displayName": "Database User Password", - "generate": "expression", - "from": "[a-zA-Z0-9]{16}" - }, - { - "name": "APP_CONFIG", - "displayName": "Application Configuration File Path", - "description": "Relative path to Gunicorn configuration file (optional)." - }, - { - "name": "DJANGO_SECRET_KEY", - "displayName": "Django Secret Key", - "description": "Set this to a long random string.", - "generate": "expression", - "from": "[\\w]{50}" - }, - { - "name": "PIP_INDEX_URL", - "displayName": "Custom PyPi Index URL", - "description": "The custom PyPi index URL", - "value": "" - } - ] -} diff --git a/openshift/templates/django-postgresql.json b/openshift/templates/django-postgresql.json deleted file mode 100644 index 4ad7bb2..0000000 --- a/openshift/templates/django-postgresql.json +++ /dev/null @@ -1,498 +0,0 @@ -{ - "kind": "Template", - "apiVersion": "template.openshift.io/v1", - "metadata": { - "name": "django-psql-example", - "annotations": { - "openshift.io/display-name": "Django + PostgreSQL (Ephemeral)", - "description": "An example Django application with a PostgreSQL database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/django-ex/blob/master/README.md.\n\nWARNING: Any data stored will be lost upon pod destruction. Only use this template for testing.", - "tags": "quickstart,python,django", - "iconClass": "icon-python", - "openshift.io/long-description": "This template defines resources needed to develop a Django based application, including a build configuration, application deployment configuration, and database deployment configuration. The database is stored in non-persistent storage, so this configuration should be used for experimental purposes only.", - "openshift.io/provider-display-name": "Red Hat, Inc.", - "openshift.io/documentation-url": "https://github.com/sclorg/django-ex", - "openshift.io/support-url": "https://access.redhat.com", - "template.openshift.io/bindable": "false" - } - }, - "message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/django-ex/blob/master/README.md.", - "labels": { - "template": "django-psql-example", - "app": "django-psql-example" - }, - "objects": [ - { - "kind": "Secret", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}" - }, - "stringData" : { - "database-user" : "${DATABASE_USER}", - "database-password" : "${DATABASE_PASSWORD}", - "django-secret-key" : "${DJANGO_SECRET_KEY}" - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Exposes and load balances the application pods", - "service.alpha.openshift.io/dependencies": "[{\"name\": \"${DATABASE_SERVICE_NAME}\", \"kind\": \"Service\"}]" - } - }, - "spec": { - "ports": [ - { - "name": "web", - "port": 8080, - "targetPort": 8080 - } - ], - "selector": { - "name": "${NAME}" - } - } - }, - { - "kind": "Route", - "apiVersion": "route.openshift.io/v1", - "metadata": { - "name": "${NAME}" - }, - "spec": { - "host": "${APPLICATION_DOMAIN}", - "to": { - "kind": "Service", - "name": "${NAME}" - } - } - }, - { - "kind": "ImageStream", - "apiVersion": "image.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Keeps track of changes in the application image" - } - } - }, - { - "kind": "BuildConfig", - "apiVersion": "build.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to build the application", - "template.alpha.openshift.io/wait-for-ready": "true" - } - }, - "spec": { - "source": { - "type": "Git", - "git": { - "uri": "${SOURCE_REPOSITORY_URL}", - "ref": "${SOURCE_REPOSITORY_REF}" - }, - "contextDir": "${CONTEXT_DIR}" - }, - "strategy": { - "type": "Source", - "sourceStrategy": { - "from": { - "kind": "ImageStreamTag", - "namespace": "${NAMESPACE}", - "name": "python:${PYTHON_VERSION}" - }, - "env": [ - { - "name": "PIP_INDEX_URL", - "value": "${PIP_INDEX_URL}" - } - ] - } - }, - "output": { - "to": { - "kind": "ImageStreamTag", - "name": "${NAME}:latest" - } - }, - "triggers": [ - { - "type": "ImageChange" - }, - { - "type": "ConfigChange" - }, - { - "type": "GitHub", - "github": { - "secret": "${GITHUB_WEBHOOK_SECRET}" - } - } - ], - "postCommit": { - "script": "./manage.py test" - } - } - }, - { - "kind": "Deployment", - "apiVersion": "apps/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to deploy the application server", - "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" - } - }, - "spec": { - "strategy": { - "type": "Recreate" - }, - "replicas": 1, - "selector": { - "matchLabels":{ - "name": "${NAME}" - } - }, - "template": { - "metadata": { - "name": "${NAME}", - "labels": { - "name": "${NAME}" - } - }, - "spec": { - "containers": [ - { - "name": "django-psql-example", - "image": " ", - "ports": [ - { - "containerPort": 8080 - } - ], - "readinessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 3, - "httpGet": { - "path": "/health", - "port": 8080 - } - }, - "livenessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 30, - "httpGet": { - "path": "/health", - "port": 8080 - } - }, - "env": [ - { - "name": "DATABASE_SERVICE_NAME", - "value": "${DATABASE_SERVICE_NAME}" - }, - { - "name": "DATABASE_ENGINE", - "value": "${DATABASE_ENGINE}" - }, - { - "name": "DATABASE_NAME", - "value": "${DATABASE_NAME}" - }, - { - "name": "DATABASE_USER", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-user" - } - } - }, - { - "name": "DATABASE_PASSWORD", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-password" - } - } - }, - { - "name": "APP_CONFIG", - "value": "${APP_CONFIG}" - }, - { - "name": "DJANGO_SECRET_KEY", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "django-secret-key" - } - } - } - ], - "resources": { - "limits": { - "memory": "${MEMORY_LIMIT}" - } - } - } - ] - } - } - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "annotations": { - "description": "Exposes the database server" - } - }, - "spec": { - "ports": [ - { - "name": "postgresql", - "port": 5432, - "targetPort": 5432 - } - ], - "selector": { - "name": "${DATABASE_SERVICE_NAME}" - } - } - }, - { - "kind": "Deployment", - "apiVersion": "apps/v1", - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "annotations": { - "description": "Defines how to deploy the database", - "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" - } - }, - "spec": { - "strategy": { - "type": "Recreate" - }, - "replicas": 1, - "selector": { - "matchLabels":{ - "name": "${DATABASE_SERVICE_NAME}" - } - }, - "template": { - "metadata": { - "name": "${DATABASE_SERVICE_NAME}", - "labels": { - "name": "${DATABASE_SERVICE_NAME}" - } - }, - "spec": { - "volumes": [ - { - "name": "data", - "emptyDir": {} - } - ], - "containers": [ - { - "name": "postgresql", - "image": " ", - "ports": [ - { - "containerPort": 5432 - } - ], - "env": [ - { - "name": "POSTGRESQL_USER", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-user" - } - } - }, - { - "name": "POSTGRESQL_PASSWORD", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "database-password" - } - } - }, - { - "name": "POSTGRESQL_DATABASE", - "value": "${DATABASE_NAME}" - } - ], - "volumeMounts": [ - { - "name": "data", - "mountPath": "/var/lib/pgsql/data" - } - ], - "readinessProbe": { - "timeoutSeconds": 1, - "initialDelaySeconds": 5, - "exec": { - "command": [ "/usr/libexec/check-container" ] - } - }, - "livenessProbe": { - "timeoutSeconds": 10, - "initialDelaySeconds": 120, - "exec": { - "command": [ "/usr/libexec/check-container", "--live" ] - } - }, - "resources": { - "limits": { - "memory": "${MEMORY_POSTGRESQL_LIMIT}" - } - } - } - ] - } - } - } - } - ], - "parameters": [ - { - "name": "NAME", - "displayName": "Name", - "description": "The name assigned to all of the frontend objects defined in this template.", - "required": true, - "value": "django-psql-example" - }, - { - "name": "NAMESPACE", - "displayName": "Namespace", - "required": true, - "description": "The OpenShift Namespace where the ImageStream resides.", - "value": "openshift" - }, - { - "name": "PYTHON_VERSION", - "displayName": "Version of Python Image", - "description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi7, 3.8-ubi8, or latest).", - "value": "3.8-ubi8", - "required": true - }, - { - "name": "POSTGRESQL_VERSION", - "displayName": "Version of PostgreSQL Image", - "description": "Version of PostgreSQL image to be used (10-el8, 12-el8, or latest).", - "value": "12-el8", - "required": true - }, - { - "name": "MEMORY_LIMIT", - "displayName": "Memory Limit", - "required": true, - "description": "Maximum amount of memory the Django container can use.", - "value": "512Mi" - }, - { - "name": "MEMORY_POSTGRESQL_LIMIT", - "displayName": "Memory Limit (PostgreSQL)", - "required": true, - "description": "Maximum amount of memory the PostgreSQL container can use.", - "value": "512Mi" - }, - { - "name": "SOURCE_REPOSITORY_URL", - "displayName": "Git Repository URL", - "required": true, - "description": "The URL of the repository with your application source code.", - "value": "https://github.com/sclorg/django-ex.git" - }, - { - "name": "SOURCE_REPOSITORY_REF", - "displayName": "Git Reference", - "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." - }, - { - "name": "CONTEXT_DIR", - "displayName": "Context Directory", - "description": "Set this to the relative path to your project if it is not in the root of your repository." - }, - { - "name": "APPLICATION_DOMAIN", - "displayName": "Application Hostname", - "description": "The exposed hostname that will route to the Django service, if left blank a value will be defaulted.", - "value": "" - }, - { - "name": "GITHUB_WEBHOOK_SECRET", - "displayName": "GitHub Webhook Secret", - "description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", - "generate": "expression", - "from": "[a-zA-Z0-9]{40}" - }, - { - "name": "DATABASE_SERVICE_NAME", - "displayName": "Database Service Name", - "required": true, - "value": "postgresql" - }, - { - "name": "DATABASE_ENGINE", - "displayName": "Database Engine", - "required": true, - "description": "Database engine: postgresql, mysql or sqlite (default).", - "value": "postgresql" - }, - { - "name": "DATABASE_NAME", - "displayName": "Database Name", - "required": true, - "value": "default" - }, - { - "name": "DATABASE_USER", - "displayName": "Database Username", - "required": true, - "value": "django" - }, - { - "name": "DATABASE_PASSWORD", - "displayName": "Database User Password", - "generate": "expression", - "from": "[a-zA-Z0-9]{16}" - }, - { - "name": "APP_CONFIG", - "displayName": "Application Configuration File Path", - "description": "Relative path to Gunicorn configuration file (optional)." - }, - { - "name": "DJANGO_SECRET_KEY", - "displayName": "Django Secret Key", - "description": "Set this to a long random string.", - "generate": "expression", - "from": "[\\w]{50}" - }, - { - "name": "PIP_INDEX_URL", - "displayName": "Custom PyPi Index URL", - "description": "The custom PyPi index URL", - "value": "" - } - ] -} diff --git a/openshift/templates/django.json b/openshift/templates/django.json deleted file mode 100644 index 746a507..0000000 --- a/openshift/templates/django.json +++ /dev/null @@ -1,299 +0,0 @@ -{ - "kind": "Template", - "apiVersion": "template.openshift.io/v1", - "metadata": { - "name": "polls", - "annotations": { - "openshift.io/display-name": "Django", - "description": "Aplicación sacada del tutorial de Django: https://docs.djangoproject.com/en/5.1/intro/tutorial01/.", - "tags": "quickstart,python,django", - "iconClass": "icon-python", - "openshift.io/long-description": "This template defines resources needed to develop a Django based application, including a build configuration and application deployment configuration. It does not include a database.", - "openshift.io/provider-display-name": "ReyMota.", - "openshift.io/documentation-url": "http://gitea.reymota.es/creylopez/djangotutorial", - "openshift.io/support-url": "https://reymota.es", - "template.openshift.io/bindable": "false" - } - }, - "labels": { - "template": "polls", - "app": "polls" - }, - "message": "The following service(s) have been created in your project: ${NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/django-ex/blob/master/README.md.", - "objects": [ - { - "kind": "Secret", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}" - }, - "stringData" : { - "django-secret-key" : "${DJANGO_SECRET_KEY}" - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Exposes and load balances the application pods" - } - }, - "spec": { - "ports": [ - { - "name": "web", - "port": 8080, - "targetPort": 8080 - } - ], - "selector": { - "name": "${NAME}" - } - } - }, - { - "kind": "Route", - "apiVersion": "route.openshift.io/v1", - "metadata": { - "name": "${NAME}" - }, - "spec": { - "host": "${APPLICATION_DOMAIN}", - "to": { - "kind": "Service", - "name": "${NAME}" - } - } - }, - { - "kind": "ImageStream", - "apiVersion": "image.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Keeps track of changes in the application image" - } - } - }, - { - "kind": "BuildConfig", - "apiVersion": "build.openshift.io/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to build the application", - "template.alpha.openshift.io/wait-for-ready": "true" - } - }, - "spec": { - "source": { - "type": "Git", - "git": { - "uri": "${SOURCE_REPOSITORY_URL}", - "ref": "${SOURCE_REPOSITORY_REF}" - }, - "contextDir": "${CONTEXT_DIR}" - }, - "strategy": { - "type": "Source", - "sourceStrategy": { - "from": { - "kind": "ImageStreamTag", - "namespace": "${NAMESPACE}", - "name": "python:${PYTHON_VERSION}" - }, - "env": [ - { - "name": "PIP_INDEX_URL", - "value": "${PIP_INDEX_URL}" - } - ] - } - }, - "output": { - "to": { - "kind": "ImageStreamTag", - "name": "${NAME}:latest" - } - }, - "triggers": [ - { - "type": "ImageChange" - }, - { - "type": "ConfigChange" - }, - { - "type": "GitHub", - "github": { - "secret": "${GITHUB_WEBHOOK_SECRET}" - } - } - ], - "postCommit": { - "script": "./manage.py test" - } - } - }, - { - "kind": "Deployment", - "apiVersion": "apps/v1", - "metadata": { - "name": "${NAME}", - "annotations": { - "description": "Defines how to deploy the application server", - "template.alpha.openshift.io/wait-for-ready": "true", - "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" - } - }, - "spec": { - "strategy": { - "type": "RollingUpdate" - }, - "replicas": 1, - "selector": { - "matchLabels":{ - "name": "${NAME}" - } - }, - "template": { - "metadata": { - "name": "${NAME}", - "labels": { - "name": "${NAME}" - } - }, - "spec": { - "containers": [ - { - "name": "polls", - "image": " ", - "ports": [ - { - "containerPort": 8080 - } - ], - "readinessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 3, - "httpGet": { - "path": "/", - "port": 8080 - } - }, - "livenessProbe": { - "timeoutSeconds": 3, - "initialDelaySeconds": 30, - "httpGet": { - "path": "/", - "port": 8080 - } - }, - "env": [ - { - "name": "APP_CONFIG", - "value": "${APP_CONFIG}" - }, - { - "name": "DJANGO_SECRET_KEY", - "valueFrom": { - "secretKeyRef" : { - "name" : "${NAME}", - "key" : "django-secret-key" - } - } - } - ], - "resources": { - "limits": { - "memory": "${MEMORY_LIMIT}" - } - } - } - ] - } - } - } - } - ], - "parameters": [ - { - "name": "NAME", - "displayName": "Name", - "description": "The name assigned to all of the frontend objects defined in this template.", - "required": true, - "value": "polls" - }, - { - "name": "NAMESPACE", - "displayName": "Namespace", - "required": true, - "description": "The OpenShift Namespace where the ImageStream resides.", - "value": "openshift" - }, - { - "name": "PYTHON_VERSION", - "displayName": "Version of Python Image", - "description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi7, 3.8-ubi8, or latest).", - "value": "latest", - "required": true - }, - { - "name": "MEMORY_LIMIT", - "displayName": "Memory Limit", - "required": true, - "description": "Maximum amount of memory the container can use.", - "value": "512Mi" - }, - { - "name": "SOURCE_REPOSITORY_URL", - "displayName": "Git Repository URL", - "required": true, - "description": "The URL of the repository with your application source code.", - "value": "https://github.com/sclorg/django-ex.git" - }, - { - "name": "SOURCE_REPOSITORY_REF", - "displayName": "Git Reference", - "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." - }, - { - "name": "CONTEXT_DIR", - "displayName": "Context Directory", - "description": "Set this to the relative path to your project if it is not in the root of your repository." - }, - { - "name": "APPLICATION_DOMAIN", - "displayName": "Application Hostname", - "description": "The exposed hostname that will route to the Django service, if left blank a value will be defaulted.", - "value": "" - }, - { - "name": "GITHUB_WEBHOOK_SECRET", - "displayName": "GitHub Webhook Secret", - "description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", - "generate": "expression", - "from": "[a-zA-Z0-9]{40}" - }, - { - "name": "APP_CONFIG", - "displayName": "Application Configuration File Path", - "description": "Relative path to Gunicorn configuration file (optional)." - }, - { - "name": "DJANGO_SECRET_KEY", - "displayName": "Django Secret Key", - "description": "Set this to a long random string.", - "generate": "expression", - "from": "[\\w]{50}" - }, - { - "name": "PIP_INDEX_URL", - "displayName": "Custom PyPi Index URL", - "description": "The custom PyPi index URL", - "value": "" - } - ] -} diff --git a/src/config/entrypoint.sh b/src/config/entrypoint.sh new file mode 100644 index 0000000..7f3a7f4 --- /dev/null +++ b/src/config/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +RUN_PORT="8000" + +/opt/venv/bin/python manage.py migrate --no-input +/opt/venv/bin/gunicorn cfehome.wsgi:application --bind "0.0.0.0:${RUN_PORT}" --daemon + +su -c "nginx -g 'daemon off;'" diff --git a/manage.py b/src/manage.py similarity index 100% rename from manage.py rename to src/manage.py diff --git a/mysite/__init__.py b/src/mysite/__init__.py similarity index 100% rename from mysite/__init__.py rename to src/mysite/__init__.py diff --git a/mysite/__pycache__/__init__.cpython-311.pyc b/src/mysite/__pycache__/__init__.cpython-311.pyc similarity index 100% rename from mysite/__pycache__/__init__.cpython-311.pyc rename to src/mysite/__pycache__/__init__.cpython-311.pyc diff --git a/mysite/__pycache__/settings.cpython-311.pyc b/src/mysite/__pycache__/settings.cpython-311.pyc similarity index 100% rename from mysite/__pycache__/settings.cpython-311.pyc rename to src/mysite/__pycache__/settings.cpython-311.pyc diff --git a/mysite/__pycache__/urls.cpython-311.pyc b/src/mysite/__pycache__/urls.cpython-311.pyc similarity index 100% rename from mysite/__pycache__/urls.cpython-311.pyc rename to src/mysite/__pycache__/urls.cpython-311.pyc diff --git a/mysite/__pycache__/wsgi.cpython-311.pyc b/src/mysite/__pycache__/wsgi.cpython-311.pyc similarity index 100% rename from mysite/__pycache__/wsgi.cpython-311.pyc rename to src/mysite/__pycache__/wsgi.cpython-311.pyc diff --git a/mysite/asgi.py b/src/mysite/asgi.py similarity index 100% rename from mysite/asgi.py rename to src/mysite/asgi.py diff --git a/mysite/settings.py b/src/mysite/settings.py similarity index 100% rename from mysite/settings.py rename to src/mysite/settings.py diff --git a/mysite/urls.py b/src/mysite/urls.py similarity index 100% rename from mysite/urls.py rename to src/mysite/urls.py diff --git a/mysite/wsgi.py b/src/mysite/wsgi.py similarity index 100% rename from mysite/wsgi.py rename to src/mysite/wsgi.py diff --git a/polls/__init__.py b/src/polls/__init__.py similarity index 100% rename from polls/__init__.py rename to src/polls/__init__.py diff --git a/polls/admin.py b/src/polls/admin.py similarity index 100% rename from polls/admin.py rename to src/polls/admin.py diff --git a/polls/apps.py b/src/polls/apps.py similarity index 100% rename from polls/apps.py rename to src/polls/apps.py diff --git a/polls/models.py b/src/polls/models.py similarity index 100% rename from polls/models.py rename to src/polls/models.py diff --git a/polls/static/.gitignore b/src/polls/static/.gitignore similarity index 100% rename from polls/static/.gitignore rename to src/polls/static/.gitignore diff --git a/polls/static/css/portal.css b/src/polls/static/css/portal.css similarity index 100% rename from polls/static/css/portal.css rename to src/polls/static/css/portal.css diff --git a/polls/templates/ver_entorno.html b/src/polls/templates/ver_entorno.html similarity index 100% rename from polls/templates/ver_entorno.html rename to src/polls/templates/ver_entorno.html diff --git a/polls/tests.py b/src/polls/tests.py similarity index 100% rename from polls/tests.py rename to src/polls/tests.py diff --git a/polls/urls.py b/src/polls/urls.py similarity index 100% rename from polls/urls.py rename to src/polls/urls.py diff --git a/polls/views.py b/src/polls/views.py similarity index 100% rename from polls/views.py rename to src/polls/views.py diff --git a/requirements.txt b/src/requirements.txt similarity index 100% rename from requirements.txt rename to src/requirements.txt diff --git a/wsgi/static/.gitignore b/src/wsgi/static/.gitignore similarity index 100% rename from wsgi/static/.gitignore rename to src/wsgi/static/.gitignore