Compare commits

...

22 Commits

Author SHA1 Message Date
  Lumir Balhar 1e9fd4e76f Update psycopg2-binary dependency to 2.9.10 11 months ago
  Petr Hracek f0a3d52fa6
Merge pull request #211 from phracek/4_2_x_master_migrate_deployment 2 years ago
  Petr "Stone" Hracek 37ccba86a5 Migration from DeploymentConfig to Deployment 2 years ago
  BeataSolitudo e84d080442
Update README.md 2 years ago
  BeataSolitudo 846a8a5a78
Update requirements.txt 2 years ago
  Lumir Balhar 6122fbe1d4 New version of psycopg2-binary works fine with Python 3.11 3 years ago
  Siteshwar Vashisht 4eae0a39d8 Fix broken links to documentation 3 years ago
  Petr Hracek 644f775552
Merge pull request #190 from multi-arch/samples-3.2 3 years ago
  Yaakov Selkowitz 0d053208af Update templates to Python 3.9 4 years ago
  Yaakov Selkowitz 69335c5513 Use groupified apiVersion 4 years ago
  Lumir Balhar 73c4ab159c Update links to Django documentation 4 years ago
  Lumir Balhar 85920f4bad Set default auto field if primary key is missing 4 years ago
  Lumir Balhar 529851cb5e Update dependencies 4 years ago
  Ben Parees 914c3ec7ad
Merge pull request #178 from sclorg/frenzymadness-patch-1 4 years ago
  Lumír 'Frenzy' Balhar f8f9d38b75
Mention Python compatibility in the readme 4 years ago
  Afreed-Sharief fa88380112 Update views.py 5 years ago
  Honza Horak a3cc749711 Update templates to 3.8 5 years ago
  Honza Horak d535d711a2
Merge pull request #162 from multi-arch/2.2.x 5 years ago
  Yaakov Selkowitz 2df0ccae87 Move templates to RHEL/CentOS/UBI 8 and PostgreSQL 12 5 years ago
  Lumír 'Frenzy' Balhar ba0c53d1fb
Merge pull request #157 from frenzymadness/psycopg2-wheels-2 5 years ago
  Lumir Balhar 6381ce544e Move from psycopg2 to psycopg2-binary to use manylinux wheels 5 years ago
  Lumir Balhar a33a1e9762 Update note in readme to reflect the old-new branches schema. 5 years ago
10 changed files with 84 additions and 157 deletions
Split View
  1. +3
    -3
      README.md
  2. +22
    -53
      openshift/templates/django-postgresql-persistent.json
  3. +22
    -53
      openshift/templates/django-postgresql.json
  4. +14
    -29
      openshift/templates/django.json
  5. +10
    -8
      project/settings.py
  6. +1
    -1
      project/urls.py
  7. +1
    -1
      project/wsgi.py
  8. +7
    -7
      requirements.txt
  9. +2
    -2
      welcome/templates/welcome/index.html
  10. +2
    -0
      welcome/views.py

+ 3
- 3
README.md View File

