|
3 | 3 | [](https://www.gnu.org/licenses/gpl-3.0) |
4 | 4 |  |
5 | 5 |
|
6 | | -Simple example of a pipeline on Docker to test your python code. |
| 6 | +Simple Docker pipeline to test your python code. |
7 | 7 |
|
8 | | -## Pipeline on a container |
| 8 | +## About |
9 | 9 |
|
10 | 10 | Although several pipeline solutions exist, they are too complex for small projects. With this solution you just need a Dockerfile. |
11 | 11 |
|
12 | | -### Implementation |
| 12 | +## Features |
13 | 13 |
|
14 | 14 | In this repo i've add a very basic python project with only four elements: a requirements file, a Dockerfile, a pytest.ini file and a simple python test that always pass. |
15 | 15 |
|
16 | | -#### Requirements file 📃 |
17 | | - |
18 | | -The requirements file lists all the project dependencies. This allows the pip (Python package manager) to download the correct versions of wich dependency. [See the dependencies tutorial to more details.](pipeline/dependencies.md) |
19 | | - |
20 | | -#### Sample test ✅ |
21 | | - |
22 | | -Our project does not have a software but we need at least a single test to prove that our test library is working, so we add a simple function with the name test-pass.py. |
23 | | - |
24 | | -When the PyTest framework execute it will find the test by the name test\*.py |
25 | | - |
26 | | -#### Pytest configuration 💻 |
27 | | - |
28 | | -The PyTest configuration is used to define the root folder for the tests and to add options to PyTest. In this example it is used to disable a warning message when used with JUnit. |
29 | | - |
30 | | -#### Dockerfile 🐳 |
31 | | - |
32 | | -The Dockerfile uses the multistage build feature to create the pipeline. Each stage can be executed by a diferent image and only the output artifacts will be reused. |
33 | | - |
34 | | -## The pipeline stages |
35 | | - |
36 | 16 | You can put several stages to your pipeline, but the most common stages are: |
37 | 17 |
|
38 | 18 | | 1 | 2 | 3 | 4 | 5 | 6 | |
39 | 19 | | ----- | ---- | ---- | -------- | ------ | --- | |
40 | 20 | | Build | Test | Lint | Analisys | Report | Tag | |
41 | 21 |
|
42 | | -### Build |
| 22 | +## The pipeline stages |
| 23 | + |
| 24 | +[Build](pipeline/dependencies.md): Downloads and build dependencies. |
| 25 | + |
| 26 | +[Test](pipeline/tests.md): Executes all tests found. |
| 27 | + |
| 28 | +[Lint](pipeline/lint.md): Checks code style and format. |
| 29 | + |
| 30 | +[Analisys](pipeline/static-analisys.md): Checks for bad code practicies. |
43 | 31 |
|
44 | | -Python does not have a build stage but has a pre-execution stage of build the dependency tree by download packages and resolving sub dependencies. |
| 32 | +[Report](pipeline/reports.md): Exports the results to archiving. |
45 | 33 |
|
46 | | -[Access the "Building the Dependency Tree" tutorial](pipeline/dependencies.md) |
| 34 | +[Tag](pipeline/tagging.md): Adds a unique identifier to the version. |
47 | 35 |
|
48 | | -### Test |
| 36 | +## Installation |
49 | 37 |
|
50 | | -After gather all the packages now we can test our application. The most common type of tests is the unit test but to achieve a good code quality we should add other types of test as well. |
| 38 | +1. Clone or download this repository. |
51 | 39 |
|
52 | | -[Access the "Testing with PyTest" tutorial](pipeline/tests.md) |
| 40 | +2. Move your code to this new structure or vice versa. |
53 | 41 |
|
54 | | -### Lint |
| 42 | +3. Make sure the `Dockerfile` is on project root folder. |
55 | 43 |
|
56 | | -When the tests are passing is time to check the code checking if guidelines for the code style are being followed. A consistent code style helps with readability and mantainece. |
| 44 | +4. Update the requiments with your dependencies or create your list of requirements. [See the dependencies tutorial to more details.](pipeline/dependencies.md) |
57 | 45 |
|
58 | | -- [Access the Lint tutorial](pipeline/lint.md) |
| 46 | +5. Make sure the name patterns on `pytest.ini` |
59 | 47 |
|
60 | | -### Analisys |
| 48 | +6. Make sure you have at least one passing test (there's one in test-pass.py) |
61 | 49 |
|
62 | | -With a consistent code base its easier to find code patterns that could lead to errors or make your code prone to atacks. Another advantage is the complexity management. |
| 50 | +7. In `Dockerfile` rename the `src` folder following your project organizaziton. |
63 | 51 |
|
64 | | -- [Access the Static Analisys tutorial](pipeline/static-analisys.md) |
| 52 | +## Usage |
65 | 53 |
|
66 | | -### Report |
| 54 | +Execute the docker build command |
67 | 55 |
|
68 | | -With all quality checks done it is necessary to comunicate the results. Its possible to send a message to external tools notifying the complete result. |
| 56 | +```bash |
| 57 | +docker build -t your-docker-user/projetc-name:tag . |
| 58 | +``` |
69 | 59 |
|
70 | | -- [Access the Report tutorial](pipeline/reports.md) |
| 60 | +If every step works correctly the command `docker images` is going to list your newly created image. |
71 | 61 |
|
72 | | -### Tag |
| 62 | +If something goes wrong youll be promptly warned. |
73 | 63 |
|
74 | | -Now that all the steps complete we can define that this build is production ready and should receive a tag with its version number using some of the common tag practicies used world-wide. |
| 64 | +## License |
75 | 65 |
|
76 | | -- [Access the Tag tutorial](pipeline/tagging.md) |
| 66 | +[GNU General Public License v3.0](LICENSE) |
0 commit comments