diff --git a/README.md b/README.md index 8df5988..d7b20f7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # inception +- will healthcheck continue after success, every 1 secondes ? +- change host file in virtual machine to connect to hulamy.42.fr instead of localhost +- machine virtual : xubuntu sur virtualbox (warning put enough place, like 30Go) +- maybe you need to put the virtual machine on sgoinfre in 42 --- ## WIP diff --git a/srcs/.env b/srcs/.env index d5903d2..cd011b5 100644 --- a/srcs/.env +++ b/srcs/.env @@ -5,9 +5,11 @@ LOGIN=$USER # MARIADB SETUP +DB_HOST=mariadb DB_NAME=db_wp_inception DB_USER=user_wp_inception DB_PSWD="if you read this i will have to erase your memory" +#ROOT_PSWD="root passphrase" # WORDPRESS SETUP diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index ab6d6e7..b24bb1b 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -16,6 +16,8 @@ services: ports: - "443:443" # - "80:80" + volumes: + - wp_volume:/var/www/html build: ./requirements/nginx image: nginx container_name: nginx_container @@ -28,14 +30,20 @@ services: env_file: .env networks: - inception -# volumes: -# - db_volume:/var/lib/mysql + volumes: + - db_volume:/var/lib/mysql build: context: ./requirements/mariadb args: + - DB_HOST=${DB_HOST} - DB_NAME=${DB_NAME} - DB_USER=${DB_USER} - DB_PSWD=${DB_PSWD} + healthcheck: + test: mariadb -h ${DB_HOST} -u ${DB_USER} -p"${DB_PSWD}" -e exit 2> /dev/null + interval: 1s + timeout: 10s + retries: 10 image: mariadb container_name: mariadb_container # --------------------------------- @@ -44,8 +52,8 @@ services: env_file: ./.env networks: - inception -# volumes: -# - wp_volume:/var/www/html + volumes: + - wp_volume:/var/www/html build: context: ./requirements/wordpress args: @@ -54,7 +62,7 @@ services: container_name: wordpress_container depends_on: mariadb: - condition: service_started + condition: service_healthy # specify path to named volumes : https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference volumes: diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile index 2796928..461e42f 100644 --- a/srcs/requirements/mariadb/Dockerfile +++ b/srcs/requirements/mariadb/Dockerfile @@ -30,6 +30,7 @@ # common ----------------------------------------------------- +ARG DB_HOST ARG DB_NAME ARG DB_USER ARG DB_PSWD @@ -41,9 +42,10 @@ RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql && \ # configure wp database COPY ./conf/create_db.sql /usr/bin/create_db.sql -RUN sed -i "s/\${DB_NAME}/${DB_NAME}/g" /usr/bin/create_db.sql -RUN sed -i "s/\${DB_USER}/${DB_USER}/g" /usr/bin/create_db.sql -RUN sed -i "s/\${DB_PSWD}/${DB_PSWD}/g" /usr/bin/create_db.sql +RUN sed -i "s/\${DB_HOST}/${DB_HOST}/g" /usr/bin/create_db.sql && \ + sed -i "s/\${DB_NAME}/${DB_NAME}/g" /usr/bin/create_db.sql && \ + sed -i "s/\${DB_USER}/${DB_USER}/g" /usr/bin/create_db.sql && \ + sed -i "s/\${DB_PSWD}/${DB_PSWD}/g" /usr/bin/create_db.sql ENTRYPOINT [ "mysqld", "--user=mysql", "--init-file=/usr/bin/create_db.sql" ] diff --git a/srcs/requirements/mariadb/conf/create_db.sql b/srcs/requirements/mariadb/conf/create_db.sql index 0067492..ce77300 100644 --- a/srcs/requirements/mariadb/conf/create_db.sql +++ b/srcs/requirements/mariadb/conf/create_db.sql @@ -1,5 +1,5 @@ USE mysql; CREATE DATABASE IF NOT EXISTS ${DB_NAME}; -CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}'; -GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option; +CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PSWD}'; +GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'%' with grant option; diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 6ac4862..0b570fe 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -1,42 +1,43 @@ # debian (~ 180s) -------------------------------------------- - FROM debian:buster - - # vim for debug - RUN apt update && apt install -y \ - nginx openssl \ - vim \ - && \ - rm -rf /var/lib/apt/lists/* - - # nginx conf - COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf - COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ +# FROM debian:buster +# +# # vim for debug +# RUN apt update && apt install -y \ +# nginx openssl \ +# vim \ +# && \ +# rm -rf /var/lib/apt/lists/* +# +# # nginx conf +# COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf +# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ # alpine (~ 45s) --------------------------------------------- -# FROM alpine:3.15 -# -# # vim and bash for debug -# RUN apk update && apk add \ -# nginx openssl \ -# vim bash \ -# && \ -# rm -rf /var/cache/apk* -# -# # nginx conf -# COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf -# COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ -# -# # create user www-data and assign it to group www-data -# RUN adduser -S www-data && \ -# adduser www-data www-data -# -# RUN mkdir -p /var/www/html + FROM alpine:3.15 + + # vim and bash for debug + RUN apk update && apk add \ + nginx openssl \ + vim bash \ + && \ + rm -rf /var/cache/apk* + + # nginx conf + COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf + COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ + + # create user www-data and assign it to group www-data + RUN adduser -S www-data && \ + adduser www-data www-data + + RUN mkdir -p /var/www/html # common ----------------------------------------------------- -RUN rm -rf /var/www/html/* +# empty /var/www/html folder to avoid it to rewrite volume +#RUN rm -rf /var/www/html/* # personalized index.html COPY ./conf/index.html /data/www/ diff --git a/srcs/requirements/nginx/conf/nginx.conf.alpine b/srcs/requirements/nginx/conf/nginx.conf.alpine index afe8267..1cdac83 100644 --- a/srcs/requirements/nginx/conf/nginx.conf.alpine +++ b/srcs/requirements/nginx/conf/nginx.conf.alpine @@ -3,6 +3,11 @@ # user : # < user www-data # > user nginx +# +# protocols : +# +# < ssl_protocols TLSv1.2 TLSv1.3; +# > ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; # /etc/nginx/nginx.conf @@ -59,7 +64,7 @@ http { # Enables the specified protocols. Default is TLSv1 TLSv1.1 TLSv1.2. # TIP: If you're not obligated to support ancient clients, remove TLSv1.1. - ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + ssl_protocols TLSv1.2 TLSv1.3; # Path of the file with Diffie-Hellman parameters for EDH ciphers. # TIP: Generate with: `openssl dhparam -out /etc/ssl/nginx/dh2048.pem 2048` diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index 4806152..d30c637 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -1,53 +1,58 @@ # debian ----------------------------------------------------- - FROM debian:buster - - # bash and vim for debug - RUN apt update && apt install -y \ - php7.3 \ - php7.3-fpm \ - php7.3-mysqli \ - curl \ - bash vim - RUN rm -rf /var/lib/apt/lists/* - - # fpm config - COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/ - RUN mkdir /run/php/ - - ENV PHP_VERSION="php-fpm7.3" - -# alpine ----------------------------------------------------- - -# FROM alpine:3.15 +# FROM debian:buster # # # bash and vim for debug -# RUN apk update && apk add \ -# php7 \ -# php7-fpm \ -# php7-mysqli \ -# php7-phar \ -# php7-json \ +# RUN apt update && apt install -y \ +# php7.3 \ +# php7.3-fpm \ +# php7.3-mysqli \ +# mariadb-client \ # curl \ # bash vim # RUN rm -rf /var/lib/apt/lists/* # # # fpm config -# COPY ./conf/www.conf /etc/php7/php-fpm.d/ +# COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/ # RUN mkdir /run/php/ # -# # create wp directory -# ARG WP_DIR -# RUN mkdir -p ${WP_DIR} -# -# # create www-data user and add to group -# RUN adduser -S www-data && \ -# adduser www-data www-data -# -# ENV PHP_VERSION="php-fpm7" +# ENV PHP_VERSION="php-fpm7.3" + +# alpine ----------------------------------------------------- + + FROM alpine:3.15 + + # bash and vim for debug + RUN apk update && apk add \ + php7 \ + php7-fpm \ + php7-mysqli \ + php7-phar \ + php7-json \ + mariadb-client \ + curl \ + bash vim + RUN rm -rf /var/lib/apt/lists/* + + # fpm config + COPY ./conf/www.conf /etc/php7/php-fpm.d/ + RUN mkdir /run/php/ + + # create wp directory + ARG WP_DIR + RUN mkdir -p ${WP_DIR} + + # create www-data user and add to group + RUN adduser -S www-data && \ + adduser www-data www-data + + ENV PHP_VERSION="php-fpm7" # common ----------------------------------------------------- +# empty /var/www/html folder to avoid it to rewrite volume +#RUN rm -rf /var/www/html/* + # install wp-cli : https://wp-cli.org/#installing RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&\ chmod +x wp-cli.phar && \ diff --git a/srcs/requirements/wordpress/conf/wp_entrypoint.sh b/srcs/requirements/wordpress/conf/wp_entrypoint.sh index 665c2da..816c9c8 100644 --- a/srcs/requirements/wordpress/conf/wp_entrypoint.sh +++ b/srcs/requirements/wordpress/conf/wp_entrypoint.sh @@ -6,10 +6,10 @@ wp core download --path="${WP_DIR}" --allow-root # create config file : wp config create \ - --dbhost=mariadb \ + --dbhost="${DB_HOST}" \ --dbname="${DB_NAME}" \ --dbuser="${DB_USER}" \ - --dbpass="${DB_PASS}" \ + --dbpass="${DB_PSWD}" \ --path="${WP_DIR}" --allow-root # install wordpress : @@ -32,5 +32,5 @@ wp user create \ chown -R www-data:www-data /var/www/* chmod 755 -R /var/www/* -exec ${PHP_VERSION} -FR +exec "${PHP_VERSION}" -FR