Skip to content

Commit 9b902eb

Browse files
author
Anushka
committed
first commit
0 parents  commit 9b902eb

23 files changed

+597
-0
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.dockerignore
2+
Dockerfile
3+
db.sqlite3
4+
__pycache__
5+
*.pyc
6+
*.pyo
7+
*.pyd
8+
.Python
9+
env
10+
pip-log.txt
11+
pip-delete-this-directory.txt
12+
.tox
13+
.coverage
14+
.coverage.*
15+
.cache
16+
coverage.xml
17+
*,cover
18+
*.log
19+
.git

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static/

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2015, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
# [START docker]
15+
16+
# The Google App Engine python runtime is Debian Jessie with Python installed
17+
# and various os-level packages to allow installation of popular Python
18+
# libraries. The source is on github at:
19+
# https://github.com/GoogleCloudPlatform/python-docker
20+
FROM gcr.io/google_appengine/python
21+
22+
# Create a virtualenv for the application dependencies.
23+
# # If you want to use Python 2, use the -p python2.7 flag.
24+
RUN virtualenv -p python3 /env
25+
ENV PATH /env/bin:$PATH
26+
27+
ADD requirements.txt /app/requirements.txt
28+
RUN /env/bin/pip install --upgrade pip && /env/bin/pip install -r /app/requirements.txt
29+
ADD . /app
30+
31+
CMD gunicorn -b :$PORT mysite.wsgi
32+
# [END docker]

Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
GCLOUD_PROJECT:=$(shell gcloud config list project --format="value(core.project)")
2+
3+
.PHONY: all
4+
all: deploy
5+
6+
.PHONY: create-cluster
7+
create-cluster:
8+
gcloud container clusters create polls \
9+
--scopes "https://www.googleapis.com/auth/userinfo.email","cloud-platform"
10+
11+
.PHONY: create-bucket
12+
create-bucket:
13+
gsutil mb gs://$(GCLOUD_PROJECT)
14+
gsutil defacl set public-read gs://$(GCLOUD_PROJECT)
15+
16+
.PHONY: build
17+
build:
18+
docker build -t gcr.io/$(GCLOUD_PROJECT)/polls .
19+
20+
.PHONY: push
21+
push: build
22+
gcloud docker push -- gcr.io/$(GCLOUD_PROJECT)/polls
23+
24+
.PHONY: template
25+
template:
26+
sed -i ".tmpl" "s/\$$GCLOUD_PROJECT/$(GCLOUD_PROJECT)/g" polls.yaml
27+
28+
.PHONY: deploy
29+
deploy: push template
30+
kubectl create -f polls.yaml
31+
32+
.PHONY: update
33+
update:
34+
kubectl patch deployment polls -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
35+
36+
.PHONY: delete
37+
delete:
38+
kubectl delete rc polls
39+
kubectl delete service polls

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Getting started with Django on Google Container Engine
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=kubernetes_engine/django_tutorial/README.md
7+
8+
This repository is an example of how to run a [Django](https://www.djangoproject.com/)
9+
app on Google Container Engine. It uses the
10+
[Writing your first Django app](https://docs.djangoproject.com/en/1.11/intro/tutorial01/)
11+
Polls application (parts 1 and 2) as the example app to deploy. From here on
12+
out, we refer to this app as the 'polls' application.
13+
14+
15+
# Tutorial
16+
See our [Django on Container Engine](https://cloud.google.com/python/django/kubernetes-engine) tutorial for instructions for setting up and deploying this sample application.
17+
18+
19+
## Contributing changes
20+
21+
* See [CONTRIBUTING.md](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md)
22+
23+
24+
## Licensing
25+
26+
* See [LICENSE](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/LICENSE)

__init__.py

Whitespace-only changes.

manage.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# Copyright 2015 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
import sys
18+
19+
if __name__ == "__main__":
20+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
21+
22+
from django.core.management import execute_from_command_line
23+
24+
execute_from_command_line(sys.argv)

mysite/__init__.py

Whitespace-only changes.

mysite/settings.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright 2015 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
import os
17+
18+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19+
20+
# Quick-start development settings - unsuitable for production
21+
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
22+
23+
# SECURITY WARNING: keep the secret key used in production secret!
24+
SECRET_KEY = 'pf-@jxtojga)z+4s*uwbgjrq$aep62-thd0q7f&o77xtpka!_m'
25+
26+
# SECURITY WARNING: don't run with debug turned on in production!
27+
DEBUG = True
28+
29+
# SECURITY WARNING: If you deploy a Django app to production, make sure to set
30+
# an appropriate host here.
31+
# See https://docs.djangoproject.com/en/1.10/ref/settings/
32+
ALLOWED_HOSTS = ['*']
33+
34+
# Application definition
35+
36+
INSTALLED_APPS = (
37+
'django.contrib.admin',
38+
'django.contrib.auth',
39+
'django.contrib.contenttypes',
40+
'django.contrib.sessions',
41+
'django.contrib.messages',
42+
'django.contrib.staticfiles',
43+
'polls'
44+
)
45+
46+
MIDDLEWARE = (
47+
'django.middleware.security.SecurityMiddleware',
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
)
55+
56+
ROOT_URLCONF = 'mysite.urls'
57+
58+
TEMPLATES = [
59+
{
60+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
61+
'DIRS': [],
62+
'APP_DIRS': True,
63+
'OPTIONS': {
64+
'context_processors': [
65+
'django.template.context_processors.debug',
66+
'django.template.context_processors.request',
67+
'django.contrib.auth.context_processors.auth',
68+
'django.contrib.messages.context_processors.messages',
69+
],
70+
},
71+
},
72+
]
73+
74+
WSGI_APPLICATION = 'mysite.wsgi.application'
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
78+
79+
# [START dbconfig]
80+
DATABASES = {
81+
'default': {
82+
# If you are using Cloud SQL for MySQL rather than PostgreSQL, set
83+
# 'ENGINE': 'django.db.backends.mysql' instead of the following.
84+
'ENGINE': 'django.db.backends.postgresql',
85+
'NAME': 'polls',
86+
'USER': 'root',
87+
'PASSWORD': 'passcode',
88+
'HOST': 'sql-ch-dev-mysql.dev',
89+
'PORT': '3306',
90+
}
91+
}
92+
# [END dbconfig]
93+
94+
# Internationalization
95+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
96+
97+
LANGUAGE_CODE = 'en-us'
98+
99+
TIME_ZONE = 'UTC'
100+
101+
USE_I18N = True
102+
103+
USE_L10N = True
104+
105+
USE_TZ = True
106+
107+
# Static files (CSS, JavaScript, Images)
108+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
109+
110+
# [START staticurl]
111+
STATIC_URL = '/static/'
112+
# STATIC_URL = 'https://storage.googleapis.com/<your-gcs-bucket>/static/'
113+
# [END staticurl]
114+
115+
STATIC_ROOT = 'static/'

mysite/urls.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2015 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from django.conf import settings
16+
from django.contrib import admin
17+
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
18+
from django.urls import include, path
19+
20+
21+
urlpatterns = [
22+
path('admin/', admin.site.urls),
23+
path('', include('polls.urls')),
24+
]
25+
26+
# Only serve static files from Django during development
27+
# Use Google Cloud Storage or an alternative CDN for production
28+
if settings.DEBUG:
29+
urlpatterns += staticfiles_urlpatterns()

mysite/wsgi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2015 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
import os
17+
18+
from django.core.wsgi import get_wsgi_application
19+
20+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
21+
22+
application = get_wsgi_application()

0 commit comments

Comments
 (0)