Compare commits
10 commits
663aefc782
...
4a60057513
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a60057513 | ||
|
|
778e1a9056 | ||
|
|
b20e81b0fe | ||
|
|
387238065d | ||
|
|
5ea86b3b51 | ||
|
|
aaa7dc3e23 | ||
|
|
3ca8a96aa7 | ||
|
|
9383276ddc | ||
|
|
971f30f8f1 | ||
|
|
7a00c7fc45 |
12 changed files with 250 additions and 30 deletions
55
Makefile
55
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2025/06/12 18:09:23 by rparodi #+# #+# #
|
# Created: 2025/06/12 18:09:23 by rparodi #+# #+# #
|
||||||
# Updated: 2025/06/14 18:26:21 by rparodi ### ########.fr #
|
# Updated: 2025/06/27 17:23:54 by rparodi ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -34,10 +34,10 @@ all: header get_secret build footer
|
||||||
build:
|
build:
|
||||||
docker compose -f $(MAIN)/docker-compose.yml up --build -d
|
docker compose -f $(MAIN)/docker-compose.yml up --build -d
|
||||||
|
|
||||||
stop:
|
stop: header
|
||||||
@docker compose -f $(MAIN)/docker-compose.yml down
|
@docker compose -f $(MAIN)/docker-compose.yml stop
|
||||||
@if [ $(shell docker ps -q | wc -l) -ne 0 ]; then \
|
@if [ $(shell docker ps -q | wc -l) -ne 0 ]; then \
|
||||||
docker stop $(docker ps -q); \
|
docker stop $(shell docker ps -q); \
|
||||||
fi
|
fi
|
||||||
@printf '$(GREY)Stopping all the $(RED)Containers$(END)\n';
|
@printf '$(GREY)Stopping all the $(RED)Containers$(END)\n';
|
||||||
|
|
||||||
|
|
@ -66,15 +66,16 @@ wordpress:
|
||||||
docker build -t wordpress-test $(WORDPRESS)
|
docker build -t wordpress-test $(WORDPRESS)
|
||||||
|
|
||||||
get_secret:
|
get_secret:
|
||||||
@if [ ! -d $(SECRET) ]; then \
|
|
||||||
printf "$(RED)The secrets home folder doesn't exist$(END)\n"; \
|
#@if [ ! -d $(SECRET) ]; then \
|
||||||
exit 1; \
|
# printf "$(RED)The secrets home folder doesn't exist$(END)\n"; \
|
||||||
elif [ ! -d $(shell pwd)/secrets ]; then \
|
# exit 1; \
|
||||||
cp -r $(SECRET) $(shell pwd)/secrets; \
|
#elif [ ! -d $(shell pwd)/secrets ]; then \
|
||||||
printf '$(GREY)Creating the folder $(GREEN)$(shell pwd)/secrets$(END)\n'; \
|
# cp -r $(SECRET) $(shell pwd)/secrets; \
|
||||||
else \
|
# printf '$(GREY)Creating the folder $(GREEN)$(shell pwd)/secrets$(END)\n'; \
|
||||||
printf '$(GREY)The secrets is $(RED)already existing$(END)\n'; \
|
#else \
|
||||||
fi
|
# printf '$(GREY)The secrets is $(RED)already existing$(END)\n'; \
|
||||||
|
#fi
|
||||||
|
|
||||||
clean: stop
|
clean: stop
|
||||||
@printf '$(GREY)Suppressing all the $(RED)Containers$(END)\n';
|
@printf '$(GREY)Suppressing all the $(RED)Containers$(END)\n';
|
||||||
|
|
@ -83,25 +84,25 @@ clean: stop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
@if [ $(shell docker images -aq | wc -l) -ne 0 ]; then \
|
docker image prune -f -a
|
||||||
docker rmi -f $(shell docker images -aq); \
|
|
||||||
fi
|
|
||||||
@printf '$(GREY)Suppressing all the $(RED)Images$(END)\n';
|
@printf '$(GREY)Suppressing all the $(RED)Images$(END)\n';
|
||||||
@if [ $(shell docker volume ls -q | wc -l) -ne 0 ]; then \
|
docker volume prune -fa
|
||||||
docker volume rm $(shell docker volume ls -q); \
|
|
||||||
fi
|
|
||||||
@printf '$(GREY)Suppressing all the $(RED)Volumes$(END)\n';
|
@printf '$(GREY)Suppressing all the $(RED)Volumes$(END)\n';
|
||||||
@if [ $(shell docker network ls | grep -v "bridge\|host\|none\|NETWORK" | awk '{print $1}' | wc -l) -ne 0 ]; then \
|
docker system prune -f -a
|
||||||
docker network rm $(shell docker network ls | grep -v "bridge\|host\|none\|NETWORK" | awk '{print $1}'); \
|
|
||||||
fi
|
|
||||||
@printf '$(GREY)Suppressing all the $(RED)Network$(END)\n';
|
@printf '$(GREY)Suppressing all the $(RED)Network$(END)\n';
|
||||||
|
|
||||||
re: header fclean all footer
|
re: header fclean all footer
|
||||||
|
|
||||||
setup_vm:
|
setup_vm: header
|
||||||
sudo $(PACK_MAN) docker docker-compose
|
@echo "127.0.0.1 rparodi.42.fr" | sudo tee -a /etc/hosts &> /dev/null
|
||||||
sudo usermod -aG docker $(shell whoami)
|
@printf "$(GREY)Adding the custom host $(GREEN)rparodi.42.fr$(END)\n";
|
||||||
@printf '$(GREY)Virtual Machine now$(GREEN)setuped$(END)\n'; \
|
@sudo $(PACK_MAN) docker docker-compose docker-buildx &> /dev/null
|
||||||
|
@printf "$(GREY)Install the $(GREEN)docker docker-compose docker-buildx packages$(END)\n";
|
||||||
|
@sudo usermod -aG docker $(shell whoami)
|
||||||
|
@printf "$(GREY)User add to the $(GREEN)docker's group$(END)\n";
|
||||||
|
@printf "$(GREY)Virtual Machine now $(GOLD)setuped$(END)\n";
|
||||||
|
|
||||||
|
setup: setup_vm
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
header:
|
header:
|
||||||
|
|
@ -135,4 +136,4 @@ footer:
|
||||||
@printf ' $(GREY)The build is $(GOLD)finished$(END)\n $(GREY)Have a good $(GOLD)evaluation !$(END)\n'
|
@printf ' $(GREY)The build is $(GOLD)finished$(END)\n $(GREY)Have a good $(GOLD)evaluation !$(END)\n'
|
||||||
|
|
||||||
# Phony
|
# Phony
|
||||||
.PHONY: all nginx mariadb wordpress get_secret clean fclean re
|
.PHONY: all nginx mariadb wordpress get_secret clean fclean re setup setup_vm
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
### Usefull links
|
### Usefull links
|
||||||
(Docker)[https://docs.docker.com/reference/]
|
- [Docker](https://docs.docker.com/reference/)
|
||||||
(MariaDB)[https://mariadb.com/kb/en/creating-a-custom-container-image/]
|
- [MariaDB](https://mariadb.com/kb/en/creating-a-custom-container-image/)
|
||||||
(Nginx)[https://nginx.org/en/docs/beginners_guide.html]
|
- [Nginx](https://nginx.org/en/docs/beginners_guide.html)
|
||||||
|
|
|
||||||
54
srcs/docker-compose.yml
Normal file
54
srcs/docker-compose.yml
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
services:
|
||||||
|
|
||||||
|
mariadb:
|
||||||
|
build: ./requirements/mariadb
|
||||||
|
container_name: mariadb
|
||||||
|
image: mariadb
|
||||||
|
env_file:
|
||||||
|
- ../secrets/.env
|
||||||
|
volumes:
|
||||||
|
- wp_db:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- inception
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
wordpress:
|
||||||
|
container_name: wordpress
|
||||||
|
image: wordpress
|
||||||
|
build: ./requirements/wordpress
|
||||||
|
env_file:
|
||||||
|
- ../secrets/.env
|
||||||
|
depends_on:
|
||||||
|
- mariadb
|
||||||
|
ports:
|
||||||
|
- 9000:9000
|
||||||
|
volumes:
|
||||||
|
- wp_files:/var/www/html
|
||||||
|
networks:
|
||||||
|
- inception
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
container_name: nginx
|
||||||
|
image: nginx
|
||||||
|
env_file:
|
||||||
|
- ../secrets/.env
|
||||||
|
build: ./requirements/nginx
|
||||||
|
extra_hosts:
|
||||||
|
- "rparodi.42.fr:127.0.0.1"
|
||||||
|
ports:
|
||||||
|
- 443:443
|
||||||
|
volumes:
|
||||||
|
- wp_files:/var/www/html
|
||||||
|
depends_on:
|
||||||
|
- wordpress
|
||||||
|
networks:
|
||||||
|
- inception
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
wp_files:
|
||||||
|
wp_db:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
inception:
|
||||||
|
driver: bridge
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
RUN apk update && apk add sudo mariadb mariadb-client bash;
|
||||||
|
|
||||||
|
RUN mkdir -p /var/lib/mysqld;
|
||||||
|
RUN mkdir -p /run/mysqld;
|
||||||
|
RUN chown -R mysql:mysql /run/mysqld;
|
||||||
|
RUN chown -R mysql:mysql /var/lib/mysqld;
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
|
||||||
|
RUN /usr/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql;
|
||||||
|
|
||||||
|
COPY tools/start_db.sh /usr/bin/start_db
|
||||||
|
RUN chmod +x /usr/bin/start_db;
|
||||||
|
|
||||||
|
CMD ["start_db"]
|
||||||
19
srcs/requirements/mariadb/tools/start_db.sh
Normal file
19
srcs/requirements/mariadb/tools/start_db.sh
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
sudo -u mysql -s /bin/sh -c mysqld &
|
||||||
|
PID=$!
|
||||||
|
|
||||||
|
mariadb-admin status --wait
|
||||||
|
|
||||||
|
mariadb -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};"
|
||||||
|
mariadb -e "CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';"
|
||||||
|
mariadb -e "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'%';"
|
||||||
|
mariadb -e "FLUSH PRIVILEGES;"
|
||||||
|
|
||||||
|
sudo -u mysql -s /bin/sh -c "mysqladmin shutdown"
|
||||||
|
wait "$PID"
|
||||||
|
|
||||||
|
sed -i /etc/my.cnf.d/mariadb-server.cnf -e 's/^port=3307$/\0\nbind-address = 0.0.0.0/'
|
||||||
|
sed -i /etc/my.cnf.d/mariadb-server.cnf -e 's/^skip-networking$/;\0/'
|
||||||
|
|
||||||
|
exec sudo -u mysql -s /bin/sh -c mysqld
|
||||||
0
srcs/requirements/nginx/.dockerignore
Normal file
0
srcs/requirements/nginx/.dockerignore
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
RUN apk update
|
||||||
|
RUN apk add nginx openssl bash
|
||||||
|
|
||||||
|
RUN mkdir -p /run/nginx /etc/nginx/ssl
|
||||||
|
|
||||||
|
RUN rm -rf /var/www/html;
|
||||||
|
COPY conf/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY tools/generate_ssl_certificate.sh /usr/bin/generate_ssl_certificate
|
||||||
|
|
||||||
|
RUN chmod +x /usr/bin/generate_ssl_certificate
|
||||||
|
|
||||||
|
EXPOSE 443
|
||||||
|
|
||||||
|
CMD ["generate_ssl_certificate"]
|
||||||
52
srcs/requirements/nginx/conf/nginx.conf
Normal file
52
srcs/requirements/nginx/conf/nginx.conf
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
# /etc/nginx/nginx.conf
|
||||||
|
# disable daemonization
|
||||||
|
daemon off;
|
||||||
|
# basically the default config. stolen from the container before overriting
|
||||||
|
error_log stderr info;
|
||||||
|
pcre_jit on;
|
||||||
|
# user wordpress;
|
||||||
|
worker_processes auto;
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
http {
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
server_tokens off;
|
||||||
|
client_max_body_size 1m;
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_session_cache shared:SSL:2m;
|
||||||
|
ssl_session_timeout 1h;
|
||||||
|
ssl_session_tickets off;
|
||||||
|
gzip_vary on;
|
||||||
|
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
access_log stderr;
|
||||||
|
# end of default server
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
listen [::]:443 ssl;
|
||||||
|
server_name rparodi.42.fr;
|
||||||
|
|
||||||
|
ssl_certificate /etc/nginx/ssl/nginx.crt;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/nginx.key;
|
||||||
|
ssl_protocols TLSv1.3;
|
||||||
|
index index.php;
|
||||||
|
root /var/www/html;
|
||||||
|
location ~ [^/]\.php(/|$) {
|
||||||
|
try_files $uri =404;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_pass wordpress:9000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ ! -f "$CERT_DIR/nginx.key" ]; then
|
||||||
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=FR/ST=Paris/L=42/O=Students/OU=Inception/CN=rparodi.42.fr"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec nginx
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
RUN apk update && apk add php82-curl php82-gd php82-mbstring php82-session php82-opcache php82-zlib bash wget php82 php82-phar php82-mysqli php82-fpm mariadb-client;
|
||||||
|
|
||||||
|
# RUN wget https://wordpress.org/latest.tar.gz -O /tmp/wp.tar.gz
|
||||||
|
|
||||||
|
RUN mkdir -p /var/www/html;
|
||||||
|
|
||||||
|
RUN wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /bin/wp-cli.phar;
|
||||||
|
RUN chmod +x /bin/wp-cli.phar;
|
||||||
|
RUN mv /bin/wp-cli.phar /bin/wp;
|
||||||
|
|
||||||
|
RUN ln -s /usr/bin/php82 /usr/bin/php;
|
||||||
|
RUN ln -s /usr/sbin/php-fpm82 /usr/sbin/php-fpm;
|
||||||
|
|
||||||
|
RUN adduser -D wordpress -g wordpress;
|
||||||
|
RUN chown wordpress:wordpress -R /var/www/html;
|
||||||
|
RUN chmod -R +rw /var/www/html;
|
||||||
|
RUN chmod -R +rw /var/log/php82/;
|
||||||
|
|
||||||
|
COPY tools/install.sh /usr/bin/install-wp
|
||||||
|
RUN chmod +x /usr/bin/install-wp;
|
||||||
|
|
||||||
|
COPY ./conf/php-fpm.conf /etc/php82/php-fpm.d/www.conf
|
||||||
|
RUN sed -i 's/^memory_limit\s*=.*/memory_limit = 1024M/' /etc/php82/php.ini;
|
||||||
|
USER wordpress
|
||||||
|
|
||||||
|
CMD ["install-wp"]
|
||||||
14
srcs/requirements/wordpress/conf/php-fpm.conf
Normal file
14
srcs/requirements/wordpress/conf/php-fpm.conf
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[global]
|
||||||
|
daemonize = false
|
||||||
|
error_log = /dev/stderr
|
||||||
|
|
||||||
|
[www]
|
||||||
|
listen = 0.0.0.0:9000
|
||||||
|
|
||||||
|
pm = dynamic
|
||||||
|
pm.max_children = 25
|
||||||
|
pm.start_servers = 5
|
||||||
|
pm.min_spare_servers = 1
|
||||||
|
pm.max_spare_servers = 10
|
||||||
|
access.log = /dev/stderr
|
||||||
|
catch_workers_output = yes
|
||||||
12
srcs/requirements/wordpress/tools/install.sh
Normal file
12
srcs/requirements/wordpress/tools/install.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -xe
|
||||||
|
mysqladmin --host=mariadb --port=3306 --user="$DB_USER" --password="$DB_PASSWORD" --wait status
|
||||||
|
|
||||||
|
if ! [ -e /var/www/html/wp-config.php ]; then
|
||||||
|
wp core download --locale=fr_FR --allow-root --path=/var/www/html
|
||||||
|
wp config create --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASSWORD --dbhost=$DB_HOST --skip-check --path=/var/www/html --allow-root
|
||||||
|
wp core install --url=$DOMAIN --title="$WP_TITLE" --admin_user=$WP_ADMIN --admin_password=$WP_PASS_ADMIN --admin_email=$WP_MAIL_ADMIN --path=/var/www/html --allow-root
|
||||||
|
wp user create "$WP_USER" "$WP_MAIL" --user_pass="$WP_PASS" --role=editor --path=/var/www/html
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec php-fpm -F
|
||||||
Loading…
Add table
Add a link
Reference in a new issue