Add week 3 materials

This commit is contained in:
2026-09-24 21:25:39 +03:00
parent 25fd4ed555
commit 0a1eb51bf8
18 changed files with 743 additions and 0 deletions
@@ -0,0 +1,30 @@
version: '3'
services:
server1:
build:
context: ./kittens
environment:
APP_VERSION: 'v1'
BIND_PORT: 5001
ports:
- 9001:5001
server2:
build:
context: ./kittens
environment:
APP_VERSION: 'v2'
BIND_PORT: 5002
ports:
- 9002:5002
proxy:
image: nginx
ports:
- 8080:80
- 8081:10000
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./static:/static
restart: unless-stopped
@@ -0,0 +1,3 @@
docker-compose.yaml
Dockerfile
__pycache__
@@ -0,0 +1,12 @@
FROM python:3.11.5-slim-bullseye
WORKDIR /application
# Copy the requirements file and download the dependencies.
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
# Copy other data.
COPY . .
CMD [ "python3", "app.py"]
@@ -0,0 +1,45 @@
from flask import Flask, render_template, request
import logging
import os
import requests
app = Flask(__name__)
app.logger.setLevel(logging.INFO)
APP_VERSION = os.getenv('APP_VERSION')
BIND_HOST = os.getenv('BIND_HOST') or '0.0.0.0'
BIND_PORT = os.getenv('BIND_PORT') or '8000'
@app.before_request
def log_request():
app.logger.info(
'method=%s path=%s host=%s remote_addr=%s',
request.method, request.path, request.host, request.remote_addr,
)
@app.route('/')
def home():
return f'Hello from app {APP_VERSION}'
@app.route('/kittens')
def kittens():
# Get a URL to a random kitten photo.
response = requests.get('https://api.thecatapi.com/v1/images/search?api_')
try:
# Response structure is as follows:
# [{"id":"bL3lrUi1A","url":"ex.com/bL3lrUi1A.jpg","width":1280,"height":720}]
data = response.json()
kitten_url = data[0]['url']
return render_template('index.html', kitten_url=kitten_url)
except Exception as e:
return f'Failed to fetch a kitten image :(\n {e}'
if __name__ == '__main__':
app.run(host=BIND_HOST, port=BIND_PORT)
@@ -0,0 +1,2 @@
Flask==2.3.3
requests==2.28.2
@@ -0,0 +1,8 @@
<html>
<head>
<title>DistSys kittens</title>
</head>
<body>
<img src="{{ kitten_url }}">
</body>
</html>
@@ -0,0 +1,49 @@
events {}
http {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
server {
listen 80;
server_name distsys.baliuk.me;
location /kittens {
proxy_pass http://backends;
add_header X-Upstream $upstream_addr;
}
location = / {
proxy_pass http://backends;
add_header X-Upstream $upstream_addr;
}
location /search/ {
rewrite ^/search/(.*)$ https://google.com/search?q=$1 redirect;
}
location = /const {
add_header Content-Type text/plain;
return 200 "Any preset text!";
}
}
upstream backends {
server server1:5001;
server server2:5002;
}
server {
listen 10000;
autoindex on; # enable directory listing output
autoindex_exact_size off; # output file sizes rounded to kilobytes, megabytes, and gigabytes
autoindex_localtime on; # output local times in the directory
location / {
root /static;
}
}
}
@@ -0,0 +1 @@
Hello, distributed systems!
@@ -0,0 +1,127 @@
<svg xmlns="http://www.w3.org/2000/svg" style="background-color:#fff" viewBox="-.5 -.5 310 191">
<rect width="100%" height="100%" fill="#FFF"/>
<rect width="297" height="87" x="7" y="58" fill="#e6e6e6" pointer-events="all" rx="6.96" ry="6.96"/>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M32.62 58.64 30.9 30" pointer-events="stroke"/>
<path d="m32.93 63.88-2.75-6.84 2.44 1.6 2.22-1.88Z" pointer-events="all"/>
</g>
<path fill="none" d="M0 0h60v30H0z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:58px;height:1px;padding-top:15px;margin-left:1px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">
<div style="font-size:16px">Method</div>
</div>
</div>
</div>
</foreignObject>
<text x="30" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Method</text>
</switch>
<path fill="none" d="M56 0h60v30H56z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:58px;height:1px;padding-top:15px;margin-left:57px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">Path</div>
</div>
</div>
</foreignObject>
<text x="86" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Path</text>
</switch>
<path fill="none" d="M113 0h122v30H113z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:120px;height:1px;padding-top:15px;margin-left:114px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">Protocol version</div>
</div>
</div>
</foreignObject>
<text x="174" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Protocol version</text>
</switch>
<path fill="none" d="M127 161h60v30h-60z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:58px;height:1px;padding-top:176px;margin-left:128px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">
<div style="font-size:16px">Headers</div>
</div>
</div>
</div>
</foreignObject>
<text x="157" y="181" font-family="Helvetica" font-size="16" text-anchor="middle">Headers</text>
</switch>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M79.45 58.2 83.73 30" pointer-events="stroke"/>
<path d="m78.67 63.39-1.26-7.27 2.04 2.08 2.57-1.38Z" pointer-events="all"/>
</g>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M153.71 58.24 166.96 30" pointer-events="stroke"/>
<path d="m151.48 62.99.86-7.33 1.37 2.58 2.85-.6Z" pointer-events="all"/>
</g>
<rect width="36" height="21" x="15" y="65" fill="#f2fffc" pointer-events="all" rx="1.68" ry="1.68"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe flex-start;width:1px;height:1px;padding-top:76px;margin-left:19px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:left">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">
<p style="line-height:100%">
<font color="#509ad4" style="font-size:16px">GET</font>
</p>
</div>
</div>
</div>
</foreignObject>
<text x="19" y="80" fill="#333" font-family="Monospace" font-size="16">GET</text>
</switch>
<rect width="17" height="21" x="70" y="64.5" fill="#f5f5ff" pointer-events="all" rx="1.36" ry="1.36"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe flex-start;width:1px;height:1px;padding-top:75px;margin-left:74px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:left">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">
<p style="line-height:100%">/</p>
</div>
</div>
</div>
</foreignObject>
<text x="74" y="80" fill="#333" font-family="Monospace" font-size="16">/</text>
</switch>
<rect width="100" height="22" x="101" y="64" fill="#f5ebef" pointer-events="all" rx="1.76" ry="1.76"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe flex-start;width:1px;height:1px;padding-top:75px;margin-left:105px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:left">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">
<p style="line-height:100%">
<font color="#5d837e" style="font-size:16px">HTTP</font>/<font color="#cd5b92" style="font-size:16px">1.1</font>
</p>
</div>
</div>
</div>
</foreignObject>
<text x="105" y="80" fill="#333" font-family="Monospace" font-size="16">HTTP/1.1</text>
</switch>
<rect width="284" height="48" x="15" y="90" fill="#cfe3f5" pointer-events="all" rx="3.84" ry="3.84"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe flex-start;width:278px;height:1px;padding-top:114px;margin-left:19px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:left">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">
<div style="font-size:16px">
<font color="#5d837e" style="font-size:16px">Host</font>: developer.mozilla.org</div>
<div style="font-size:16px">
<font color="#5d837e" style="font-size:16px">Accept-Language</font>: fr</div>
</div>
</div>
</div>
</foreignObject>
<text x="19" y="119" fill="#333" font-family="Monospace" font-size="16">Host: developer.mozilla.org...</text>
</switch>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M157 144.37V161" pointer-events="stroke"/>
<path d="m157 139.12 2.33 7-2.33-1.75-2.33 1.75Z" pointer-events="all"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

