Skip to content

Commit

Permalink
google cloud implementation (#30)
Browse files Browse the repository at this point in the history
* first step

* updated pipfiles

* updated procfile for heroku

* temporarily setting debug to true in prod

* trying something else

* trying stuff again

* got it deployed, db doesnt work yet

* forms

* god why wont this work

* IT LIVES

* almost

* almost

* god pls work

* I am a code god

* deleted outdated fixture and added comment

Former-commit-id: 4bf0539
  • Loading branch information
NullDefault authored Mar 20, 2021
1 parent 4aea178 commit 7fb4fe9
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 452 deletions.
23 changes: 23 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg

# Pipenv stuff
Pipfile
Pipfile.lock
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ dmypy.json
/node_modules/
/csrs/

/staticfiles/
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ django-tailwind = "*"
gunicorn = "*"
cryptography = "==3.3.2"
crispy-tailwind = "*"
mysqlclient = "*"
pymysql = "*"

[requires]
python_version = "3.8"
python_version = "3.9"
29 changes: 24 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Procfile

This file was deleted.

31 changes: 31 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
runtime: python39
env: standard
entrypoint: gunicorn -b :$PORT config.wsgi


handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
static_dir: staticfiles/

# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
script: auto

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10

env_variables:
DJANGO_SETTINGS_MODULE: "config.settings.prod"
DJANGO_SECRET_KEY: "42)%4yx)aa@a=+_c(fn&kf3g19xax+=+a&key4i=!98zyim=8j"
29 changes: 6 additions & 23 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import os
from pathlib import Path

# GENERAL
# ------------------------------------------------------------------------------
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts\
INTERNAL_IPS = ['127.0.0.1']
ALLOWED_HOSTS = ["localhost",
"0.0.0.0",
"127.0.0.1",
"http://cs3-drew.herokuapp.com",
"https://cs3-drew.herokuapp.com",
"cs3-drew.herokuapp.com"]
ALLOWED_HOSTS = ['*']
# APPS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.sites',

Expand Down Expand Up @@ -88,16 +82,6 @@
},
]

# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# PASSWORDS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -133,16 +117,15 @@
# STATIC
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(BASE_DIR.joinpath('staticfiles'))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [
str(BASE_DIR.joinpath('static')),
str(BASE_DIR.joinpath('theme', 'static'))
os.path.join(BASE_DIR, 'static')
]
# http://whitenoise.evans.io/en/stable/django.html#add-compression-and-caching-support
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"

# EMAIL
# ------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
DEBUG = True
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = '43)%4yx)aa@a=+_c(fn&kf3g29xax+=+a&key9i=!98zyim=8j'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
29 changes: 29 additions & 0 deletions config/settings/gcloud_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from .base import *

# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = '43)%4yx)aa@a=+_c(fn&kf3g29xax+=+a&key9i=!98zyim=8j'

import pymysql

pymysql.version_info = (1, 4, 6, 'final', 0)
pymysql.install_as_MySQLdb()

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'USER': 'django',
'PASSWORD': 'cs3',
'NAME': 'django_data',
}
}

"""
To run the proxy:
cloud_sql_proxy.exe -instances="rapid-league-302721:us-east1:my-sql-db"=tcp:3306
dont forget to change manage.py settings to this file
"""
18 changes: 16 additions & 2 deletions config/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
from .base import *
import socket
import os

# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')

import pymysql

pymysql.version_info = (1, 4, 6, 'final', 0)
pymysql.install_as_MySQLdb()


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/rapid-league-302721:us-east1:my-sql-db',
'USER': 'django',
'PASSWORD': 'cs3',
'NAME': 'django_data'
}
}
3 changes: 3 additions & 0 deletions config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')

application = get_wsgi_application()

application = WhiteNoise(application, root='/staticfiles')
Loading

0 comments on commit 7fb4fe9

Please sign in to comment.