2. Set up a new project¶

In this section we will create and deploy a new project in the Control Panel,then replicate it locally.

2.1. Set up a project in the Cloud¶

In the Divio Cloud Control Panel, create a new project.

For the purposes of this tutorial, select the following options for yourproject (other options can be left on their default settings):

  • Python: Python 3.x
  • Project type: Django
    Once the project has been created, deploy the Test server, and then login tothe admin.

Note

By logging in, you will add your 3. Divio Cloud single-sign-on user to theproject’s database, and will be able to log in to the site locally withouthaving to add the new user to the database manually.

You’ll see a familiar Django admin for a new site.

2.2. Replicate it locally¶

Now let’s replicate this project locally.

List your cloud projects:

  1. divio project list

Identify the slug of the project you created in the previous step, and use thiswith the divio project setup command, for example:

  1. divio project setup my-tutorial-project

Note

You can find the exact command, and other useful commands, by selectingLocal Development from the project’s menu in the Control Panel.

Various processes will unfold, taking a few minutes (see The project build processfor a description of them).

cd into the newly-created project directory, where you will find a mostly-familiar Django project.

Start the project:

  1. divio project up

divio project up will also open the project in a web browser once it’s upand running.

Note

If you didn’t previously log in to the Cloud site before setting up theproject locally, you’ll need to add a user to the database before you canlog in. The Divio Cloud SSO system allows you todo this from the Django login page.

2.3. Control your project and see its console¶

As you proceed through this tutorial, you will inevitably encounter theoccasional issue. There are some commands that will help you when this happens.

You already know how to start your project with the divio command (divio
project up
, above). We’ll be introducing two new tools in this section:

  • docker
  • docker-compose
    This may seem a complex combination of commands, but through practice you willstart to understand when and how to use each one. Try them now to becomefamiliar with them.

2.3.1. Using docker¶

Check what Docker processes are running:

  1. docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME
  3. d6007edbaf32 demoproject_web "/tini -g -- pytho..." 17 minutes ago Up 8 seconds 0.0.0.0:8000->80/tcp demoproject_web_
  4. 27ff3e661027 postgres:9.4 "docker-entrypoint..." 6 days ago Up 8 seconds 5432/tcp demoproject_db_

Shut it down with divio project stop, the opposite of divio
project up
:

  1. divio project stop
  2. Stopping demoproject_web_1 ... done
  3. Stopping demoproject_db_1 ... done

Now docker ps should show that neither the web nor db containersare running (see the Docker command reference formore information using the Docker tool).

2.3.2. Using docker-compose¶

You can also start the project with the Docker Compose command, a command for working with projects (we willspecify that we want to bring up the web service described in the project’sThe docker-compose.yml file file, which also launches the dbservice):

  1. docker-compose up web
  2. Starting demoproject_db_1
  3. Performing system checks...
  4.  
  5. System check identified 1 issue (0 silenced).
  6. June 21, 2017 - 05:48:10
  7. Django version 1.8.18, using settings 'settings'
  8. Starting development server at http://0.0.0.0:80/
  9. Quit the server with CONTROL-C.

This is a good thing to do while developing, because it gives you the consoleoutput in your terminal, so you can see what’s going on.

When you stop it with CONTROL-C, the web service will stop, but thedb service will remain running. On the other hand, if you start theproject with docker-compose up, then when you stop it with CONTROL-C,both containers will stop.

Note

To make matters more complicated, under certain circumstances, the webcontainer may continue running after exiting from the docker-compose up
web
command. Invoking and exiting it again will usually stop it.

Now you can also run a command in a specific container, such as:

  1. docker-compose run --rm --service-ports web bash

which will open bash right in the web container. (—rm means removethe container when exiting; —service-ports tells it to expose the portslisted in the docker-compose.yml.) And you can run:

  1. python manage.py runserver 0.0.0.0:80

at the container’s bash prompt as another way of running the project andgetting the output.

Use CONTROL-C to stop the runserver and CONTROL-D to exit the bashshell and drop back into your own.

原文: http://docs.divio.com/en/latest/introduction/02-set-up.html