You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated Django Container Engine sample to use CloudSQL v2, sidecar co… (GoogleCloudPlatform#758)
* Updated Django Container Engine sample to use CloudSQL v2, sidecar container pod pattern, Django 1.10, and Deployment rather than ReplicationController
* Added secrets for database user/password
Copy file name to clipboardExpand all lines: container_engine/django_tutorial/README.md
+2-179Lines changed: 2 additions & 179 deletions
Original file line number
Diff line number
Diff line change
@@ -5,187 +5,10 @@ app on Google Container Engine. It uses the [Writing your first Django app](http
5
5
.9/intro/tutorial01/) Polls application as the example app to deploy. From here on out, we refer to this app as
6
6
the 'polls' application.
7
7
8
-
## Pre-requisites
9
8
10
-
1. Create a project in the [Google Cloud Platform Console](https://console.cloud.google.com).
9
+
# Tutorial
10
+
See our [Django on Container Engine](https://cloud.google.com/python/django/container-engine) tutorial for instructions for setting up and deploying this sample application.
11
11
12
-
2.[Enable billing](https://console.cloud.google.com/project/_/settings) for your project.
13
-
14
-
3.[Enable APIs](https://console.cloud.google.com/flows/enableapi?apiid=datastore,pubsub,storage_api,logging,plus) for your project. The provided link will enable all necessary APIs, but if you wish to do so manually you will need Datastore, Pub/Sub, Storage, and Logging.
15
-
16
-
4. Install the [Google Cloud SDK](https://cloud.google.com/sdk)
17
-
18
-
$ curl https://sdk.cloud.google.com | bash
19
-
$ gcloud init
20
-
21
-
5. Install [Docker](https://www.docker.com/).
22
-
23
-
## Makefile
24
-
25
-
Several commands listed below are provided in simpler form via the Makefile. Many of them use the GCLOUD_PROJECT
26
-
environment variable, which will be picked up from your gcloud config. Make sure you set this to the correct project,
The scopes specified in the `--scope` argument allows nodes in the cluster to access Google Cloud Platform APIs, such as the Cloud Datastore API.
40
-
41
-
### Create a Cloud Storage bucket
42
-
43
-
The bookshelf application uses [Google Cloud Storage](https://cloud.google.com/storage) to store image files. Create a bucket for your project:
44
-
45
-
gsutil mb gs://<your-project-id>
46
-
gsutil defacl set public-read gs://<your-project-id>
47
-
48
-
49
-
## Setup the database
50
-
51
-
This tutorial assumes you are setting up Django using a SQL database, which is the easiest way to run Django. If you have an existing SQL database running, you can use that, but if not, these are the instructions for creating a managed MySQL instance using CloudSQL.
52
-
53
-
54
-
* Create a [CloudSQL instance](https://console.cloud.google.com/project/_/sql/create)
55
-
56
-
* In the instances list, click your Cloud SQL instance.
57
-
58
-
* Click Access Control.
59
-
60
-
* In the IP address subsection, click Request an IPv4 address to enable access to the Cloud SQL instance through an
61
-
IPv4 address. It will take a moment to initialize the new IP address.
62
-
63
-
* Also under Access Control, in the Authorization subsection, under Allowed Networks, click the add (+) button .
64
-
65
-
* In the Networks field, enter 0.0.0.0/0. This value allows access by all IP addresses.
66
-
67
-
* Click Save.
68
-
69
-
Note: setting allowed networks to 0.0.0.0/0 opens your SQL instance to traffic from any computer. For production databases, it's highly recommended to limit the authorized networks to only IP ranges that need access.
70
-
71
-
* Alternatively, the instance can be created with the gcloud command line tool as follows, substituting `your-root-pw
* Using the root password created in the last step to create a new database, user, and password using your preferred MySQL client. Alternatively, follow these instructions to create the database and user from the console.
79
-
* From the CloudSQL instance in the console, click New user.
80
-
* Enter a username and password for the application. For example, name the user "pythonapp" and give it a randomly
81
-
generated password.
82
-
* Click Add.
83
-
* Click Databases and then click New database.
84
-
* For Name, enter the name of your database (for example, "polls"), and click Add.
85
-
86
-
Once you have a SQL host, configuring mysite/settings.py to point to your database. Change `your-database-name`,
87
-
`your-database-user`, `your-database-host` , and `your-database-password` to match the settings created above. Note the
88
-
instance name is not used in this configuration, and the host name is the IP address you created.
89
-
90
-
91
-
## Running locally
92
-
93
-
First make sure you have Django installed. It's recommended you do so in a
94
-
[virtualenv](https://virtualenv.pypa.io/en/latest/). The requirements.txt
95
-
contains just the Django dependency.
96
-
97
-
pip install -r requirements.txt
98
-
99
-
Once the database is setup, run the migrations.
100
-
101
-
python manage.py migrate
102
-
103
-
If you'd like to use the admin console, create a superuser.
104
-
105
-
python manage.py createsuperuser
106
-
107
-
The app can be run locally the same way as any other Django app.
108
-
109
-
python manage.py runserver
110
-
111
-
Now you can view the admin panel of your local site at
112
-
113
-
http://localhost:8080/admin
114
-
115
-
# Deploying To Google Container Engine (Kubernetes)
116
-
117
-
## Build the polls container
118
-
119
-
Before the application can be deployed to Container Engine, you will need build and push the image to [Google Container Registry](https://cloud.google.com/container-registry/).
120
-
121
-
docker build -t gcr.io/your-project-id/polls .
122
-
gcloud docker push gcr.io/your-project-id/polls
123
-
124
-
Alternatively, this can be done using
125
-
126
-
make push
127
-
128
-
129
-
## Deploy to the application
130
-
131
-
### Serve the static content
132
-
133
-
Collect all the static assets into the static/ folder.
134
-
135
-
python manage.py collectstatic
136
-
137
-
When DEBUG is enabled, Django can serve the files directly from that folder. For production purposes, you should
138
-
serve static assets from a CDN. Here are instructions for how to do this using Google Cloud Storage.
139
-
140
-
Upload it to CloudStorage using the `gsutil rsync` command
0 commit comments