Coder Social home page Coder Social logo

squidboylan / dreamcompute-hello-world Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryanpetrello/dreamcompute-hello-world

0.0 2.0 0.0 9 KB

Deploy an example Python application on DreamHost Compute with Ansible

Python 10.10% Nginx 16.08% Shell 73.82%

dreamcompute-hello-world's Introduction

Deploying a Simple Web Application on DreamCompute

Introduction

In this article, you'll learn to deploy a simple web application on an OpenStack public cloud (DreamCompute) using the popular automation tool, Ansible. To get started:

  • Sign up for a DreamCompute account (DreamHost offers a free trial period)

  • Log in to the DreamCompute Dashboard and create an SSH key (filling out the form will download a PEM keyfile you'll use to authenticate to your server). Remember the name of the key that you create - you'll need that value later.

  • Install a recent version of Python (2.7+)

  • Install the helloworld Python package in this repository, shade, and ansible:

    $ git clone https://github.com/ryanpetrello/dreamcompute-hello-world.git hello-world

    $ cd hello-world && pip install -e . shade ansible

Python and WSGI

We'll be deploying a very simple Python WSGI application that responds to all HTTP requests with Hello, World! WSGI is a Python protocol which allows a web server to interface with a Python callable (or function) to handle each request. Our function looks like this:

def application(environ, start_response):
      data = "Hello, World!\n"
      start_response("200 OK", [
          ("Content-Type", "text/plain"),
          ("Content-Length", str(len(data)))
      ])
      return data

...but you could replace this Python code and the web server with your own written in PHP, Ruby, Javascript, or any other language!

Deploying with Ansible

We'll use Ansible to create a repeatable "playbook" of commands to set up the Hello World application on a DreamCompute server. These commands include:

  • Launching a server in DreamCompute and assigning a public IP address to it
  • Installing a web server (we'll use http://gunicorn.org)
  • Installing our example Python application and configuring it to handle requests

In order for Ansible to run DreamCompute API calls on your behalf, you'll need to download a small shell script that sets up your API credentials. Do so by visiting API Access in the OpenStack Dashboard. After the shell script downloads, open your computer's command line and run the following (substituting the actual location of your downloaded file).

$ source /path/to/downloaded/file/dhc123456789-openrc.sh

You'll be prompted for a password - it's the one you use to log in to the DreamCompute Dashboard.

At this point you should be ready to deploy your application. Do so by running the following commands:

$ chmod 600 /path/to/keyname.pem
$ ansible-playbook -vvvv -i "localhost," playbooks/deploy.yml --extra-vars "key_name=keyname private_key=/path/to/keyname.pem"

You'll need to substitute the keyname key name value for the actual name you chose earlier, and you'll also need to replace /path/to/keyname.pem with the actual path to the PEM file you downloaded.

If all is well, you'll be greeted with an instructional message:

Visit http://1.2.3.4/ in your browser!

Example Server Architecture

If you ssh into your newly created server:

$ ssh -i /path/to/keyname.pem [email protected]

...you'll find a variety of processes running in the following configuration:

HTTP Request ──> <Production/Proxy Server>, nginx (1.2.3.4:80)
                  │
                  │   <supervisord> (monitors and keeps gunicorn processes running)
                  ├── <WSGI Server> gunicorn Instance (/tmp/gunicorn.sock)
                  ├── <WSGI Server> gunicorn Instance (/tmp/gunicorn.sock)
                  ├── <WSGI Server> gunicorn Instance (/tmp/gunicorn.sock)
                  ├── <WSGI Server> gunicorn Instance (/tmp/gunicorn.sock)

supervisord is installed and is used to manage multiple gunicorn worker processes, each of which is bound to a Unix domain socket (though you could also configure them to bind to a TCP port). nginx listens on port 80 and balances incoming HTTP requests across the gunicorn workers processes.

dreamcompute-hello-world's People

Contributors

ryanpetrello avatar squidboylan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.