Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw2 #82

Open
wants to merge 3 commits into
base: SadkinID/main
Choose a base branch
from
Open

hw2 #82

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Docker/code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

Check failure on line 1 in Docker/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line

Check failure on line 1 in Docker/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

End of line character is invalid; expected &quot;\n&quot; but found &quot;\r\n&quot;
echo "Hello, Проверяющие :)";

phpinfo();

Check failure on line 4 in Docker/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
27 changes: 27 additions & 0 deletions Docker/fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM php:8.3-fpm

RUN apt-get update && apt-get install -y \
curl \
wget \
git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& mkdir -p /run/php

# Устанавливаем Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY php.ini /usr/local/etc/php/conf.d/php-custom.ini
COPY zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf


WORKDIR /data

VOLUME /data

CMD ["php-fpm"]
2 changes: 2 additions & 0 deletions Docker/fpm/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
session.save_handler = memcache
session.save_path = "tcp://memcache:11211"
6 changes: 6 additions & 0 deletions Docker/fpm/zz-docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[global]
daemonize = no

[www]
listen = /run/php/php-fpm.sock
listen.mode = 0666
7 changes: 7 additions & 0 deletions Docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx:latest
COPY hosts/application.local.conf /etc/nginx/conf.d/application.local.conf

WORKDIR /data
VOLUME /data
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
26 changes: 26 additions & 0 deletions Docker/nginx/hosts/application.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server {
listen 80;
server_name application.local;

root /data/application.local;

index index.php index.html;

location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
19 changes: 19 additions & 0 deletions calc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

if [ $# -ne 2 ]; then
echo "Дай мне два числа, разделенные пробелом :)"
exit
fi

num1=$(echo "$1" | sed 's/,/./')

num2=$(echo "$2" | sed 's/,/./')

if ! [[ $num1 =~ ^[-+]?[0-9]+(\.[0-9]+)?$ ]] || ! [[ $num2 =~ ^[-+]?[0-9]+(\.[0-9]+)?$ ]]; then
echo "Мне не удалось разобрать один из передаваемых аргументов :("
exit
fi

sum=$(awk "BEGIN {print $num1 + $num2}")

echo "Ответ: $sum"
17 changes: 17 additions & 0 deletions city.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [ ! -f "$1" ]; then
echo "Мне не удалось найти передаваемый файл."
exit
fi

if [ -z $2 ]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если запустить без аргументов - просто висит.

count=3
else
count=$2
fi

cat $1 | tail -n +2 | awk '{print $3}' | grep -v '^$'| sort | uniq | while read city; do
summ=$(cat $1 | tail -n +2 | grep $city | awk '{sum += $4;} END {print sum;}')
echo $city $summ
done | sort -r -n -k2 | head -$count
15 changes: 15 additions & 0 deletions city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id user city phone

1 test Omsk 53984123

2 test2 Moscow 1234123

3 test3 Saint-P 1232121

4 test4 Tver 4352124

5 test5 Milan 7990923

6 test6 Moscow 908213

7 test7 Omsk 12682543
4 changes: 4 additions & 0 deletions code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

Check failure on line 1 in code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line

Check failure on line 1 in code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

End of line character is invalid; expected &quot;\n&quot; but found &quot;\r\n&quot;
echo "Hello, Otus!";

phpinfo();

Check failure on line 4 in code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
65 changes: 65 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

version: '3'

services:
app:
build:
context: Docker/fpm
dockerfile: Dockerfile
image: myapp/php
container_name: app
volumes:
- ./Docker/code:/data/application.local
- "phpsocket:/var/run"
networks:
- app-network

webserver:
build:
context: Docker/nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
ports:
- "8080:80"
- "443:443"
volumes:
- ./Docker/code:/data/application.local
- "phpsocket:/var/run"
networks:
- app-network

memcached:
image: memcached:latest
ports:
- "11211:11211"
networks:
- app-network

redis:
image: redis:latest
ports:
- "6379:6379"
networks:
- app-network

postgres_db:
image: postgres:latest
container_name: db
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- '5432:5432'
volumes:
- postgres_db:/var/lib/postgresql/data


volumes:
postgres_db:
driver: local
phpsocket:
networks:
app-network:
driver: bridge
54 changes: 54 additions & 0 deletions docker-compose.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# версия синтаксиса
version: '3'

# в этом блоке мы описываем контейнеры, которые будут запускаться
services:

#Контейнер с PHP, назовём его app
app:
# Если нет секции build, то система будет искать образ в репозиториях
build:
context: ./fpm
dockerfile: Dockerfile
image: myapp/php # имя будущего образа
container_name: app # имя контейнера после запуска
volumes:
- ./code:/data/mysite.local
# мы можем создать для контейнеров внутреннюю сеть
networks:
- app-network

#контейне с Nginx
webserver:
build:
context: ./nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
volumes:
- ./code:/data/mysite.local
# проброс портов
ports:
- "80:80"
- "443:443"
networks:
- app-network

#MySQL Service
db:
image: mysql:5.7.22
container_name: db
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
networks:
- app-network
volumes:
- ./dbdata:/var/lib/mysql

#Docker Networks
networks:
app-network:
driver: bridge
Loading