docker application

Can you please help me on below assignment … I would be thankful to you…

Assignment

Your task is to accomplish the following:

  • Deploy the sample python applications to a cluster of nodes using a container orchestration framework
  • Application A should be publicly accessible over HTTPS
  • Application B should not be accessible via the public internet
  • Please show how you would auto-scale the number of nodes and containers as the number of requests increases.
  • Bonus work : Use Nginx to host it with HTTP and then :
  1. Enable HTTPS and redirect HTTP to HTTPS

  2. Create a self-signed certificate or use LetsEncrypt, also document the commands you are using to create the certificate

For delivery of this assignment, we’d like to see:

  • A Dockerfile for each application
  • Framework for deploying containers to a group of nodes
  • Document how you will use continuous delivery to ship to a production environment
  • Scripts and/or docs involved with automatically scaling the application and nodes horizontally based on requests
  • Nginx configuration file (optional, bonus task)

Getting Started in Local Development

Please create and source your virtualenv before beginning.

Running the apps locally:

pip install -r requirements.txt
sqlite3 database.db < schema.sql
python app_a.py
python app_b.py

Making a request

curl -X POST -H 'Authorization: mytoken' http://127.0.0.1:5000/jobs

Simulating a lot of requests

ab -m POST -H "Authorization: mytoken" -n 500 -c 4 http://127.0.0.1:5000/jobs


----------------------------------------------------------------------------------------------------------------------------
  1. =============================================
  2. cat requirements.txt
  3. flask>=0.12.3
  4. requests>=2.20.0
  5. ============================================
  6. cat database.db
  7. P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)▒▒ableusersusersCREATE TABLE users (
  8. id integer primary key autoincrement,
  9. username text not null,
  10. password text not null,
  11. ====================================================================
  12. cat schema.sql
  13. CREATE TABLE users (
  14. id integer primary key autoincrement,
  15. username text not null,
  16. password text not null,
  17. token text not null);
  • INSERT INTO users (username, password, token) VALUES (‘density’, ‘password123’, ‘mytoken’);
  • ===================================================================
  1. cat app_a.py
  2. from flask import Flask, request
  3. import requests
  4. application = Flask(name)
  • @application.route(‘/hello’)
  1. def hello():
  2. return ‘Hello there’
  • @application.route(‘/jobs’, methods=[‘POST’])
  1. def jobs():
  2. token = request.headers[‘Authorization’]
  3. data = {“token”: token}
  4. result = requests.post(‘http://0.0.0.0:5001/auth’, data=data).content
  5. if result == “density”:
  6. return ‘Jobs:\nTitle: Devops\nDescription: Awesome\n’
  7. else:
  8. return ‘fail’
  • if name == “main”:
  1. application.run(host=‘0.0.0.0’, port=5000)
  • ======================================================================
  1. cat app_b.py
  2. from flask import Flask, request
  3. import sqlite3 as sql
  4. application = Flask(name)
  • @application.route(‘/auth’, methods=[‘POST’])
  1. def auth():
  2. try:
  3. token = request.form[‘token’]
  4. con = sql.connect(“database.db”)
  5. cur = con.cursor()
  6. cur.execute(
  7. “SELECT username from users where token = (?) LIMIT 1”,
  8. (token, ))
  9. username = cur.fetchone()[0]
  10. con.close()
  11. return username
  12. except:
  13. return ‘fail’
  • if name == “main”:
  1. application.run(host=‘0.0.0.0’, port=5001)
  2. ===========================================================================