diff --git a/docker/docker-bind/docker-bind.png b/docker/docker-bind/docker-bind.png new file mode 100644 index 00000000..7c8b66aa Binary files /dev/null and b/docker/docker-bind/docker-bind.png differ diff --git a/docker/docker-compose/docker-compose.png b/docker/docker-compose/docker-compose.png new file mode 100644 index 00000000..a04cae01 Binary files /dev/null and b/docker/docker-compose/docker-compose.png differ diff --git a/docker/docker-compose/docker-compose.yml b/docker/docker-compose/docker-compose.yml new file mode 100644 index 00000000..b16eeffc --- /dev/null +++ b/docker/docker-compose/docker-compose.yml @@ -0,0 +1,6 @@ +services: + api: + image: jusan-fastapi-final:dockerized + container_name: jusan-compose + ports: + - "8282:8080" \ No newline at end of file diff --git a/docker/docker-exec/docker-exec.png b/docker/docker-exec/docker-exec.png new file mode 100644 index 00000000..cdec8d38 Binary files /dev/null and b/docker/docker-exec/docker-exec.png differ diff --git a/docker/docker-mount/docker-mount.png b/docker/docker-mount/docker-mount.png new file mode 100644 index 00000000..f534fa0d Binary files /dev/null and b/docker/docker-mount/docker-mount.png differ diff --git a/docker/docker-run/docker-run_1.png b/docker/docker-run/docker-run_1.png new file mode 100644 index 00000000..1bd70a5f Binary files /dev/null and b/docker/docker-run/docker-run_1.png differ diff --git a/docker/docker-run/docker-run_2.png b/docker/docker-run/docker-run_2.png new file mode 100644 index 00000000..aef4e366 Binary files /dev/null and b/docker/docker-run/docker-run_2.png differ diff --git a/docker/dockerfile/Dockerfile b/docker/dockerfile/Dockerfile new file mode 100644 index 00000000..5a64432e --- /dev/null +++ b/docker/dockerfile/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:mainline +WORKDIR /var/www +COPY jusan-dockerfile.conf /etc/nginx/conf.d/jusan-dockerfile.conf +COPY jusan-dockerfile . +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker/dockerfile/dockerfile.png b/docker/dockerfile/dockerfile.png new file mode 100644 index 00000000..1c3731ab Binary files /dev/null and b/docker/dockerfile/dockerfile.png differ diff --git a/docker/dockerize/Dockerfile b/docker/dockerize/Dockerfile new file mode 100644 index 00000000..79608fd1 --- /dev/null +++ b/docker/dockerize/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.8 +WORKDIR /opt +COPY main.py /opt/ +RUN pip3 install fastapi uvicorn +EXPOSE 8080 +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"] \ No newline at end of file diff --git a/docker/dockerize/__pycache__/main.cpython-311.pyc b/docker/dockerize/__pycache__/main.cpython-311.pyc new file mode 100644 index 00000000..bc47ed66 Binary files /dev/null and b/docker/dockerize/__pycache__/main.cpython-311.pyc differ diff --git a/docker/dockerize/dockerize.png b/docker/dockerize/dockerize.png new file mode 100644 index 00000000..96747c12 Binary files /dev/null and b/docker/dockerize/dockerize.png differ diff --git a/docker/dockerize/main.py b/docker/dockerize/main.py new file mode 100644 index 00000000..98c29e55 --- /dev/null +++ b/docker/dockerize/main.py @@ -0,0 +1,159 @@ +from fastapi import FastAPI, Response, status +from prometheus_client import Counter, Histogram, Gauge, generate_latest, REGISTRY +from prometheus_client.exposition import basic_auth_handler +import time + +app=FastAPI() + +REQUESTS = Counter('http_requests_total', 'Number of HTTP requests received', ['endpoint', 'method']) + +REQUEST_LATENCY = Histogram('http_requests_milliseconds', 'Duration of HTTP requests in milliseconds', ['endpoint', 'method'], buckets=[0.1, 0.3, 0.5, 1, 2, 5, 10]) + +LAST_VALUE_SUM1N = Gauge('last_sum1n', 'Value stores last result of sum1n') + +LAST_VALUE_FIBO = Gauge('last_fibo', 'Value stores last result of fibo') + +LAST_SIZE = Gauge('last_size', 'Value stores current list size') + +LAST_CALCULATOR = Gauge('last_calculator', 'Value stores last result of calculator') + +ERRORS_CALCULATOR = Counter('errors_calculator_total', 'Number of errors in calculator') + +@app.get("/") +async def root(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/', method='HTTP').inc() + return {"message": duration} + +@app.get("/metrics") +async def metrics(): + return Response(generate_latest(REGISTRY), media_type="text/plain") + +@app.get("/sum1n/{item}") +def sum1n(item): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/sum1n', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/sum1n', method='HTTP').inc() + result = 0 + i = 1 + while i <= int(item): + result += i + i += 1 + LAST_VALUE_SUM1N.set(result) + return {"result": result} + +@app.get("/fibo/") +def fibo(n: int = 0): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/fibo', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/fibo', method='HTTP').inc() + fibon = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] + LAST_VALUE_FIBO.set(fibon[int(n)-1]) + return {"result": fibon[int(n)-1]} + +@app.post("/reverse") +def reverse(item:str): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/reverse', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/reverse', method='HTTP').inc() + word = item [::-1] + return {"reversed word":word} + +ary = [] +@app.put("/list") +def list(item:str): + ary.append(item) + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/list', method='HTTP').inc() + LAST_SIZE.set(len(ary)) + return {"result":ary} + +@app.get("/list") +def list(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/list', method='HTTP').inc() + return {"result":ary} + +@app.post("/calculator") +def calc(item:str, response: Response): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/calculator', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/hello', method='HTTP').inc() + ind = [] + + for i in range(len(item)): + if item[i] == ",": + ind.append(i) + + num1_arr = "" + num2_arr = "" + oper=item[ind[0]+1] + + for i in range(ind[0]): + num1_arr =num1_arr + item[i] + + + for i in range(ind[1]+1, len(item), 1): + num2_arr = num2_arr + item[i] + + if len(ind) == 2 and num1_arr.isnumeric() == True and num2_arr.isnumeric() == True: + if oper == "+": + LAST_CALCULATOR.set(int(num1_arr)+int(num2_arr)) + return {"result":(int(num1_arr)+int(num2_arr))} + elif oper == "-": + LAST_CALCULATOR.set(int(num1_arr)-int(num2_arr)) + return {"result":(int(num1_arr)-int(num2_arr))} + elif oper == "*": + LAST_CALCULATOR.set(int(num1_arr)*int(num2_arr)) + return {"result":(int(num1_arr)*int(num2_arr))} + elif oper == "/": + if int(num2_arr)==0: + response.status_code = status.HTTP_403_FORBIDDEN + ERRORS_CALCULATOR.inc() + return{"error": "zerodiv"} + else: + LAST_CALCULATOR.set(int(num1_arr)/int(num2_arr)) + return{"result":(int(num1_arr)/int(num2_arr))} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + ERRORS_CALCULATOR.inc() + return{"error": "invalid"} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + ERRORS_CALCULATOR.inc() + return{"error":"invalid"} + +@app.get("/hello") +def hello(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/hello', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/hello', method='HTTP').inc() + return {"hello":"world"} + +@app.post("/create") +def create(item:int): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/create', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/create', method='HTTP').inc() + return {"newitem":item} + +@app.get("/new/{item}/{item2}") +def new(item,item2): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/new', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/new', method='HTTP').inc() + return {"new":item, + "new2":item2} \ No newline at end of file diff --git a/fastapi/fast_api.py b/fastapi/fast_api.py new file mode 100644 index 00000000..f0626f7a --- /dev/null +++ b/fastapi/fast_api.py @@ -0,0 +1,84 @@ +from fastapi import FastAPI, Response, status + +app=FastAPI() + +@app.get("/sum1n/{item}") +def sum1n(item): + result = 0 + i = 1 + while i <= int(item): + result += i + i += 1 + return {"result": result} + +@app.get("/fibo/") +def fibo(n: int = 0): + fibon = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] + return {"result": fibon[int(n)-1]} + +@app.post("/reverse") +def reverse(item:str): + word = item [::-1] + return {"reversed word":word} + +ary = [] +@app.put("/list") +def list(item:str): + ary.append(item) + return {"result":ary} + +@app.get("/list") +def list(): + return {"result":ary} + +@app.post("/calculator") +def calc(item:str, response: Response): + ind = [] + + for i in range(len(item)): + if item[i] == ",": + ind.append(i) + + num1_arr = "" + num2_arr = "" + oper=item[ind[0]+1] + + for i in range(ind[0]): + num1_arr =num1_arr + item[i] + + + for i in range(ind[1]+1, len(item), 1): + num2_arr = num2_arr + item[i] + + if len(ind) == 2 and num1_arr.isnumeric() == True and num2_arr.isnumeric() == True: + if oper == "+": + return {"result":(int(num1_arr)+int(num2_arr))} + elif oper == "-": + return {"result":(int(num1_arr)-int(num2_arr))} + elif oper == "*": + return {"result":(int(num1_arr)*int(num2_arr))} + elif oper == "/": + if int(num2_arr)==0: + response.status_code = status.HTTP_403_FORBIDDEN + return{"error": "zerodiv"} + else: + return{"result":(int(num1_arr)/int(num2_arr))} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + return{"error": "invalid"} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + return{"error":"invalid"} + +@app.get("/hello") +def hello(): + return {"hello":"world"} + +@app.post("/create") +def create(item:int): + return {"newitem":item} + +@app.get("/new/{item}/{item2}") +def new(item,item2): + return {"new":item, + "new2":item2} \ No newline at end of file diff --git a/git/0 git_homework/1 git-init.txt b/git/0 git_homework/1 git-init.txt new file mode 100644 index 00000000..58394575 --- /dev/null +++ b/git/0 git_homework/1 git-init.txt @@ -0,0 +1,7 @@ +https://github.com/khalykbaiakaris/jusan-git/tree/e2d7ccc7db8d4c0ebd582c79edab18e39e2f9feaf683 + + +### вывод лога +### git log --all --decorate --oneline --graph +### * ccc7db8 (HEAD -> main, origin/main) add: README.md +### * e2d743e add: script.sh \ No newline at end of file diff --git a/git/0 git_homework/2 readme.txt b/git/0 git_homework/2 readme.txt new file mode 100644 index 00000000..df62b211 --- /dev/null +++ b/git/0 git_homework/2 readme.txt @@ -0,0 +1 @@ +https://github.com/khalykbaiakaris/jusan-git/tree/06ef4226f63b5bba8290e04e6ab897d203f28187 \ No newline at end of file diff --git a/git/0 git_homework/3 gitignore.txt b/git/0 git_homework/3 gitignore.txt new file mode 100644 index 00000000..8b1e60e8 --- /dev/null +++ b/git/0 git_homework/3 gitignore.txt @@ -0,0 +1 @@ +https://github.com/khalykbaiakaris/jusan-git/tree/58065e3386ff0ca3488172403a662e839e31a9d0 \ No newline at end of file diff --git a/git/0 git_homework/4 branch.txt b/git/0 git_homework/4 branch.txt new file mode 100644 index 00000000..ae47cc20 --- /dev/null +++ b/git/0 git_homework/4 branch.txt @@ -0,0 +1 @@ +https://github.com/khalykbaiakaris/jusan-git/tree/5612c4829f4320b05ea88e403d7600097578f135 \ No newline at end of file diff --git a/git/0 git_homework/5 merge.txt b/git/0 git_homework/5 merge.txt new file mode 100644 index 00000000..be81dde5 --- /dev/null +++ b/git/0 git_homework/5 merge.txt @@ -0,0 +1 @@ +https://github.com/khalykbaiakaris/jusan-git/tree/23c9068bf6dff83881da56408bcf847d8d5be6d4 \ No newline at end of file diff --git a/git/0 git_homework/6 my-pr.txt b/git/0 git_homework/6 my-pr.txt new file mode 100644 index 00000000..ece52374 --- /dev/null +++ b/git/0 git_homework/6 my-pr.txt @@ -0,0 +1 @@ +https://github.com/khalykbaiakaris/jusan-git/pull/1 \ No newline at end of file diff --git a/git/0 git_homework/7 fork-pr.txt b/git/0 git_homework/7 fork-pr.txt new file mode 100644 index 00000000..778f2a50 --- /dev/null +++ b/git/0 git_homework/7 fork-pr.txt @@ -0,0 +1 @@ +https://github.com/jusan-singularity/fork-me/pull/113 \ No newline at end of file diff --git a/monitoring/Dockerfile b/monitoring/Dockerfile new file mode 100644 index 00000000..8c143cc3 --- /dev/null +++ b/monitoring/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.8 +WORKDIR /opt +COPY main.py /opt +RUN pip3 install fastapi uvicorn prometheus_client +EXPOSE 8080 +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"] \ No newline at end of file diff --git a/monitoring/alerting.png b/monitoring/alerting.png new file mode 100644 index 00000000..a9664b00 Binary files /dev/null and b/monitoring/alerting.png differ diff --git a/monitoring/docker-compose.yml b/monitoring/docker-compose.yml new file mode 100644 index 00000000..2b8c3a60 --- /dev/null +++ b/monitoring/docker-compose.yml @@ -0,0 +1,21 @@ +services: + api: + build: . + ports: + - 8080:8080 + restart: on-failure + prometheus: + image: prom/prometheus:v2.34.0 + ports: + - 9090:9090 + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + depends_on: + - api + + grafana: + image: grafana/grafana:8.4.5 + ports: + - 3000:3000 + depends_on: + - prometheus \ No newline at end of file diff --git a/monitoring/grafana.png b/monitoring/grafana.png new file mode 100644 index 00000000..27a2335f Binary files /dev/null and b/monitoring/grafana.png differ diff --git a/monitoring/main.py b/monitoring/main.py new file mode 100644 index 00000000..8ce1c0fc --- /dev/null +++ b/monitoring/main.py @@ -0,0 +1,159 @@ +from main import FastAPI, Response, status +from prometheus_client import Counter, Histogram, Gauge, generate_latest, REGISTRY +from prometheus_client.exposition import basic_auth_handler +import time + +app=FastAPI() + +REQUESTS = Counter('http_requests_total', 'Number of HTTP requests received', ['endpoint', 'method']) + +REQUEST_LATENCY = Histogram('http_requests_milliseconds', 'Duration of HTTP requests in milliseconds', ['endpoint', 'method'], buckets=[0.1, 0.3, 0.5, 1, 2, 5, 10]) + +LAST_VALUE_SUM1N = Gauge('last_sum1n', 'Value stores last result of sum1n') + +LAST_VALUE_FIBO = Gauge('last_fibo', 'Value stores last result of fibo') + +LAST_SIZE = Gauge('last_size', 'Value stores current list size') + +LAST_CALCULATOR = Gauge('last_calculator', 'Value stores last result of calculator') + +ERRORS_CALCULATOR = Counter('errors_calculator_total', 'Number of errors in calculator') + +@app.get("/") +async def root(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/', method='HTTP').inc() + return {"message": duration} + +@app.get("/metrics") +async def metrics(): + return Response(generate_latest(REGISTRY), media_type="text/plain") + +@app.get("/sum1n/{item}") +def sum1n(item): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/sum1n', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/sum1n', method='HTTP').inc() + result = 0 + i = 1 + while i <= int(item): + result += i + i += 1 + LAST_VALUE_SUM1N.set(result) + return {"result": result} + +@app.get("/fibo/") +def fibo(n: int = 0): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/fibo', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/fibo', method='HTTP').inc() + fibon = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] + LAST_VALUE_FIBO.set(fibon[int(n)-1]) + return {"result": fibon[int(n)-1]} + +@app.post("/reverse") +def reverse(item:str): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/reverse', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/reverse', method='HTTP').inc() + word = item [::-1] + return {"reversed word":word} + +ary = [] +@app.put("/list") +def list(item:str): + ary.append(item) + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/list', method='HTTP').inc() + LAST_SIZE.set(len(ary)) + return {"result":ary} + +@app.get("/list") +def list(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/list', method='HTTP').inc() + return {"result":ary} + +@app.post("/calculator") +def calc(item:str, response: Response): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/calculator', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/hello', method='HTTP').inc() + ind = [] + + for i in range(len(item)): + if item[i] == ",": + ind.append(i) + + num1_arr = "" + num2_arr = "" + oper=item[ind[0]+1] + + for i in range(ind[0]): + num1_arr =num1_arr + item[i] + + + for i in range(ind[1]+1, len(item), 1): + num2_arr = num2_arr + item[i] + + if len(ind) == 2 and num1_arr.isnumeric() == True and num2_arr.isnumeric() == True: + if oper == "+": + LAST_CALCULATOR.set(int(num1_arr)+int(num2_arr)) + return {"result":(int(num1_arr)+int(num2_arr))} + elif oper == "-": + LAST_CALCULATOR.set(int(num1_arr)-int(num2_arr)) + return {"result":(int(num1_arr)-int(num2_arr))} + elif oper == "*": + LAST_CALCULATOR.set(int(num1_arr)*int(num2_arr)) + return {"result":(int(num1_arr)*int(num2_arr))} + elif oper == "/": + if int(num2_arr)==0: + response.status_code = status.HTTP_403_FORBIDDEN + ERRORS_CALCULATOR.inc() + return{"error": "zerodiv"} + else: + LAST_CALCULATOR.set(int(num1_arr)/int(num2_arr)) + return{"result":(int(num1_arr)/int(num2_arr))} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + ERRORS_CALCULATOR.inc() + return{"error": "invalid"} + else: + response.status_code = status.HTTP_400_BAD_REQUEST + ERRORS_CALCULATOR.inc() + return{"error":"invalid"} + +@app.get("/hello") +def hello(): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/hello', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/hello', method='HTTP').inc() + return {"hello":"world"} + +@app.post("/create") +def create(item:int): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/create', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/create', method='HTTP').inc() + return {"newitem":item} + +@app.get("/new/{item}/{item2}") +def new(item,item2): + start_time = time.time() + duration = start_time/1000000000 + REQUEST_LATENCY.labels(endpoint='/new', method='HTTP').observe(duration) + REQUESTS.labels(endpoint='/new', method='HTTP').inc() + return {"new":item, + "new2":item2} \ No newline at end of file diff --git a/monitoring/prometheus.yml b/monitoring/prometheus.yml new file mode 100644 index 00000000..0b41ed5e --- /dev/null +++ b/monitoring/prometheus.yml @@ -0,0 +1,8 @@ +scrape_configs: + - job_name: 'Prometheus' + + # Override the global default and scrape targets from this job every 5 seconds. + scrape_interval: 10s + + static_configs: + - targets: ['api:8080'] diff --git a/nginx/nginx-auth/nginx-auth.png b/nginx/nginx-auth/nginx-auth.png new file mode 100644 index 00000000..080b6879 Binary files /dev/null and b/nginx/nginx-auth/nginx-auth.png differ diff --git a/nginx/nginx-auth/nginx.conf b/nginx/nginx-auth/nginx.conf new file mode 100644 index 00000000..d2b0a2c1 --- /dev/null +++ b/nginx/nginx-auth/nginx.conf @@ -0,0 +1,48 @@ + +events {} + + +http { + + include mime.types; + + server { + listen 8080; + listen 443 ssl; + + ssl_certificate /etc/nginx/ssl/track-devops.crt; + ssl_certificate_key /etc/nginx/ssl/track-devops.key; + + server_name jusan.kz example.com; + root /var/www; + + location / { + index index.html; + } + + location /images { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_img; + root /var/www; + try_files $uri =404; + } + + location /gifs { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_gif; + root /var/www; + try_files $uri =404; + } + + location = /secret_word { + allow 192.0.0.1/20; + deny 192.0.0.1; + deny all; + return 201 'jusan-nginx-locations'; + } + + location /api { + proxy_pass http://localhost:9090; + } + } +} diff --git a/nginx/nginx-cert/nginx-cert.png b/nginx/nginx-cert/nginx-cert.png new file mode 100644 index 00000000..3cd8a10c Binary files /dev/null and b/nginx/nginx-cert/nginx-cert.png differ diff --git a/nginx/nginx-cert/nginx.conf b/nginx/nginx-cert/nginx.conf new file mode 100644 index 00000000..d2b0a2c1 --- /dev/null +++ b/nginx/nginx-cert/nginx.conf @@ -0,0 +1,48 @@ + +events {} + + +http { + + include mime.types; + + server { + listen 8080; + listen 443 ssl; + + ssl_certificate /etc/nginx/ssl/track-devops.crt; + ssl_certificate_key /etc/nginx/ssl/track-devops.key; + + server_name jusan.kz example.com; + root /var/www; + + location / { + index index.html; + } + + location /images { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_img; + root /var/www; + try_files $uri =404; + } + + location /gifs { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_gif; + root /var/www; + try_files $uri =404; + } + + location = /secret_word { + allow 192.0.0.1/20; + deny 192.0.0.1; + deny all; + return 201 'jusan-nginx-locations'; + } + + location /api { + proxy_pass http://localhost:9090; + } + } +} diff --git a/nginx/nginx-install/nginx-install.png b/nginx/nginx-install/nginx-install.png new file mode 100644 index 00000000..8b150bb0 Binary files /dev/null and b/nginx/nginx-install/nginx-install.png differ diff --git a/nginx/nginx-ip/nginx.conf b/nginx/nginx-ip/nginx.conf new file mode 100644 index 00000000..d2b0a2c1 --- /dev/null +++ b/nginx/nginx-ip/nginx.conf @@ -0,0 +1,48 @@ + +events {} + + +http { + + include mime.types; + + server { + listen 8080; + listen 443 ssl; + + ssl_certificate /etc/nginx/ssl/track-devops.crt; + ssl_certificate_key /etc/nginx/ssl/track-devops.key; + + server_name jusan.kz example.com; + root /var/www; + + location / { + index index.html; + } + + location /images { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_img; + root /var/www; + try_files $uri =404; + } + + location /gifs { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_gif; + root /var/www; + try_files $uri =404; + } + + location = /secret_word { + allow 192.0.0.1/20; + deny 192.0.0.1; + deny all; + return 201 'jusan-nginx-locations'; + } + + location /api { + proxy_pass http://localhost:9090; + } + } +} diff --git a/nginx/nginx-locations/nginx-locations.png b/nginx/nginx-locations/nginx-locations.png new file mode 100644 index 00000000..2f655c4f Binary files /dev/null and b/nginx/nginx-locations/nginx-locations.png differ diff --git a/nginx/nginx-locations/nginx.conf b/nginx/nginx-locations/nginx.conf new file mode 100644 index 00000000..d2b0a2c1 --- /dev/null +++ b/nginx/nginx-locations/nginx.conf @@ -0,0 +1,48 @@ + +events {} + + +http { + + include mime.types; + + server { + listen 8080; + listen 443 ssl; + + ssl_certificate /etc/nginx/ssl/track-devops.crt; + ssl_certificate_key /etc/nginx/ssl/track-devops.key; + + server_name jusan.kz example.com; + root /var/www; + + location / { + index index.html; + } + + location /images { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_img; + root /var/www; + try_files $uri =404; + } + + location /gifs { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_gif; + root /var/www; + try_files $uri =404; + } + + location = /secret_word { + allow 192.0.0.1/20; + deny 192.0.0.1; + deny all; + return 201 'jusan-nginx-locations'; + } + + location /api { + proxy_pass http://localhost:9090; + } + } +} diff --git a/nginx/nginx-proxy/nginx-proxy.png b/nginx/nginx-proxy/nginx-proxy.png new file mode 100644 index 00000000..0eb8b77e Binary files /dev/null and b/nginx/nginx-proxy/nginx-proxy.png differ diff --git a/nginx/nginx-proxy/nginx.conf b/nginx/nginx-proxy/nginx.conf new file mode 100644 index 00000000..d2b0a2c1 --- /dev/null +++ b/nginx/nginx-proxy/nginx.conf @@ -0,0 +1,48 @@ + +events {} + + +http { + + include mime.types; + + server { + listen 8080; + listen 443 ssl; + + ssl_certificate /etc/nginx/ssl/track-devops.crt; + ssl_certificate_key /etc/nginx/ssl/track-devops.key; + + server_name jusan.kz example.com; + root /var/www; + + location / { + index index.html; + } + + location /images { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_img; + root /var/www; + try_files $uri =404; + } + + location /gifs { + auth_basic "Enter password"; + auth_basic_user_file conf.d/.auth_gif; + root /var/www; + try_files $uri =404; + } + + location = /secret_word { + allow 192.0.0.1/20; + deny 192.0.0.1; + deny all; + return 201 'jusan-nginx-locations'; + } + + location /api { + proxy_pass http://localhost:9090; + } + } +} diff --git a/nginx/nginx-ufw/nginx-ufw.png b/nginx/nginx-ufw/nginx-ufw.png new file mode 100644 index 00000000..981d2435 Binary files /dev/null and b/nginx/nginx-ufw/nginx-ufw.png differ diff --git a/python/easy/array-min.py b/python/easy/array-min.py new file mode 100644 index 00000000..2e34fc02 --- /dev/null +++ b/python/easy/array-min.py @@ -0,0 +1,7 @@ +def array_min(array): + if len(array) > 0: + print(min(array)) + else: + print(0) + +array_min([]) \ No newline at end of file diff --git a/python/easy/array-sort.py b/python/easy/array-sort.py new file mode 100644 index 00000000..7602cada --- /dev/null +++ b/python/easy/array-sort.py @@ -0,0 +1,5 @@ +def array_sort(array): + array.sort() + print(array) + +array_sort([3,2,1]) \ No newline at end of file diff --git a/python/easy/array-sum.py b/python/easy/array-sum.py new file mode 100644 index 00000000..843973d7 --- /dev/null +++ b/python/easy/array-sum.py @@ -0,0 +1,7 @@ +def array_sum(array): + sum = 0 + for i in array: + sum += i + print(sum) + +array_sum([1,2,3]) \ No newline at end of file diff --git a/python/easy/calc-deposit.py b/python/easy/calc-deposit.py new file mode 100644 index 00000000..d5636ea8 --- /dev/null +++ b/python/easy/calc-deposit.py @@ -0,0 +1,6 @@ +def calc(b, k, n): + for i in range(n): + b += b*k/100 + print(b) + +calc(1000, 5, 1) \ No newline at end of file diff --git a/python/easy/int-cmp.py b/python/easy/int-cmp.py new file mode 100644 index 00000000..df47c280 --- /dev/null +++ b/python/easy/int-cmp.py @@ -0,0 +1,8 @@ +a = input("a = ") +b = input("b = ") +if a > b: + print("1") +elif a == b: + print("0") +else: + print("-1") \ No newline at end of file diff --git a/python/easy/max-of-three.py b/python/easy/max-of-three.py new file mode 100644 index 00000000..41308724 --- /dev/null +++ b/python/easy/max-of-three.py @@ -0,0 +1,5 @@ +a = input("a = ") +b = input("b = ") +c = input("c = ") +list3 = [a, b, c] +print(max(list3)) \ No newline at end of file diff --git a/python/easy/pow-a-b.py b/python/easy/pow-a-b.py new file mode 100644 index 00000000..98164d98 --- /dev/null +++ b/python/easy/pow-a-b.py @@ -0,0 +1,7 @@ +a = int(input("a = ")) +b = int(input("b = ")) +sum = 1 +for i in range(b): + sum*=a + +print("pow(a,b)", sum) \ No newline at end of file diff --git a/python/easy/print-even-a-b.py b/python/easy/print-even-a-b.py new file mode 100644 index 00000000..d9bcc80e --- /dev/null +++ b/python/easy/print-even-a-b.py @@ -0,0 +1,8 @@ +a = int(input("a = ")) +b = int(input("b = ")) +list1 = [] +while a <= b: + if a%2 == 0: + list1.append(a) + a+=1 +print(list1) \ No newline at end of file diff --git a/python/easy/range.py b/python/easy/range.py new file mode 100644 index 00000000..68a852f2 --- /dev/null +++ b/python/easy/range.py @@ -0,0 +1,9 @@ +def range(n): + array1 = [0] * n + i = 0 + while i < n: + array1[i] = i+1 + i+=1 + print(array1) + +range(5) \ No newline at end of file diff --git a/python/easy/sqr-sum-1-n.py b/python/easy/sqr-sum-1-n.py new file mode 100644 index 00000000..a6943c31 --- /dev/null +++ b/python/easy/sqr-sum-1-n.py @@ -0,0 +1,6 @@ +n = int(input("n = ")) +sum = 0 +for i in range(n): + sum+=(i+1)*(i+1) + +print("sum = ", sum) \ No newline at end of file diff --git a/python/hard/median.py b/python/hard/median.py new file mode 100644 index 00000000..745e7d12 --- /dev/null +++ b/python/hard/median.py @@ -0,0 +1,8 @@ +def median(array): + i = int(len(array)/2) + if len(array)%2==1: + print(array[i]) + else: + print(array[i-1]) + +median([1, 2, 3, 4]) \ No newline at end of file diff --git a/python/hard/perfectly-balanced.py b/python/hard/perfectly-balanced.py new file mode 100644 index 00000000..7471698d --- /dev/null +++ b/python/hard/perfectly-balanced.py @@ -0,0 +1,17 @@ +ary = [1, 2, 9, 8, 5, 7] +res=bool + +for i in range(len(ary)-2): + sum1=0 + sum2=0 + for j in range(i+1): + sum1+=ary[j] + for k in range(len(ary)-2-i): + sum2+=ary[k+i+2] + if sum1 == sum2: + res=True + +if res==True: + print("true") +else: + print("false") diff --git a/python/hard/sort-nums-thress.py b/python/hard/sort-nums-thress.py new file mode 100644 index 00000000..8026fde7 --- /dev/null +++ b/python/hard/sort-nums-thress.py @@ -0,0 +1,18 @@ +def sortn(a, b, c): + if a <= b and a <= c: + if b <= c: + print(a, " ", b, " ", c) + else: + print(a, " ", c, " ", b) + elif b <= a and b <= c: + if a <= c: + print(b, " ", a, " ", c) + else: + print(b, " ", c, " ", a) + else: + if b <= a: + print(c, " ", b, " ", a) + else: + print(c, " ", a, " ", b) + +sortn(3, 2, 1) \ No newline at end of file diff --git a/python/hard/sum-1-n.py b/python/hard/sum-1-n.py new file mode 100644 index 00000000..5b3736df --- /dev/null +++ b/python/hard/sum-1-n.py @@ -0,0 +1,7 @@ +def sumn(n): + if n < 1: + return 0 + return n + sumn(n-1) + +number = int(input("Enter number: ")) +print(sumn(number)) \ No newline at end of file diff --git a/python/hard/swap-bits.py b/python/hard/swap-bits.py new file mode 100644 index 00000000..b83a8437 --- /dev/null +++ b/python/hard/swap-bits.py @@ -0,0 +1,15 @@ +import math + +number=int(input("Enter number: ")) +bit = [0, 0, 0, 0, 0, 0, 0, 0] +res = 0 + +for i in range(len(bit)): + if number >= 1: + bit[i]=number%2 + number=int(number/2) + +for i in range(len(bit)): + res += bit[i] * pow(2, (7-i)) + +print(res) \ No newline at end of file diff --git a/python/medium/date.py b/python/medium/date.py new file mode 100644 index 00000000..601d675a --- /dev/null +++ b/python/medium/date.py @@ -0,0 +1,5 @@ +date = input("Enter date: ") +if date[2] == "." and date[5] == "." and int(date[0])*10+int(date[1]) <=31 and (int(date[3])*10+int(date[4])) <= 12 and int(date[6])*1000+int(date[7])*100+int(date[8])*10+int(date[9]) <= 2024: + print("You entered correct date") +else: + print("You entered incorrect date") diff --git a/python/medium/even-or-odd.py b/python/medium/even-or-odd.py new file mode 100644 index 00000000..6ca254d2 --- /dev/null +++ b/python/medium/even-or-odd.py @@ -0,0 +1,5 @@ +number = int(input("Enter numer: ")) +if number%2 == 0: + print("You entered even number") +else: + print("You entered odd number") \ No newline at end of file diff --git a/python/medium/fibonachi.py b/python/medium/fibonachi.py new file mode 100644 index 00000000..417af2d6 --- /dev/null +++ b/python/medium/fibonachi.py @@ -0,0 +1,6 @@ +fibo = (0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144) +number = int(input("Enter number")) +if number in fibo: + print("The number is fibonachi") +else: + print("The number is not fibonachi") \ No newline at end of file diff --git a/python/medium/natural-number.py b/python/medium/natural-number.py new file mode 100644 index 00000000..b4c83a6d --- /dev/null +++ b/python/medium/natural-number.py @@ -0,0 +1,22 @@ +def range(n): + array1 = [0] * n + i = 0 + while i < n: + array1[i] = i+1 + i+=1 + return array1 + +number = int(input("Enter number: ")) +array2 = range(number) + +i = 1 + +while i < number-1: + if number%array2[i]==0: + print(number, " is not natural") + break + else: + i+=1 + +if i == number-1: + print(number, " is natural") \ No newline at end of file diff --git a/python/medium/palindrom.py b/python/medium/palindrom.py new file mode 100644 index 00000000..fa5b3fc1 --- /dev/null +++ b/python/medium/palindrom.py @@ -0,0 +1,14 @@ +word = str(input("Enter word: ")) +l = len(word) + +j = int(l/2) +k = 0 +for i in range(j): + if word[i] == word[l-1-i]: + k+=1 + else: + break +if k == j: + print(word, " is palindrom") +else: + print(word, " is not polindrom") diff --git a/python/medium/perfect-number-enter.py b/python/medium/perfect-number-enter.py new file mode 100644 index 00000000..600aa6ef --- /dev/null +++ b/python/medium/perfect-number-enter.py @@ -0,0 +1,9 @@ +number = int(input("Enter number: ")) +dls = list() +for i in range(number): + if number%(i+1)==0: + dls.append(i+1) +if sum(dls)/2 == number: + print("The number is perfect") +else: + print("The number is not perfect") \ No newline at end of file diff --git a/python/medium/perfect-number.py b/python/medium/perfect-number.py new file mode 100644 index 00000000..dc69a54a --- /dev/null +++ b/python/medium/perfect-number.py @@ -0,0 +1,10 @@ +i = 2 +while i <= 1000: + dls = list() + j = 1 + for j in range(i): + if i%(j+1)==0: + dls.append(j+1) + if sum(dls)/2 == i: + print(i, " ") + i+=1 diff --git a/python/medium/season.py b/python/medium/season.py new file mode 100644 index 00000000..0f5b34a4 --- /dev/null +++ b/python/medium/season.py @@ -0,0 +1,16 @@ +date = input("Enter date: ") +if int(date[0])==0: + if int(date[1]) <= 2: + print("it is winter") + elif int(date[1]) <= 5: + print("it is spring") + elif int(date[1]) <= 8: + print("it is summer") + else: + print("it is autumn") +else: + if int(date[1]) <= 1: + print("it is autumn") + else: + print("it is winter") + \ No newline at end of file