diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7958fac --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__* +.__* diff --git a/Makefile b/Makefile index 2287ed3..9695171 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,14 @@ # TODO(vm) data is supposed to be in $HOME/data/ +WWW_PATH=__www/ # TODO to change +BUILD_PATH=__build/ + DOCKER=docker SRC_COMPOSE=srcs/ .ONESHELL : .SHELLFLAGS = -eu -c -.PHONY : run help +.PHONY : run install uninstall debug re help shell ### pretty logs #### @@ -19,25 +22,71 @@ _ECHO = echoo(){ \ ## Run the compose. -run : +run : $(WWW_PATH) @$(_ECHO) echoo "Running '$(SRC_COMPOSE)'..." - echo "$ cd -- $(SRC_COMPOSE)" cd -- $(SRC_COMPOSE) - echo "$ $(DOCKER) compose up --build" - $(DOCKER) compose up --build + INCEPTION_WWW_PATH="$(shell realpath $(WWW_PATH))" $(DOCKER) compose up --build -## Run the compose with debug flags. -debug : - $(MAKE) DEBUG=yes run +## Create WWW_PATH from wordpress' release. +install : $(WWW_PATH) + + +$(WWW_PATH) : + @$(_ECHO) + + echoo "Creating $(WWW_PATH) directory from wordpress release..." + + rm -rf $(BUILD_PATH) + + # download and uncompress release + mkdir -p $(BUILD_PATH)"/www/" + curl https://wordpress.org/latest.tar.gz | tar zx -C $(BUILD_PATH)/www + + # move in WWW_PATH + rm -rf -- $(WWW_PATH) + mv $(BUILD_PATH)"/www/wordpress" $(WWW_PATH) + + rm -rf $(BUILD_PATH) + + +## Remove WWW_PATH. +uninstall : + @$(_ECHO) + + echoo "Removing $(WWW_PATH)..." + rm -r $(WWW_PATH) || true + + +## 'uninstall' then 'install' +re : uninstall install + @$(_ECHO) + echo + echo "run \`make\` or \`make run\` to run the docker." + + +## TODO docs +shell : + @$(_ECHO) + + echoo "Running shell inside '$(SRC_COMPOSE)' (container nginx)..." + cd -- $(SRC_COMPOSE) + INCEPTION_WWW_PATH="$(shell realpath $(WWW_PATH))" $(DOCKER) compose run --build nginx sh ## Show help help : @$(_ECHO) - echo "run Run the compose." - echo "debug Run the compose with debug flags." - echo "That's all lol" + echo + echo "run Run the compose, install WWW_PATH if necessary." + echo "install Create WWW_PATH from wordpress' release." + echo "uninstall Remove WWW_PATH." + echo "re 'uninstall' then 'install'." + # TODO docs shell + echo + echo "WWW_PATH is the volume directory where WordPress is installed." + echo "you might want to reset the WWW_PATH variable in the Makefile." + echo diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 7d1b4a9..9455888 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -6,8 +6,25 @@ services: build: ./requirements/nginx/ ports: - 4433:443 + depends_on: + - wordpress + volumes: + - www:/www:ro # domainname: mcolonna.42.fr # TODO(vm) useful? # TODO(any)(nocopy) + wordpress: + build: ./requirements/wordpress + volumes: + - www:/www:rw + +volumes: + www: + driver: local + driver_opts: + o: bind + type: none + device: "${INCEPTION_WWW_PATH:?error}" + ### services ### # image: # build: diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index ac5fb93..1a5d8b2 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -26,8 +26,6 @@ RUN apk fix # add config RUN rm /etc/nginx/nginx.conf COPY conf/ /etc/nginx/ -RUN rm -r /usr/share/nginx/html -COPY www/ /usr/share/nginx/html # start CMD ["nginx", "-g", "daemon off;"] diff --git a/srcs/requirements/nginx/conf/nginx.conf b/srcs/requirements/nginx/conf/nginx.conf index fc74893..08917f1 100644 --- a/srcs/requirements/nginx/conf/nginx.conf +++ b/srcs/requirements/nginx/conf/nginx.conf @@ -35,12 +35,16 @@ http { access_log /var/log/nginx/mcolonna.42.fr.access.log main; location / { - root /usr/share/nginx/html; - index index.html index.htm; + root /www; + index index.php; + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass wordpress:9000; + } } # TODO(more) error_page 404 /404.html; # TODO(more) error_page 500 502 503 504 /50x.html; } } - diff --git a/srcs/requirements/nginx/conf/snippets/fastcgi-php.conf b/srcs/requirements/nginx/conf/snippets/fastcgi-php.conf new file mode 100644 index 0000000..5ed9d38 --- /dev/null +++ b/srcs/requirements/nginx/conf/snippets/fastcgi-php.conf @@ -0,0 +1,15 @@ +# from https://exampleconfig.com/view/nginx-ubuntu20-04-etc-nginx-snippets-fastcgi-php-conf + +# regex to split $uri to $fastcgi_script_name and $fastcgi_path +fastcgi_split_path_info ^(.+?\.php)(/.*)$; + +# Check that the PHP script exists before passing it +try_files $fastcgi_script_name =404; + +# Bypass the fact that try_files resets $fastcgi_path_info +# see: http://trac.nginx.org/nginx/ticket/321 +set $path_info $fastcgi_path_info; +fastcgi_param PATH_INFO $path_info; + +fastcgi_index index.php; +include fastcgi.conf; \ No newline at end of file diff --git a/srcs/requirements/nginx/www/VarelaRound.ttf b/srcs/requirements/nginx/www/VarelaRound.ttf deleted file mode 100644 index 9d01812..0000000 Binary files a/srcs/requirements/nginx/www/VarelaRound.ttf and /dev/null differ diff --git a/srcs/requirements/nginx/www/index.html b/srcs/requirements/nginx/www/index.html deleted file mode 100644 index dc17481..0000000 --- a/srcs/requirements/nginx/www/index.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - yippee - - - -
yippee
-
yippee
-
yippee
- - diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile new file mode 100644 index 0000000..d51e8e8 --- /dev/null +++ b/srcs/requirements/wordpress/Dockerfile @@ -0,0 +1,24 @@ +# TODO(any)(latest) +FROM alpine:latest + +# EXPOSE +EXPOSE 9000 + +# install packages +RUN apk update +RUN apk add php-fpm +RUN apk fix + +RUN addgroup -S www +RUN adduser -D -S -G www www + +#RUN apk add curl +# install wordpress +# RUN mkdir -p /www +# RUN curl https://wordpress.org/latest.tar.gz | tar zx -C /www + +# add config +COPY /conf/ /etc/php83/ + +# start +CMD ["php-fpm83", "-F"] diff --git a/srcs/requirements/wordpress/conf/php-fpm.conf b/srcs/requirements/wordpress/conf/php-fpm.conf new file mode 100644 index 0000000..c587bf2 --- /dev/null +++ b/srcs/requirements/wordpress/conf/php-fpm.conf @@ -0,0 +1 @@ +include=/etc/php83/php-fpm.d/*.conf diff --git a/srcs/requirements/wordpress/conf/php-fpm.d/www.conf b/srcs/requirements/wordpress/conf/php-fpm.d/www.conf new file mode 100644 index 0000000..273c434 --- /dev/null +++ b/srcs/requirements/wordpress/conf/php-fpm.d/www.conf @@ -0,0 +1,11 @@ +[www] + +user = www +group = www +listen = wordpress:9000 + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3