diff --git a/Makefile b/Makefile index 3f90f39..aa3efe8 100644 --- a/Makefile +++ b/Makefile @@ -8,19 +8,11 @@ DOCKERFILE_DB := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(DB_SERVER_NAME)/Dockerfile DOCKERFILE_WEVSRV := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(WEB_SERVER_NAME)/Dockerfile DOCKERFILE_CMS := $(DOCKER_CONTEXT)$(DOCKER_FOLDER)/$(CMS_NAME)/Dockerfile -dev: - docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build +include srcs/docker/composes/dev/dev.mk +include srcs/docker/composes/correction.mk +include srcs/docker/composes/prod.mk -prod: - docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build - -all: dev - -stop: - docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml stop - -stop-prod: - docker compose -f $(DOCKER_CONTEXT)docker-compose-prod.yml stop +all: setup-corr correction clean: stop docker system prune @@ -30,4 +22,4 @@ fclean: clean re: clean all -.PHONY: cms-build db-build websrv-build clean-db clean-nginx +.PHONY: all clean fclean re diff --git a/srcs/configs/nginx/entry/cert-gen.sh b/srcs/configs/nginx/entry/cert-gen.sh index 56d276b..0793b3c 100755 --- a/srcs/configs/nginx/entry/cert-gen.sh +++ b/srcs/configs/nginx/entry/cert-gen.sh @@ -1,22 +1,8 @@ #!/bin/sh -if [ ! -v ${PRODUCTION} ]; then - if [ ! -f ${NGINX_SSL_KEY_FILE} ]; then - echo "Generating certs" - mkdir -p /etc/nginx/ssl - openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ${NGINX_SSL_KEY_FILE} -out ${NGINX_SSL_CERT_FILE} -subj "/C=FR/ST=IDF/L=Angouleme/O=42/OU=42/CN=adjoly.42.fr/UID=adjoly" - else - printf "Key already exist not recreating\n" - fi -else - printf "Entering production mode for nginx" - INPUT_FILE="/etc/nginx/http.d/www.conf" - OUTPUT_FILE="/etc/nginx/http.d/www.conf" - sed -E ' - s/listen\s+443 ssl;/listen 80;/; - s/server_name.*/&\n\tlisten 80;/; - /ssl_certificate/d; - /ssl_certificate_key/d; - /ssl_protocols/d; - /ssl_session_timeout/d; - ' "$INPUT_FILE" > "$OUTPUT_FILE" +if [ ! -f ${NGINX_SSL_KEY_FILE} ]; then + echo "Generating certs" + mkdir -p /etc/nginx/ssl + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ${NGINX_SSL_KEY_FILE} -out ${NGINX_SSL_CERT_FILE} -subj "/C=FR/ST=IDF/L=Angouleme/O=42/OU=42/CN=adjoly.42.fr/UID=adjoly" +else + printf "Key already exist not recreating\n" fi diff --git a/srcs/configs/nginx/templates-dev/www.conf.template b/srcs/configs/nginx/templates-dev/www.conf.template new file mode 100644 index 0000000..9cfccf9 --- /dev/null +++ b/srcs/configs/nginx/templates-dev/www.conf.template @@ -0,0 +1,24 @@ +server { + listen localhost:443 ssl; + + root /var/www/html; + index index.php; + + ssl_certificate $NGINX_SSL_CERT_FILE; + ssl_certificate_key $NGINX_SSL_KEY_FILE; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_session_timeout 10m; + + keepalive_timeout 60; + + location / { + try_files $${q}uri $${q}uri/ =404; + } + + location ~ \.php$ { + fastcgi_pass $NGINX_PHP_HOST:9000; + fastcgi_index index.php; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + include fastcgi.conf; + } +} diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 30223ab..34ca922 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -7,6 +7,12 @@ include: project_directory: ./ - path: ./docker/composes/db.yml project_directory: ./ + - path: ./docker/composes/dev/nginx.yml + project_directory: ./ + - path: ./docker/composes/dev/wordp-php.yml + project_directory: ./ + - path: ./docker/composes/dev/db.yml + project_directory: ./ networks: inception: diff --git a/srcs/docker/composes/correction.mk b/srcs/docker/composes/correction.mk new file mode 100644 index 0000000..3845d58 --- /dev/null +++ b/srcs/docker/composes/correction.mk @@ -0,0 +1,10 @@ +setup-corr: + mkdir -P $HOME/data + +correction: + docker compose --profile correction -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build + +stop: + docker compose --profile correction -f $(DOCKER_CONTEXT)docker-compose.yml stop + +.PHONY: stop correction setup-corr diff --git a/srcs/docker/composes/db.yml b/srcs/docker/composes/db.yml index c24eb42..9d8d7d9 100644 --- a/srcs/docker/composes/db.yml +++ b/srcs/docker/composes/db.yml @@ -18,3 +18,5 @@ services: volumes: - wp-db:/var/lib/mysql restart: unless-stopped + profiles: + - correction diff --git a/srcs/docker/composes/dev/db.yml b/srcs/docker/composes/dev/db.yml new file mode 100644 index 0000000..cc90501 --- /dev/null +++ b/srcs/docker/composes/dev/db.yml @@ -0,0 +1,19 @@ +services: + db-dev: + container_name: inception-db + build: + context: . + dockerfile: docker/images/mariadb/Dockerfile + networks: + - inception + environment: + - MYSQL_ROOT_PASSWORD="alpine" + - MYSQL_PASSWORD="alpine" + - MYSQL_USER="kanel" + - MYSQL_DATABASE="knl" + - TZ=Europe/Paris + volumes: + - wp-db:/var/lib/mysql + restart: unless-stopped + profiles: + - dev diff --git a/srcs/docker/composes/dev/dev.mk b/srcs/docker/composes/dev/dev.mk new file mode 100644 index 0000000..35d3264 --- /dev/null +++ b/srcs/docker/composes/dev/dev.mk @@ -0,0 +1,9 @@ +# those rules a for developement purposes + +dev: + docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build + +stop-dev: + docker compose --profile dev -f $(DOCKER_CONTEXT)docker-compose.yml stop + +.PHONY: dev stop-dev diff --git a/srcs/docker/composes/dev/nginx.yml b/srcs/docker/composes/dev/nginx.yml new file mode 100644 index 0000000..0a203c2 --- /dev/null +++ b/srcs/docker/composes/dev/nginx.yml @@ -0,0 +1,27 @@ +services: + nginx-dev: + container_name: inception-nginx + build: + context: . + dockerfile: docker/images/nginx/Dockerfile + networks: + - inception + environment: + - TZ=Europe/Paris + - NGINX_PHP_HOST=inception-wordp-php + - NGINX_SSL_KEY_FILE=/etc/nginx/ssl/adjoly-wp.key + - NGINX_SSL_CERT_FILE=/etc/nginx/ssl/adjoly-wp.crt + depends_on: + wordpress-php-dev: + condition: service_healthy + db-dev: + condition: service_healthy + volumes: + - wp-site:/var/www/html + - ./configs/nginx/templates-dev:/etc/nginx/templates + - ./configs/nginx/entry:/docker-entrypoint.d + ports: + - "443:443" + restart: unless-stopped + profiles: + - dev diff --git a/srcs/docker/composes/dev/wordp-php.yml b/srcs/docker/composes/dev/wordp-php.yml new file mode 100644 index 0000000..72373b1 --- /dev/null +++ b/srcs/docker/composes/dev/wordp-php.yml @@ -0,0 +1,24 @@ +volumes: + wp-site: + +services: + wordpress-php-dev: + container_name: inception-wordp-php + build: + context: . + dockerfile: docker/images/wordpress/Dockerfile + networks: + - inception + depends_on: + db-dev: + condition: service_healthy + environment: + - PHP_MEMORY_LIMIT="512M" + - PHP_MAX_UPLOAD="50M" + - PHP_PORT=9000 + - TZ=Europe/Paris + volumes: + - wp-site:/var/www/html + restart: unless-stopped + profiles: + - dev diff --git a/srcs/docker/composes/nginx.yml b/srcs/docker/composes/nginx.yml index 18b804e..926edc9 100644 --- a/srcs/docker/composes/nginx.yml +++ b/srcs/docker/composes/nginx.yml @@ -3,14 +3,14 @@ volumes: name: nginx-templates driver: local driver_opts: - device: ./configs/nginx/templates + device: $HOME/data/nginx/templates o: "bind,ro" type: none nginx-entry: name: nginx-entry driver: local driver_opts: - device: ./configs/nginx/entry + device: $HOME/data/nginx/entry o: "bind,ro" type: none @@ -41,3 +41,5 @@ services: ports: - "10443:443" restart: unless-stopped + profiles: + - correction diff --git a/srcs/docker/composes/prod.mk b/srcs/docker/composes/prod.mk new file mode 100644 index 0000000..56d1ebd --- /dev/null +++ b/srcs/docker/composes/prod.mk @@ -0,0 +1,9 @@ +# those are for production testing only do not execute in production environment + +prod: + docker compose -f $(DOCKER_CONTEXT)docker-compose.yml up -d --build + +stop-prod: + docker compose -f $(DOCKER_CONTEXT)docker-compose-prod.yml stop + +.PHONY: prod stop-prod diff --git a/srcs/docker/composes/wordp-php.yml b/srcs/docker/composes/wordp-php.yml index 3dc4577..0b45e48 100644 --- a/srcs/docker/composes/wordp-php.yml +++ b/srcs/docker/composes/wordp-php.yml @@ -20,3 +20,5 @@ services: volumes: - wp-site:/var/www/html restart: unless-stopped + profiles: + - correction