feat: trying to docker
This commit is contained in:
parent
6c206fa756
commit
9f903ce255
71
docker/docker-compose.yml
Executable file
71
docker/docker-compose.yml
Executable file
@ -0,0 +1,71 @@
|
||||
services:
|
||||
mariadb:
|
||||
container_name: mariadb
|
||||
build:
|
||||
context: ./mariadb
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
HOST_UID: ${HOST_UID:-1000}
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=password
|
||||
- MYSQL_DATABASE=wordpress
|
||||
- MYSQL_USER=wp_user
|
||||
- MYSQL_PASSWORD=password
|
||||
- HOST_UID=${HOST_UID:-1000}
|
||||
networks:
|
||||
- docker-network
|
||||
volumes:
|
||||
- data_mariadb:/var/lib/mysql
|
||||
restart: unless-stopped
|
||||
|
||||
webserv:
|
||||
container_name: webserv
|
||||
build:
|
||||
context: ./webserv
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
HOST_UID: ${HOST_UID:-1000}
|
||||
depends_on:
|
||||
- mariadb
|
||||
environment:
|
||||
# - DOMAIN_NAME=${DOMAIN_NAME}
|
||||
|
||||
- DB_HOST=mariadb
|
||||
- DB_PORT=3306
|
||||
|
||||
- MYSQL_DATABASE=wordpress
|
||||
- MYSQL_USER=wp_user
|
||||
- MYSQL_PASSWORD=password
|
||||
|
||||
- WP_TITLE="webserv blog"
|
||||
- WP_DESCRIPTION=""
|
||||
#- WP_THEME=
|
||||
|
||||
- WP_ADMIN=admin
|
||||
- WP_ADMIN_PASSWORD=admin
|
||||
- WP_ADMIN_EMAIL=admin@admin.admin
|
||||
networks:
|
||||
- docker-network
|
||||
volumes:
|
||||
- data_wordpress:/var/www/html
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
docker-network:
|
||||
name: docker-network
|
||||
|
||||
volumes:
|
||||
data_mariadb:
|
||||
name: data_mariadb
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: none
|
||||
device: /home/kali/data/mariadb
|
||||
o: bind
|
||||
data_wordpress:
|
||||
name: data_wordpress
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: none
|
||||
device: /home/kali/data/wordpress
|
||||
o: bind
|
||||
29
docker/mariadb/Dockerfile
Executable file
29
docker/mariadb/Dockerfile
Executable file
@ -0,0 +1,29 @@
|
||||
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache \
|
||||
mariadb \
|
||||
mariadb-client && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
ARG HOST_UID
|
||||
|
||||
RUN addgroup -S -g $HOST_UID mariadb && \
|
||||
adduser -S -u $HOST_UID mariadb -G mariadb
|
||||
|
||||
RUN mkdir -p /var/run/mysqld && \
|
||||
chown -R mariadb:mariadb /var/run/mysqld && \
|
||||
chown -R mariadb:mariadb /var/lib/mysql && \
|
||||
chmod -R 750 /var/lib/mysql
|
||||
|
||||
COPY ./tools/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
COPY ./conf/my.cnf /etc/my.cnf
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
WORKDIR /var/lib/mysql
|
||||
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
|
||||
CMD ["mysqld", "--datadir=/var/lib/mysql", "--user=mariadb"]
|
||||
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=1 CMD mysqladmin ping -h localhost || exit 1
|
||||
5
docker/mariadb/conf/my.cnf
Normal file
5
docker/mariadb/conf/my.cnf
Normal file
@ -0,0 +1,5 @@
|
||||
[mysqld]
|
||||
port=3306
|
||||
bind-address=0.0.0.0
|
||||
datadir=/var/lib/mysql
|
||||
pid-file=/var/run/mysqld/mysqld.pid
|
||||
19
docker/mariadb/tools/docker-entrypoint.sh
Normal file
19
docker/mariadb/tools/docker-entrypoint.sh
Normal file
@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ "$1" = 'mysqld' ] && [ ! -d "/var/lib/mysql/mysql" ]; then
|
||||
mysql_install_db --user=mariadb --datadir=/var/lib/mysql --rpm
|
||||
mysqld --user=mariadb --skip-networking &
|
||||
pid=$!
|
||||
while ! mysqladmin ping --silent; do sleep 1; done
|
||||
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';"
|
||||
[ "$MYSQL_DATABASE" ] && mysql -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\`;"
|
||||
[ "$MYSQL_USER" ] && [ "$MYSQL_PASSWORD" ] && \
|
||||
mysql -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" && \
|
||||
mysql -e "GRANT ALL PRIVILEGES ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'%';"
|
||||
mysql -e "FLUSH PRIVILEGES;"
|
||||
# [ -f "/usr/bin/local/init.sql" ] && mysql "${MYSQL_DATABASE}" < /usr/bin/local/init.sql
|
||||
kill "$pid" && wait "$pid"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
77
docker/webserv/Dockerfile
Executable file
77
docker/webserv/Dockerfile
Executable file
@ -0,0 +1,77 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
# Set environment variables for non-interactive installation
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install development tools in one layer
|
||||
RUN apt-get update && apt-get install -y \
|
||||
# Build essentials
|
||||
build-essential \
|
||||
# Clang 12 toolchain
|
||||
clang-12 \
|
||||
clang++-12 \
|
||||
clang-format-12 \
|
||||
clang-tidy-12 \
|
||||
clangd \
|
||||
lldb \
|
||||
# Build tools
|
||||
cmake \
|
||||
make \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
# Version control and utilities
|
||||
git \
|
||||
curl \
|
||||
unzip \
|
||||
# Development utilities
|
||||
gdb \
|
||||
valgrind \
|
||||
strace \
|
||||
# Network tools for web server testing
|
||||
netcat \
|
||||
telnet \
|
||||
# Text processing
|
||||
vim \
|
||||
nano \
|
||||
# Include What You Use
|
||||
iwyu \
|
||||
php-cgi \
|
||||
# Clean up
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set up Clang 12 alternatives
|
||||
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 \
|
||||
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 \
|
||||
&& update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 100 \
|
||||
&& update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100
|
||||
|
||||
# Set environment variables
|
||||
ENV CC=clang-12
|
||||
ENV CXX=clang++-12
|
||||
|
||||
RUN git clone https://github.com/WHaffmans/webserv.git
|
||||
|
||||
RUN cd webserv && make
|
||||
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
php \
|
||||
php-cgi \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir /webserv
|
||||
|
||||
COPY --from=0 /webserv/build/webserv /webserv/.
|
||||
|
||||
COPY ./conf/default.conf /webserv/.
|
||||
|
||||
COPY ./conf/hosts /etc/hosts
|
||||
|
||||
# RUN chmod 777 /webserv/default.conf
|
||||
|
||||
RUN mkdir /logs && touch /logs/webserv.log
|
||||
|
||||
CMD ["./webserv/webserv", "/webserv/default.conf"]
|
||||
129
docker/webserv/conf/default.conf
Executable file
129
docker/webserv/conf/default.conf
Executable file
@ -0,0 +1,129 @@
|
||||
server {
|
||||
listen 8080;
|
||||
host 0.0.0.0;
|
||||
server_name localhost;
|
||||
|
||||
root ./htdocs/site-1/;
|
||||
index index.html index.htm;
|
||||
|
||||
error_page 400 ./htdocs/error_pages/400.html;
|
||||
error_page 404 ./htdocs/error_pages/404.html;
|
||||
error_page 404 ./htdocs/error_pages/404.html;
|
||||
error_page 403 ./htdocs/error_pages/403.html;
|
||||
error_page 405 ./htdocs/error_pages/405.html;
|
||||
error_page 413 ./htdocs/error_pages/413.html;
|
||||
error_page 500 ./htdocs/error_pages/500.html;
|
||||
error_page 502 ./htdocs/error_pages/502.html;
|
||||
error_page 504 ./htdocs/error_pages/504.html;
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
location / {
|
||||
autoindex off;
|
||||
root ./htdocs/site-1/;
|
||||
index index2.html index.html;
|
||||
allowed_methods GET POST DELETE;
|
||||
}
|
||||
|
||||
# location /uploads {
|
||||
# root /var/www/uploads;
|
||||
# autoindex on;
|
||||
# allowed_methods GET POST;
|
||||
# }
|
||||
|
||||
location /images {
|
||||
root ./htdocs/site-1/img;
|
||||
autoindex off;
|
||||
index index.jpg;
|
||||
allowed_methods GET;
|
||||
}
|
||||
|
||||
location /test {
|
||||
root ./htdocs/site-1/tester;
|
||||
autoindex off;
|
||||
index test.html;
|
||||
allowed_methods GET;
|
||||
}
|
||||
|
||||
location /redirect {
|
||||
redirect 301 http://localhost:8081/;
|
||||
allowed_methods GET POST;
|
||||
}
|
||||
|
||||
location /autoindex {
|
||||
root ./htdocs/site-1;
|
||||
autoindex on;
|
||||
allowed_methods GET;
|
||||
index index2.html;
|
||||
}
|
||||
|
||||
location /upload {
|
||||
upload_store ./htdocs/site-1/uploads/;
|
||||
allowed_methods POST;
|
||||
}
|
||||
|
||||
location /uploads {
|
||||
root ./htdocs/site-1/uploads/;
|
||||
autoindex on;
|
||||
allowed_methods GET;
|
||||
}
|
||||
|
||||
cgi_enabled yes;
|
||||
cgi_handler .php /usr/bin/php-cgi;
|
||||
# cgi_handler .php /usr/bin/php-cgi;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8081;
|
||||
host 127.0.0.1;
|
||||
server_name localhost;
|
||||
|
||||
root ./htdocs/site-2/;
|
||||
index index.html index2.htm;
|
||||
|
||||
client_max_body_size 1M;
|
||||
|
||||
location / {
|
||||
autoindex off;
|
||||
root ./htdocs/site-2/;
|
||||
index index.html;
|
||||
allowed_methods GET POST DELETE;
|
||||
}
|
||||
|
||||
# location /2uploads {
|
||||
# root /var/www/uploads;
|
||||
# autoindex on;
|
||||
# allowed_methods GET POST;
|
||||
# }
|
||||
|
||||
# location /2images {
|
||||
# root /var/www/images;
|
||||
# autoindex off;
|
||||
# index index.jpg;
|
||||
# allowed_methods GET;
|
||||
# }
|
||||
|
||||
# cgi_enabled yes;
|
||||
cgi_handler .php /usr/bin/php-cgi;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8082;
|
||||
host 127.0.0.1;
|
||||
server_name localhost;
|
||||
|
||||
root ./htdocs/site-3/;
|
||||
index index.html index2.htm;
|
||||
|
||||
client_max_body_size 1M;
|
||||
|
||||
location / {
|
||||
autoindex off;
|
||||
index index.php;
|
||||
allowed_methods GET POST DELETE;
|
||||
}
|
||||
|
||||
cgi_enabled yes;
|
||||
cgi_handler .php /usr/bin/php-cgi;
|
||||
cgi_handler .cgi;
|
||||
}
|
||||
1
docker/webserv/conf/hosts
Executable file
1
docker/webserv/conf/hosts
Executable file
@ -0,0 +1 @@
|
||||
127.0.0.1 localhost 42.fr qmennen.42.fr whaffman.42.fr wordpress.com
|
||||
Loading…
Reference in New Issue
Block a user