Skip to content

Commit c0aee3e

Browse files
committed
Update Python demo projects
1 parent 60c0264 commit c0aee3e

File tree

2 files changed

+45
-134
lines changed

2 files changed

+45
-134
lines changed

jekyll/_cci2/language-python.md

Lines changed: 43 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,36 @@ categories: [language-guides]
77
order: 6
88
---
99

10-
## Overview
10+
## New to CircleCI 2.0?
1111

12-
This guide will help you get started with a Python project on CircleCI. If you’re in a rush, just copy the sample configuration below into `.circleci/config.yml` in your project’s root directory and start building.
12+
If you're new to CircleCI 2.0, we recommend reading our [Project Walkthrough]({{ site.baseurl }}/2.0/project-walkthrough/) for a detailed explanation of our configuration using Python and Flask as an example.
1313

14-
Otherwise, we recommend reading our [walkthrough](#config-walkthrough) for a detailed explanation of our configuration.
14+
## Quickstart: demo Python Django reference project
1515

16-
## Sample Configuration
16+
We maintain a reference Python Django project to show how to build Django on CircleCI 2.0:
1717

18-
{% raw %}
19-
```YAML
20-
version: 2
21-
jobs:
22-
build:
23-
docker:
24-
- image: python:3.5
25-
environment:
26-
FLASK_CONFIG: testing
27-
DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
28-
- image: postgres:9.5.5
29-
environment:
30-
POSTGRES_USER: ubuntu
31-
POSTGRES_DB: circle_test
32-
POSTGRES_PASSWORD: ""
33-
working_directory: /home/ubuntu/cci-demo-flask
34-
steps:
35-
- checkout
36-
- run:
37-
name: Install Yarn
38-
command: |
39-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68576280 86E50310
40-
echo "deb http://deb.nodesource.com/node_7.x jessie main" | tee /etc/apt/sources.list.d/nodesource.list
41-
echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
42-
apt-get update -qq
43-
apt-get install -y -qq nodejs yarn
44-
- restore_cache:
45-
key: projectname-{{ .Branch }}-{{ checksum "yarn.lock" }}
46-
- run: yarn && pip install -r requirements.txt
47-
- save_cache:
48-
key: projectname-{{ .Branch }}-{{ checksum "yarn.lock" }}
49-
paths:
50-
- "/home/ubuntu/.yarn-cache"
51-
- run: python manage.py test --coverage
52-
- store_artifacts:
53-
path: test-reports/coverage
54-
destination: reports
55-
- store_test_results:
56-
path: "test-reports/"
57-
```
58-
{% endraw %}
18+
- <a href="https://github.com/CircleCI-Public/circleci-demo-python-django"> target="_blank">Demo Python Django Project on GitHub</a>
19+
- <a href="https://circleci.com/gh/CircleCI-Public/circleci-demo-python-django"> target="_blank">Demo Python Django Project building on CircleCI</a>
5920

60-
## Get the Code
21+
In the project you will find a commented CircleCI configuration file <a href="https://github.com/CircleCI-Public/circleci-demo-python-django/blob/master/.circleci/config.yml" target="_blank">`.circleci/config.yml`</a>. This file shows best practice for using CircleCI 2.0 with Python projects.
6122

62-
The configuration above is from a demo Python/flask app, which you can access at [https://github.com/circleci/cci-demo-flask](https://github.com/circleci/cci-demo-flask).
23+
## Alternative: Python Flask demo reference project
6324

64-
Fork the project and download it to your machine. Go to the [Add Projects](https://circleci.com/add-projects) page in CircleCI and click the Build Project button next to your project. Finally, delete everything in `.circleci/config.yml`.
25+
The [Project Walkthrough]({{ site.baseurl }}/2.0/project-walkthrough/) uses a Flask application: <https://github.com/CircleCI-Public/cci-demo-python-flask>
6526

66-
Now we’re ready to build a `config.yml` from scratch.
27+
## Pre-built CircleCI Docker images
6728

29+
We recommend using a CircleCI pre-built image that comes pre-installed with tools that are useful in a CI environment. You can select the Python version you need from Docker Hub: <https://hub.docker.com/r/circleci/python/>. The demo project uses an official CircleCI image.
30+
31+
Database images for use as a secondary 'service' container are also available.
32+
33+
## Build the demo Django project yourself
34+
35+
A good way to start using CircleCI is to build a project yourself. Here's how to build the demo project with your own account:
36+
37+
1. Fork the project on GitHub to your own account
38+
2. Go to the [Add Projects](https://circleci.com/add-projects) page in CircleCI and click the Build Project button next to the project you just forked
39+
3. To make changes you can edit the `.circleci/config.yml` file and make a commit. When you push a commit to GitHub, CircleCI will build and test the project.
6840
---
6941

7042
## Config Walkthrough
@@ -77,110 +49,49 @@ version: 2
7749
7850
Next, we have a `jobs` key. Each job represents a phase in your Build-Test-Deploy (BTD) process. Our sample app only needs a `build` job, so everything else is going to live under that key.
7951

80-
We also need to specify container images for this build in `docker`.
81-
82-
We'll need to tell the Flask app to run in `testing` mode by setting it in `environment`, as well as where to find the database (DB). This is a special local URL linked to an additional Docker container.
52+
We need to specify a working directory container images for this build in `docker` section:
8353

8454
```YAML
8555
...
8656
jobs:
8757
build:
58+
working_directory: ~/circleci-demo-python-django
8859
docker:
89-
- image: python:3.5
60+
- image: circleci/python:3.6.1
61+
- image: circleci/postgres:9.6.2
9062
environment:
91-
FLASK_CONFIG: testing
92-
DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
93-
```
94-
95-
We'll also create a container for PostgreSQL, along with 3 environment variables for initializing the database.
96-
97-
```YAML
98-
...
99-
- image: postgres:9.5.5
100-
environment:
101-
POSTGRES_USER: ubuntu
63+
POSTGRES_USER: root
10264
POSTGRES_DB: circle_test
103-
POSTGRES_PASSWORD: ""
104-
```
105-
106-
In each job, we specify a `working_directory`. In this sample config, we’ll name it after the project in our home directory.
107-
108-
```YAML
109-
...
110-
working_directory: /home/ubuntu/cci-demo-flask
11165
```
11266

113-
Now we need to add several `steps` within the `build` job.
67+
Now we need to add several `steps` within the `build` job:
11468

115-
You could install NPM, but we’re going to use Yarn for reasons that are outside the scope of this document.
11669

11770
```YAML
118-
...
11971
steps:
12072
- checkout
73+
- restore_cache:
74+
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
12175
- run:
122-
name: Install Yarn
12376
command: |
124-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68576280 86E50310
125-
echo "deb http://deb.nodesource.com/node_7.x jessie main" | tee /etc/apt/sources.list.d/nodesource.list
126-
echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
127-
apt-get update -qq
128-
apt-get install -y -qq nodejs yarn
129-
```
130-
131-
Let's restore the Yarn package cache if it's available.
132-
133-
{% raw %}
134-
```YAML
135-
...
136-
- restore_cache:
137-
key: projectname-{{ .Branch }}-{{ checksum "yarn.lock" }}
138-
```
139-
{% endraw %}
140-
141-
Install both Yarn and Python dependencies.
142-
143-
```YAML
144-
...
145-
- run: yarn && pip install -r requirements.txt
146-
```
147-
148-
Specify where to save that Yarn cache.
149-
150-
{% raw %}
151-
```YAML
152-
...
77+
python3 -m venv venv
78+
. venv/bin/activate
79+
pip install -r requirements.txt
15380
- save_cache:
154-
key: projectname-{{ .Branch }}-{{ checksum "yarn.lock" }}
81+
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
15582
paths:
156-
- "/home/ubuntu/.yarn-cache"
157-
```
158-
{% endraw %}
159-
160-
Run our tests.
161-
162-
```YAML
163-
...
164-
- run: python manage.py test --coverage
165-
```
166-
167-
Store test results as an artifact.
168-
169-
```YAML
170-
...
83+
- "venv"
84+
- run:
85+
command: |
86+
. venv/bin/activate
87+
python manage.py test
17188
- store_artifacts:
172-
path: test-reports/coverage
173-
destination: reports
89+
path: test-reports/
90+
destination: tr1
17491
```
17592

176-
Finally, let's specify where those test results are actually located.
177-
178-
```YAML
179-
...
180-
- store_test_results:
181-
path: "test-reports/"
182-
```
93+
You can learn more about each of these steps in our [configuration reference]({{ site.baseurl }}/2.0/configuration-reference/)
18394

184-
Nice! You just set up CircleCI for a Flask app. Nice! Check out our [project’s build page](https://circleci.com/gh/circleci/cci-demo-flask).
95+
Success! You just set up CircleCI 2.0 for a Python Django app. Check out our [project’s build page](https://circleci.com/gh/CircleCI-Public/circleci-demo-python-django) to see how this looks when building on CircleCI.
18596

186-
If you have any questions, head over to our [community forum](https://discuss.circleci.com/) for support from us and other users.
97+
If you have any questions about the specifics of testing your Python application, head over to our [community forum](https://discuss.circleci.com/) for support from us and other users.

jekyll/_cci2/project-walkthrough.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CircleCI is a very flexible platform so you should be able to adapt this tutoria
2424

2525
![Circulate demo app screenshot]({{ site.baseurl }}/assets/img/docs/walkthrough0.png)
2626

27-
The source for the application is here: [cci-demo-walkthrough](https://github.com/circleci/cci-demo-walkthrough).
27+
The source for the application is here: [cci-demo-python-flask](https://github.com/CircleCI-Public/cci-demo-python-flask).
2828

2929
### The Stack
3030

@@ -41,7 +41,7 @@ Finally, we'll deploy the application to Heroku and discuss other deployment opt
4141
To use CircleCI, your code must be available on GitHub or Bitbucket, in either a private or public repository. We'll be assuming GitHub for this walkthrough, but the same flow applies to Bitbucket as well.
4242

4343
<div class="alert alert-info" role="alert">
44-
<strong>Tip:</strong> If you're following along and want to use the code, you should fork and clone the <a class="alert-link" href="https://github.com/circleci/cci-demo-walkthrough">cci-demo-walkthrough</a> project. On your local machine, delete the <code>.circleci</code> directory and make a commit. You now have a clean project ready to start configuring for use with CircleCI.
44+
<strong>Tip:</strong> If you're following along and want to use the code, you should fork and clone the <a class="alert-link" href="https://github.com/CircleCI-Public/cci-demo-python-flask">cci-demo-walkthrough</a> project. On your local machine, delete the <code>.circleci</code> directory and make a commit. You now have a clean project ready to start configuring for use with CircleCI.
4545
</div>
4646

4747
## Create CircleCI config file

0 commit comments

Comments
 (0)