ianlewis / homepage

My homepage/blog
MIT License
4 stars 3 forks source link

Homepage

This is my homepage/blog.

Prerequisites

  1. Python 2.7
  2. MySQL Client

    You need to have a mysql client installed. Usually that means installing the right package.

    $ apt-get install -y libmysqlclient-dev

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 the App

This application is deployed on Google Container Engine, however, any Kubernetes cluster would do.

Create the Environment

  1. Create secrets for the homepage app. The secrets file should something like the file below. Each value should be encoded in base64. See the secrets doc for more info. Save the file to homepage-secrets.yaml.

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

    $ kubectl apply -f homepage-secrets.yaml

Build the Docker Images

Building a Docker image should be straight-forward. Give the image a tag that matches the repository url you want and give it a version label.

$ docker build -t gcr.io/ianlewis-org/homepage:<VERSION> .

Deploy the Application

This app depends on MySQL so you need to deploy that app first.

Deploy the homepage app.

$ kustomize build kubernetes/staging | kubectl apply -f -

Running Migrations

Migrations are run by running a Job using the Kubernetes Jobs API.

$ kubectl apply -f kubernetes/extras/migrate.yaml

Creating Superusers

Creating superusers is done by running a Job using the Kubernetes Jobs API.

$ kubectl apply -f kubernetes/extras/createsuperuser-job.yaml

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.