This file has all the requirements to run the application
Flask, pytest, and pytest-html
This file contains the flask application
There are 2 ways to run the application:
-
Open this file:
src/app.sh
-
using CLI type these commands
export message="Hello, World!"
python app.py
This file contains the test of the application
To run this file using CLI type this command:
There are 2 ways to test the application:
-
Open this file:
src/test.sh
-
using CLI type these commands
export message="Hello, World!"
python test_.py
To run Using pytest and pytest-html:
export message="Hello, World!"
pytest
Just make sure that you have installed pytest and pytest-html
This file contains that configurations of CircleCi
When running using pytest, the testing results will be printed in this directory:
test-reports/junit.html
test-reports/pytest_report.html
In CircleCI, they will be artifacts.
This is the code inside the file:
# Section 1
version: 2.1
# Section 3
executors:
the_python_executor:
docker:
- image: circleci/python:3.7.4
# Section 3
commands:
build_and_test_commands:
steps:
- checkout
- run:
name: Install Python dependencies
command: |
echo 'export PATH=~$PATH:~/.local/bin' >> $BASH_ENV && source $BASH_ENV
pip install --user -r requirements.txt
- run:
name: Run unit tests
command: |
pytest -rP --junitxml=test-reports/junit.xml --html=test-reports/pytest_report.html --self-contained-html --cov --cov-report=html:test-reports/pytest_cov_report
- store_test_results:
path: test-reports
- store_artifacts:
path: test-reports
test_env_variables_commands:
parameters:
p1:
type: string
default: "Passing a Parameter"
steps:
- run:
name: Testing Env Vars
command: |
echo '$message' # Prints "$message"
echo '${message}' # Prints "${message}"
echo "$message" # Prints "*************"
echo "${message}" # Prints "*************"
echo $message # Prints "*************"
echo ${message} # Prints "*************"
echo "<< parameters.p1 >>"
# Section 4
jobs:
build_and_test:
executor: the_python_executor
steps:
- build_and_test_commands
trying_env_vars:
executor: the_python_executor
parameters:
p1:
type: string
default: "Passing a Parameter"
steps:
- test_env_variables_commands:
p1: << parameters.p1 >>
# Section 5
orbs:
# Declare a dependency on the welcome-orb
welcome: circleci/welcome-orb@0.4.1
# Section 6
workflows:
build_test_on_push:
jobs:
- build_and_test
- trying_env_vars:
p1: "Changed the parameter"
- welcome/run
- welcome/run:
requires:
- build_and_test
build_test_on_cron:
triggers:
- schedule:
cron: "1 1 * * *"
filters:
branches:
only:
- master
jobs:
- build_and_test
- trying_env_vars:
p1: "Changed the parameter"
- welcome/run
- welcome/run:
requires:
- build_and_test
This is the version of CircleCI config file.
The latest version is 2.
So we will use this version.
Note: There is lots of difference between version 1 and 2
Executors are the environment that the application will run inside.
Here we will run the application inside a Docker environment and the
main image is python.
Commands are fixed steps that are repeated.
The commands are used in jobs.
Commands have parameters.
This is what will be executed in the workflow.
Predefined jobs
The final product of the circleci Configuration file.
The workflow has a cronjob.
It will run every day, to make sure that everything is working.
workflows:
build_test_on_push:
.
.
.
build_test_on_cron:
triggers:
- schedule:
cron: "1 1 1 * *"
We have here 2 workflows:
- build_test_on_push:
- This runs when there are chages pushed to the master branch
- build_test_on_cron:
- This is a cron job
- It runs monthly in the first day of the month, at 1 AM, and 1 Minute