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

hw1 #1166

Open
wants to merge 9 commits into
base: AGaliy/main
Choose a base branch
from
39 changes: 39 additions & 0 deletions hw1/code/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

Check failure on line 1 in hw1/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;
Copy link

Choose a reason for hiding this comment

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

Поправьте все замечания линтера.


echo "Привет, Otus!<br>".date("Y-m-d H:i:s") ."<br><br>";

Check failure on line 3 in hw1/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;.&quot;; 0 found

Check failure on line 3 in hw1/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;.&quot;; 0 found

Check failure on line 3 in hw1/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;.&quot;; 0 found

// Параметры подключения к базе данных
$hostname = 'mysql';
$username = 'user';
$password = 'pass';
$database = 'app';

// Создание подключения
$connection = new mysqli($hostname, $username, $password);
// Проверка подключения
if ($connection->connect_error) {
echo "Ошибка подключения: " . $connection->connect_error;
} else {
echo "Подключение к базе данных MySQL успешно установлено!";
}

define('MEMCACHED_HOST', 'memcached');
define('MEMCACHED_PORT', '11211');
$memcache = new Memcached;

Check failure on line 22 in hw1/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Parentheses must be used when instantiating a new class
$cacheAvailable = $memcache->addServer(MEMCACHED_HOST, MEMCACHED_PORT);

if ($cacheAvailable) {
echo "<br>Memcached подключен!";
} else {
echo "<br>Ошибка Memcached";
}

$redis = new Redis();
$redis->connect('redis');
$redisPing = $redis->ping();

if ($redisPing) {
echo "<br>Redis подключен!";
} else {
echo "<br>Ошибка Redis";
}

Check failure on line 39 in hw1/code/index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
91 changes: 91 additions & 0 deletions hw1/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# версия синтаксиса
version: '3'

# в этом блоке мы описываем контейнеры, которые будут запускаться
services:
#контейнер с Nginx
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
image: myapp/nginx
container_name: webserver
# проброс портов
ports:
- "80:80"
volumes:
- ./code:/data/application.local
networks:
- app-network

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

mysql:
container_name: mysql
build:
context: ./mysql
dockerfile: Dockerfile
image: myapp/mysql
volumes:
- ./mysql.sock:/var/lib/
# - ./mysql:/var/lib/mysqld
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: app
ports:
- 3306:3306
networks:
- app-network

adminer:
image: adminer:latest
restart: always
environment:
ADMINER_DEFAULT_SERVER: mysql
ports:
- 8080:8080
networks:
- app-network

redis:
container_name: redis
image: redis
command: redis-server
ports:
- "6379:6379"
volumes:
- /redis:/var/lib/redis
- /redis/redis.conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
networks:
- app-network

memcached:
container_name: memcached
image: memcached
ports:
- 11211:11211
command:
- '--memory-limit=1024'
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge
31 changes: 31 additions & 0 deletions hw1/fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM php:8.2-fpm

RUN apt-get update && apt-get install -y \
libfreetype-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
unzip \
libmemcached-dev \
zlib1g-dev \
libmemcached11 \
libssl-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 \
&& pecl install redis && \
docker-php-ext-enable redis

RUN yes '' | pecl install -f memcached-3.2.0 \
&& docker-php-ext-enable memcached

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

WORKDIR /data

VOLUME /data

CMD ["php-fpm"]
2 changes: 2 additions & 0 deletions hw1/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"
2 changes: 2 additions & 0 deletions hw1/memcached/.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM memcached:latest
Copy link

Choose a reason for hiding this comment

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

Можно просто взять базовый образ.

CMD ["memcached", "-D"]
12 changes: 12 additions & 0 deletions hw1/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mysql:8.0
Copy link

Choose a reason for hiding this comment

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

Можно просто взять базовый образ.


# Set an insecure password

ENV MYSQL_USER=user
ENV MYSQL_PASSWORD=pass
ENV MYSQL_ROOT_PASSWORD=pass
# Copy over our SQL queries
# COPY init.sql init.sql

# Startup MySQL and run the queries
# CMD ["mysqld", "--init-file=init.sql"]
14 changes: 14 additions & 0 deletions hw1/mysql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE DATABASE app;
USE app;

CREATE TABLE message (
id INT NOT NULL AUTO_INCREMENT,
message VARCHAR(50) NOT NULL,
PRIMARY KEY(id)
);

INSERT INTO message (message)
VALUES
("Hello World"),
("A second message"),
("J.Cole went double platinum with no features");
11 changes: 11 additions & 0 deletions hw1/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;"]
36 changes: 36 additions & 0 deletions hw1/nginx/hosts/application.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
server {
# указываем 80 порт для соединения
listen 80;
# нужно указать, какому доменному имени принадлежит наш конфиг
server_name application.local;

# задаём корневую директорию
root /data/application.local;

# стартовый файл
index index.php index.html;

# при обращении к статическим файлам логи не нужны, равно как и обращение к fpm
# http://application.local/static/some.png
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}

# помним про единую точку доступа
# все запросы заворачиваются в корневую директорию root на index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# и наконец правило обращения к php-fpm
location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
1 change: 1 addition & 0 deletions hw1/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM redis:alpine
Copy link

Choose a reason for hiding this comment

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

Можно просто взять базовый образ.

1 change: 1 addition & 0 deletions hw1/redis/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG SET requirepass ``
Loading