Implement flask-ops task - #2
Conversation
|
Hi @SmirnovsIgor , the code changes you've made, as well as the pipeline setup look pretty good. Especially the python work you did is excellent, great work! However, as a devops/infra engineer, a large part of the job is clearly communicating with others.
For these reasons, we need everything we build to be very clearly explained. Following this theme, I have two requests:
Of course if you have any questions about any this, we can discuss in this PR here on GitHub. |
Definitely, there must be documentation for this pull request. That's a good point. Now I'm at the stage of writing documentation, but I have one or two questions for you.
|
|
Hello @SmirnovsIgor, No style guides required from our side. Please use your best understanding of DevOps practices for writing documentation/communicate for when you make changes to a developer's code, and have to explain the infrastructure decisions to other developers/team members. For some inspiration, here's some documentation I wrote for a test project a few years ago: https://github.com/DragonStuff/saltstack-test/blob/master/index.html.md |
|
Hello @DragonStuff, I've wrote the documentation for this PR. Could you please check it out? |
Introduction.
In this pull request I've implemented CI/CD pipeline for the flask-ops task using CircleCI and Heroku.
This documentation outlines the steps I took to deploy, and automate the deployment of, the flask-ops application.
The beginning of this documentation outlines the steps I took to understand the project and the environment and architectural decisions I've made.
Understanding of the project. Architectural decisions.
My first step was to start this application and to see how it works on my local machine. Then I started reading the code, thinking in parallel about the environment and pipeline steps, which I'd like to implement. First of all, I decided to change the code based on the PEP8 knowledge. Immediately I came across a secret variable and hid it to prevent security issues, e.g. if this app will be used in generating some tokens like csrf-token or others. Then I analyzed that there were no unit/integration tests. As I know, one of the most important DevOps methodology's goals are:
Due to this goals, I have made a decision of writing some unit and integration tests for this app, because, in my opinion, the main thing that can show that the product works well is testing.
Unit tests.
The main logic functions I've highlighted were
encrypt_string()andgenerate()func's. I hadn't found the solution of testing the second one, so I decided to write unit tests for sha256 encrypting function.Integration tests.
The main goals of these tests are to see if the app is working, i.e, it generates unique tokens and the server response is 200 OK.
While writing tests, I faced the problem of non reusable code. The
generate()func was tied to aSECRET_SALT_KEYvariable and could not be used in other parts of the program, e.g. in creating app mock object for tests.Also I've edited the
start.shscript file based on the work of Heroku itself. Heroku generates PORT env variable on which app will be running on the prod.So I've decided to make this app running on 5000 by default and on PORT env var if it is exported. This allows us to enter the port on which we want to run this application.
In the next section I'll try to describe my thoughts on the pipeline I've implemented.
Pipeline steps.
Installation.
Flask-ops requires Python v3.6+, pip v20.0.0+, Docker
Clone the repository.
Install the dependencies and start the server.
Server will be available at 0.0.0.0:5000 by default
Also before launching the script you can also export the PORT var, on which you'd like to start the server.
Tests.
Unit tests.
To run unit tests run following command
Integration tests.
To run integration tests run following command
Deployment.
Make sure you've installed requirements.txt
Export all necessary env variables before launching the script below.
Monitoring and maintenance
Heroku provides its own observability and monitoring tools. You can access them logging in the Heroku Dashboard.