Skip to content

digideskio/homepage-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Homepage

This is my homepage/blog.

Development

  1. Create a virtualenv

    $ mkvirtualenv homepage
  2. Install the development requirements

    $ python setup.py develop
  3. Run initial migrations

    $ DEBUG=true homepage migrate
  4. Create an "admin" superuser with password "admin"

    $ DEBUG=true homepage createsuperuser
  5. Run the development server in debug mode.

    $ DEBUG=true python manage.py runserver

    You can also run the production webserver in debug mode but it won't reload when code is updated.

    $ DEBUG=true homepage start

Deploy Staging or Production

You can deploy staging, and production environments to Google Cloud Platform. There are a number of scripts for deploying to Google Container Engine.

Create and Setup a Cloud Platform Project

  1. Install the Google Cloud Platform SDK.

  2. Create a project in the Google Cloud Platform console.

  3. Authenticate the Google Cloud Platform SDK:

    $ gcloud auth login
  4. Set the id of your new project:

    $ gcloud config set project <PROJECT>
  5. Set the zone you want the app to run in:

    $ gcloud config set compute/zone asia-east1-b
  6. Create a Container Engine Cluster. You may need to specify other options, such as the size of the cluster, VM type etc.

    $ gcloud container clusters create homepage-cluster

Create the Environment

  1. Create namespaces for staging and production.

    $ kubectl create -f deploy/homepage-staging-ns.yaml
    $ kubectl create -f deploy/homepage-prod-ns.yaml
  2. Create secrets for each environment. The secrets file should something like the file below. Each value should be encoded in base64. See the secrets doc for more info.

    apiVersion: v1
    kind: Secret
    metadata:
      name: homepage-secret
    data:
      secret-key: ...
      disqus-api-key: ...
      disqus-website-shortname: ...
      db-user: ...
      db-password: ...
  3. Deploy the secrets to the cluster.

    $ kubectl create -f staging-secrets.yaml --namespace=homepage-staging
    $ kubectl create -f webfront-secrets-staging.yaml --namespace=homepage-staging
    $ kubectl create -f prod-secrets.yaml --namespace=homepage-prod
    $ kubectl create -f webfront-secrets-prod.yaml --namespace=homepage-prod

Build the Docker Images

There is a handy build script in the bin directory you can run to build and push the app image.

$ ./bin/build.sh

This script will build a Python package for the app, build a Docker image, and push it to Google Container Registry.

Deploy the Application

  1. Deploy the database.

    $ kubectl create -f deploy/mysql/mysql.yaml --namespace=<namespace> 
    $ kubectl create -f deploy/mysql/mysql-service.yaml --namespace=<namespace> 
  2. Deploy the homepage app.

    $ kubectl create -f deploy/homepage-rc.yaml --namespace=<namespace>
    $ kubectl create -f deploy/homepage-service.yaml --namespace=<namespace>

Creating the MySQL database

You can create the MySQL database by running the "CREATE DATABASE" query inside the mysql database container after it's running.

$ kubectl exec mysql --namespace=<namespace> -- \
    bash -c "echo 'CREATE DATABASE IF NOT EXISTS homepage CHARACTER SET utf8;' \
    | mysql -u root --password=yourpassword"

Running Migrations

Migrations are run in staging or production by running a pod in Container Engine.

$ kubectl create -f deploy/homepage-migrate-pod.yaml --namespace=<namespace>

The pod will be created with the name "homepage-migrate". Since it exits normally, in order to preserve info and logs, Container Engine keeps the pod around. In order to run the migration again, you need clean up by deleting the previous pod.

$ kubectl delete pod homepage-migrate --namespace=<namespace>

Creating Superusers

Creating superusers is done by running a pod in Container Engine.

$ kubectl create -f deploy/homepage-createsuperuser-pod.yaml --namespace=<namespace>

This will create a superuser with the username and password "admin". You will need to login and update the password of this user immediately after creation.

About

My homepage/blog

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 53.4%
  • JavaScript 31.1%
  • Python 7.3%
  • CSS 5.8%
  • Go 1.6%
  • Nginx 0.4%
  • Other 0.4%