Skip to content

Commit

Permalink
Add source code
Browse files Browse the repository at this point in the history
  • Loading branch information
robertDouglass committed Jul 17, 2024
1 parent 0a86865 commit 4f0dcc0
Show file tree
Hide file tree
Showing 23 changed files with 472 additions and 2 deletions.
8 changes: 8 additions & 0 deletions 02_install_django_postgresql_pgvector_upsun/.environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set database environment variables
export DB_HOST="$POSTGRESQL_HOST"
export DB_PORT="$POSTGRESQL_PORT"
export DB_PATH="$POSTGRESQL_PATH"
export DB_USERNAME="$POSTGRESQL_USERNAME"
export DB_PASSWORD="$POSTGRESQL_PASSWORD"
export DB_SCHEME="postgresql"
export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}"
1 change: 1 addition & 0 deletions 02_install_django_postgresql_pgvector_upsun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myenv
154 changes: 154 additions & 0 deletions 02_install_django_postgresql_pgvector_upsun/.upsun/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Complete list of all available properties: https://docs.upsun.com/create-apps/app-reference.html
applications:
upsun_django_sqlite:
# Application source code directory
source:
root: "/"

# The runtime the application uses.
# Complete list of available runtimes: https://docs.upsun.com/create-apps/app-reference.html#types
type: "python:3.11"

# Choose which container profile (ratio CPU+RAM) your app will use. Default value comes from the image itself.
# More information: https://docs.upsun.com/manage-resources/adjust-resources.html#adjust-a-container-profile
# container_profile:

# The relationships of the application with services or other applications.
# The left-hand side is the name of the relationship as it will be exposed
# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand
# side is in the form `<service name>:<endpoint name>`.
# More information: https://docs.upsun.com/create-apps/app-reference.html#relationships
relationships:
postgresql:


# Mounts define directories that are writable after the build is complete.
# More information: https://docs.upsun.com/create-apps/app-reference.html#mounts
# mounts:
# "/var/uploads": # Represents the path in the app.
# source: "storage" # "storage" sources are unique to the app, but shared among instances of the app. "service" sources can be shared among apps.
# source_path: "var/uploads" # The subdirectory within the mounted disk (the source) where the mount should point.

# The web key configures the web server running in front of your app.
# More information: https://docs.upsun.com/create-apps/app-reference.html#web
web:
# Commands are run once after deployment to start the application process.
# More information: https://docs.upsun.com/create-apps/app-reference.html#web-commands
commands:
# The command to launch your app. If it terminates, it’s restarted immediately.
# You can use the $PORT or the $SOCKET environment variable depending on the socket family of your upstream
start: "gunicorn --pythonpath=myproject -b unix:$SOCKET myproject.wsgi --log-file -"
# You can listen to a UNIX socket (unix) or a TCP port (tcp, default).
# Whether your app should speak to the webserver via TCP or Unix socket. Defaults to tcp
# More information: https://docs.upsun.com/create-apps/app-reference.html#where-to-listen
upstream:
# Whether your app should speak to the webserver via TCP or Unix socket. Defaults to tcp
# More information: https://docs.upsun.com/create-apps/app-reference.html#where-to-listen
socket_family: unix
# Each key in locations is a path on your site with a leading /.
# More information: https://docs.upsun.com/create-apps/app-reference.html#locations
locations:
"/":
passthru: true

"/static":
allow: true
expires: "1h"
root: "static"



# Alternate copies of the application to run as background processes.
# More information: https://docs.upsun.com/create-apps/app-reference.html#workers
# workers:

# The timezone for crons to run. Format: a TZ database name. Defaults to UTC, which is the timezone used for all logs
# no matter the value here. More information: https://docs.upsun.com/create-apps/timezone.html
# timezone: <time-zone>

# Access control for roles accessing app environments.
# More information: https://docs.upsun.com/create-apps/app-reference.html#access
# access:

# Variables to control the environment. More information: https://docs.upsun.com/create-apps/app-reference.html#variables
# variables:
# env:
# # Add environment variables here that are static.
# PYTHONUNBUFFERED: "1"

# Outbound firewall rules for the application. More information: https://docs.upsun.com/create-apps/app-reference.html#firewall
# firewall:

# Specifies a default set of build tasks to run. Flavors are language-specific.
# More information: https://docs.upsun.com/create-apps/app-reference.html#build
build:
flavor: none

# Installs global dependencies as part of the build process. They’re independent of your app’s dependencies and
# are available in the PATH during the build process and in the runtime environment. They’re installed before
# the build hook runs using a package manager for the language.
# More information: https://docs.upsun.com/create-apps/app-reference.html#dependencies
# dependencies:
# python3: # Specify one Python 3 package per line.
# numpy: '*'

# Hooks allow you to customize your code/environment as the project moves through the build and deploy stages
# More information: https://docs.upsun.com/create-apps/app-reference.html#hooks
hooks:
# The build hook is run after any build flavor.
# More information: https://docs.upsun.com/create-apps/hooks/hooks-comparison.html#build-hook
build: |
set -eux
pip install -r requirements.txt
# Collect static files so that they can be served by Upsun
python myproject/manage.py collectstatic --noinput
# The deploy hook is run after the app container has been started, but before it has started accepting requests.
# More information: https://docs.upsun.com/create-apps/hooks/hooks-comparison.html#deploy-hook
deploy: |
set -eux
python myproject/manage.py migrate
# The post_deploy hook is run after the app container has been started and after it has started accepting requests.
# More information: https://docs.upsun.com/create-apps/hooks/hooks-comparison.html#deploy-hook
# post_deploy: |

# Scheduled tasks for the app.
# More information: https://docs.upsun.com/create-apps/app-reference.html#crons
# crons:

# Customizations to your PHP or Lisp runtime. More information: https://docs.upsun.com/create-apps/app-reference.html#runtime
# runtime:

# More information: https://docs.upsun.com/create-apps/app-reference.html#additional-hosts
# additional_hosts:

# The services of the project.
#
# Each service listed will be deployed
# to power your Upsun project.
# More information: https://docs.upsun.com/add-services.html
# Full list of available services: https://docs.upsun.com/add-services.html#available-services
services:
postgresql:
type: postgresql:16 # All available versions are: 15, 14, 13, 12, 11
configuration:
extensions:
- vector


# The routes of the project.
#
# Each route describes how an incoming URL is going
# to be processed by Upsun.
# More information: https://docs.upsun.com/define-routes.html
routes:
"https://{default}/":
type: upstream
upstream: "upsun_django_sqlite:http"
# A basic redirect definition
# More information: https://docs.upsun.com/define-routes.html#basic-redirect-definition
"https://www.{default}":
type: redirect
to: "https://{default}/"
22 changes: 22 additions & 0 deletions 02_install_django_postgresql_pgvector_upsun/myproject/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for myproject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

application = get_asgi_application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""
Django settings for myproject project.
Generated by 'django-admin startproject' using Django 5.0.7.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-9x^ejjx!ie0_r(pc+v&jh)f2#!l3lrx7h+du!@3_y5zq0670=d'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'myproject.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'myproject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

# Set the DB_DIR to one level higher than BASE_DIR
DB_DIR = BASE_DIR.parent

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db/db.sqlite3',
'NAME': os.path.join(DB_DIR, 'db', 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


from .settings_psh import *
Loading

0 comments on commit 4f0dcc0

Please sign in to comment.