@ -2,7 +2,7 @@
This is a [Django](http://www.djangoproject.com) project that you can use as the starting point to develop your own and deploy it on an [OpenShift](https://github.com/openshift/origin) cluster.
**NOTE:** The current master branch works with Django 2.2 LTS. The version for older Django 1.11 LTS is in [branch 1.11.x](https://github.com/sclorg/django-ex/tree/1.11.x).
**NOTE:** This is an example Django application for specific Django LTS version. If you want an older or newer version, check the alternative branches.
The steps in this document assume that you have access to an OpenShift deployment that you can deploy applications on.
@ -56,9 +56,9 @@ To run this project in your development machine, follow these steps:
2. Ensure that the executable `pg_config` is available on your machine. You can check this using `which pg_config`. Otherwise, sqlite will be used.
3. Fork this repo and clone your fork:
**Note:** pg_config is not needed. You can use sqlite instead.
`git clone https://github.com/sclorg/django-ex.git`
3. Fork this repo and clone your fork. Make sure that you are in the right branch.
4. Install dependencies:


+ 22
- 53
openshift/templates/django-postgresql-persistent.json View File

@ -1,6 +1,6 @@
{
"kind": "Template",
"apiVersion": "v1",
"apiVersion": "template.openshift.io/v1",
"metadata": {
"name": "django-psql-persistent",
"annotations": {
@ -58,7 +58,7 @@
},
{
"kind": "Route",
"apiVersion": "v1",
"apiVersion": "route.openshift.io/v1",
"metadata": {
"name": "${NAME}"
},
@ -72,7 +72,7 @@
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"apiVersion": "image.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -82,7 +82,7 @@
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"apiVersion": "build.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -141,40 +141,25 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"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"
"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"
},
"triggers": [
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"django-psql-persistent"
],
"from": {
"kind": "ImageStreamTag",
"name": "${NAME}:latest"
}
}
},
{
"type": "ConfigChange"
}
],
"replicas": 1,
"selector": {
"name": "${NAME}"
"matchLabels":{
"name": "${NAME}"
}
},
"template": {
"metadata": {
@ -305,41 +290,25 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"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"
"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"
},
"triggers": [
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"postgresql"
],
"from": {
"kind": "ImageStreamTag",
"namespace": "${NAMESPACE}",
"name": "postgresql:${POSTGRESQL_VERSION}"
}
}
},
{
"type": "ConfigChange"
}
],
"replicas": 1,
"selector": {
"name": "${DATABASE_SERVICE_NAME}"
"matchLabels":{
"name": "${DATABASE_SERVICE_NAME}"
}
},
"template": {
"metadata": {
@ -440,15 +409,15 @@
{
"name": "PYTHON_VERSION",
"displayName": "Version of Python Image",
"description": "Version of Python image to be used (3.6 or latest).",
"value": "3.6",
"description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi8, 3.9-ubi8, or latest).",
"value": "3.9-ubi8",
"required": true
},
{
"name": "POSTGRESQL_VERSION",
"displayName": "Version of PostgreSQL Image",
"description": "Version of PostgreSQL image to be used (10 or latest).",
"value": "10",
"description": "Version of PostgreSQL image to be used (10-el8, 12-el8, or latest).",
"value": "12-el8",
"required": true
},
{


+ 22
- 53
openshift/templates/django-postgresql.json View File

@ -1,6 +1,6 @@
{
"kind": "Template",
"apiVersion": "v1",
"apiVersion": "template.openshift.io/v1",
"metadata": {
"name": "django-psql-example",
"annotations": {
@ -58,7 +58,7 @@
},
{
"kind": "Route",
"apiVersion": "v1",
"apiVersion": "route.openshift.io/v1",
"metadata": {
"name": "${NAME}"
},
@ -72,7 +72,7 @@
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"apiVersion": "image.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -82,7 +82,7 @@
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"apiVersion": "build.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -141,40 +141,25 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"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"
"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"
},
"triggers": [
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"django-psql-example"
],
"from": {
"kind": "ImageStreamTag",
"name": "${NAME}:latest"
}
}
},
{
"type": "ConfigChange"
}
],
"replicas": 1,
"selector": {
"name": "${NAME}"
"matchLabels":{
"name": "${NAME}"
}
},
"template": {
"metadata": {
@ -288,41 +273,25 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"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"
"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"
},
"triggers": [
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"postgresql"
],
"from": {
"kind": "ImageStreamTag",
"namespace": "${NAMESPACE}",
"name": "postgresql:${POSTGRESQL_VERSION}"
}
}
},
{
"type": "ConfigChange"
}
],
"replicas": 1,
"selector": {
"name": "${DATABASE_SERVICE_NAME}"
"matchLabels":{
"name": "${DATABASE_SERVICE_NAME}"
}
},
"template": {
"metadata": {
@ -421,15 +390,15 @@
{
"name": "PYTHON_VERSION",
"displayName": "Version of Python Image",
"description": "Version of Python image to be used (3.6 or latest).",
"value": "3.6",
"description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi8, 3.9-ubi8, or latest).",
"value": "3.9-ubi8",
"required": true
},
{
"name": "POSTGRESQL_VERSION",
"displayName": "Version of PostgreSQL Image",
"description": "Version of PostgreSQL image to be used (10 or latest).",
"value": "10",
"description": "Version of PostgreSQL image to be used (10-el8, 12-el8, or latest).",
"value": "12-el8",
"required": true
},
{


+ 14
- 29
openshift/templates/django.json View File

@ -1,6 +1,6 @@
{
"kind": "Template",
"apiVersion": "v1",
"apiVersion": "template.openshift.io/v1",
"metadata": {
"name": "django-example",
"annotations": {
@ -55,7 +55,7 @@
},
{
"kind": "Route",
"apiVersion": "v1",
"apiVersion": "route.openshift.io/v1",
"metadata": {
"name": "${NAME}"
},
@ -69,7 +69,7 @@
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"apiVersion": "image.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -79,7 +79,7 @@
},
{
"kind": "BuildConfig",
"apiVersion": "v1",
"apiVersion": "build.openshift.io/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
@ -138,40 +138,25 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"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"
"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": "Rolling"
"type": "RollingUpdate"
},
"triggers": [
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"django-example"
],
"from": {
"kind": "ImageStreamTag",
"name": "${NAME}:latest"
}
}
},
{
"type": "ConfigChange"
}
],
"replicas": 1,
"selector": {
"name": "${NAME}"
"matchLabels":{
"name": "${NAME}"
}
},
"template": {
"metadata": {
@ -251,8 +236,8 @@
{
"name": "PYTHON_VERSION",
"displayName": "Version of Python Image",
"description": "Version of Python image to be used (3.6 or latest).",
"value": "3.6",
"description": "Version of Python image to be used (3.6-ubi8, 3.8-ubi8, 3.9-ubi8, or latest).",
"value": "3.9-ubi8",
"required": true
},
{


+ 10
- 8
project/settings.py View File

@ -1,13 +1,13 @@
"""
Django settings for this project.
Generated by 'django-admin startproject' using Django 2.2.12.
Generated by 'django-admin startproject' using Django 3,2,4.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# The SECRET_KEY is provided via an environment variable in OpenShift
@ -80,7 +80,7 @@ WSGI_APPLICATION = 'project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
from . import database
@ -88,9 +88,11 @@ DATABASES = {
'default': database.config()
}
# https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
@ -109,7 +111,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
@ -123,7 +125,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')


+ 1
- 1
project/urls.py View File

@ -1,7 +1,7 @@
"""project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views


+ 1
- 1
project/wsgi.py View File

@ -4,7 +4,7 @@ WSGI config for this project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os


+ 7
- 7
requirements.txt View File

@ -1,7 +1,7 @@
Django>=2.2.12,<3.0
django-debug-toolbar==2.2
gunicorn==20.0.4
psycopg2==2.8.5
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0
Django>=4.2,<5.0
django-debug-toolbar==3.2.1
gunicorn==20.1.0
psycopg2-binary==2.9.10
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0

+ 2
- 2
welcome/templates/welcome/index.html View File

@ -220,7 +220,7 @@ pre {
<section class='col-xs-12 col-sm-6 col-md-6'>
<section>
<h2>How to use this example application</h2>
<p>For instructions on how to use this application with OpenShift, start by reading the <a href="http://docs.okd.io/latest/dev_guide/templates.html#using-the-quickstart-templates">Developer Guide</a>.</p>
<p>For instructions on how to use this application with OpenShift, start by reading the <a href="https://docs.okd.io/latest/openshift_images/using-templates.html#templates-using-instant-app-quickstart_using-templates">Developer Guide</a>.</p>
<h2>Deploying code changes</h2>
<p>
@ -282,7 +282,7 @@ $ git push</pre>
<h2>Managing your application</h2>
<p>Documentation on how to manage your application from the Web Console or Command Line is available at the <a href="http://docs.okd.io/latest/dev_guide/overview.html">Developer Guide</a>.</p>
<p>Documentation on how to manage your application from the <a href="https://docs.okd.io/latest/web_console/web-console.html">Web Console</a> or <a href="https://docs.okd.io/latest/cli_reference/index.html">Command Line</a> is available at the <a href="http://docs.okd.io/latest/welcome/overview.html">OKD Documentation</a>.</p>
<h3>Web Console</h3>
<p>You can use the Web Console to view the state of your application components and launch new builds.</p>


+ 2
- 0
welcome/views.py View File

@ -9,6 +9,7 @@ from .models import PageView
# Create your views here.
def index(request):
"""Takes an request object as a parameter and creates an pageview object then responds by rendering the index view."""
hostname = os.getenv('HOSTNAME', 'unknown')
PageView.objects.create(hostname=hostname)
@ -19,4 +20,5 @@ def index(request):
})
def health(request):
"""Takes an request as a parameter and gives the count of pageview objects as reponse"""
return HttpResponse(PageView.objects.count())

Loading…
Cancel
Save