-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: AGaliy/main
Are you sure you want to change the base?
hw1 #1166
Changes from 1 commit
8c825a8
baa8286
81ea5ce
e7173da
e0d193b
0183dff
d7dc808
a44afba
a3a6672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
echo "Привет, Otus!<br>".date("Y-m-d H:i:s") ."<br><br>"; | ||
Check failure on line 3 in hw1/code/index.php GitHub Actions / phpcs
Check failure on line 3 in hw1/code/index.php GitHub Actions / phpcs
|
||
|
||
// Параметры подключения к базе данных | ||
$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; | ||
$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"; | ||
} | ||
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 |
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"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
session.save_handler = memcache | ||
session.save_path = "tcp://memcache:11211" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM memcached:latest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно просто взять базовый образ. |
||
CMD ["memcached", "-D"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM mysql:8.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] |
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"); |
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;"] |
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM redis:alpine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно просто взять базовый образ. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG SET requirepass `` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поправьте все замечания линтера.