@@ -0,0 +1,121 @@
<svg xmlns="http://www.w3.org/2000/svg" style="background-color:#fff" viewBox="-0.5 -0.5 422 205">
<rect width="100%" height="100%" fill="#FFF"/>
<rect width="381" height="105" x="30" y="51" fill="#e6e6e6" pointer-events="all" rx="3.15" ry="3.15"/>
<path fill="none" d="M233 0h137v30H233z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:135px;height:1px;padding-top:15px;margin-left:234px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">Status message</div>
</div>
</div>
</foreignObject>
<text x="302" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Status message</text>
</switch>
<path fill="none" d="M137 0h94v30h-94z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:92px;height:1px;padding-top:15px;margin-left:138px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">Status code</div>
</div>
</div>
</foreignObject>
<text x="184" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Status code</text>
</switch>
<path fill="none" d="M0 0h118v30H0z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:116px;height:1px;padding-top:15px;margin-left:1px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">Protocol version</div>
</div>
</div>
</foreignObject>
<text x="59" y="20" font-family="Helvetica" font-size="16" text-anchor="middle">Protocol version</text>
</switch>
<path fill="none" d="M192 175h60v30h-60z" pointer-events="all"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:58px;height:1px;padding-top:190px;margin-left:193px">
<div data-drawio-colors="color: rgb(0, 0, 0);" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:Helvetica;color:#000;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">
<div style="font-size:16px">Headers</div>
</div>
</div>
</div>
</foreignObject>
<text x="222" y="195" font-family="Helvetica" font-size="16" text-anchor="middle">Headers</text>
</switch>
<rect width="36" height="21" x="197" y="56" fill="#f2fffc" pointer-events="all" rx="1.68" ry="1.68"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:1px;height:1px;padding-top:66px;margin-left:215px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">OK</div>
</div>
</div>
</foreignObject>
<text x="215" y="71" fill="#333" font-family="Monospace" font-size="16" text-anchor="middle">OK</text>
</switch>
<rect width="42" height="21" x="139" y="56" fill="#f5f5ff" pointer-events="all" rx="1.68" ry="1.68"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:1px;height:1px;padding-top:66px;margin-left:160px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">200</div>
</div>
</div>
</foreignObject>
<text x="160" y="71" fill="#333" font-family="Monospace" font-size="16" text-anchor="middle">200</text>
</switch>
<rect width="92" height="22" x="38" y="55" fill="#f5ebef" pointer-events="all" rx="1.76" ry="1.76"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe center;width:1px;height:1px;padding-top:66px;margin-left:84px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:center">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:nowrap">
<p style="line-height:100%">
<font color="#5d837e" style="font-size:16px">HTTP</font>/<font color="#cd5b92" style="font-size:16px">1.1</font>
</p>
</div>
</div>
</div>
</foreignObject>
<text x="84" y="71" fill="#333" font-family="Monospace" font-size="16" text-anchor="middle">HTTP/1.1</text>
</switch>
<rect width="368" height="63" x="38" y="83" fill="#cfe3f5" pointer-events="all" rx="1.89" ry="1.89"/>
<switch transform="translate(-.5 -.5)">
<foreignObject width="100%" height="100%" pointer-events="none" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow:visible;text-align:left">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:unsafe center;justify-content:unsafe flex-start;width:362px;height:1px;padding-top:115px;margin-left:42px">
<div data-drawio-colors="color: #333333;" style="box-sizing:border-box;font-size:0;text-align:left">
<div style="display:inline-block;font-size:16px;font-family:monospace;color:#333;line-height:1.2;pointer-events:all;white-space:normal;overflow-wrap:normal">
<div style="font-size:16px">
<font color="#5d837e" style="font-size:16px">date</font>: Tue, 18 Jun 2024 10:03:55 GMT</div>
<div style="font-size:16px">
<font color="#5d837e" style="font-size:16px">cache-control</font>: public, max-age=3600</div>
<div style="font-size:16px">
<font color="#5d837e" style="font-size:16px">content-type</font>: text/html</div>
</div>
</div>
</div>
</foreignObject>
<text x="42" y="119" fill="#333" font-family="Monospace" font-size="16">date: Tue, 18 Jun 2024 10:03:55 GMT...</text>
</switch>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M222 152.37V175" pointer-events="stroke"/>
<path d="m222 147.12 2.33 7-2.33-1.75-2.33 1.75Z" pointer-events="all"/>
</g>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M229.63 53.02 273.15 30" pointer-events="stroke"/>
<path d="m224.99 55.48 5.09-5.34-.45 2.88 2.64 1.25Z" pointer-events="all"/>
</g>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="m163.22 50.5 12-20.5" pointer-events="stroke"/>
<path d="m160.56 55.04 1.53-7.22 1.13 2.68 2.89-.33Z" pointer-events="all"/>
</g>
<g stroke="#000" stroke-miterlimit="10">
<path fill="none" d="M60.68 48.64 59.75 30" pointer-events="stroke"/>
<path d="m60.94 53.88-2.68-6.87 2.42 1.63 2.25-1.86Z" pointer-events="all"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB