wordpress works now with :

+ volumes in mariadb container
+ db pswd in quotes
+ somes other settings
This commit is contained in:
hugo gogo
2022-09-21 18:10:03 +02:00
parent ef8ce69dad
commit 0603616d3e
9 changed files with 108 additions and 81 deletions

View File

@@ -1,6 +1,10 @@
# inception # 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 ## WIP

View File

@@ -5,9 +5,11 @@ LOGIN=$USER
# MARIADB SETUP # MARIADB SETUP
DB_HOST=mariadb
DB_NAME=db_wp_inception DB_NAME=db_wp_inception
DB_USER=user_wp_inception DB_USER=user_wp_inception
DB_PSWD="if you read this i will have to erase your memory" DB_PSWD="if you read this i will have to erase your memory"
#ROOT_PSWD="root passphrase"
# WORDPRESS SETUP # WORDPRESS SETUP

View File

@@ -16,6 +16,8 @@ services:
ports: ports:
- "443:443" - "443:443"
# - "80:80" # - "80:80"
volumes:
- wp_volume:/var/www/html
build: ./requirements/nginx build: ./requirements/nginx
image: nginx image: nginx
container_name: nginx_container container_name: nginx_container
@@ -28,14 +30,20 @@ services:
env_file: .env env_file: .env
networks: networks:
- inception - inception
# volumes: volumes:
# - db_volume:/var/lib/mysql - db_volume:/var/lib/mysql
build: build:
context: ./requirements/mariadb context: ./requirements/mariadb
args: args:
- DB_HOST=${DB_HOST}
- DB_NAME=${DB_NAME} - DB_NAME=${DB_NAME}
- DB_USER=${DB_USER} - DB_USER=${DB_USER}
- DB_PSWD=${DB_PSWD} - 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 image: mariadb
container_name: mariadb_container container_name: mariadb_container
# --------------------------------- # ---------------------------------
@@ -44,8 +52,8 @@ services:
env_file: ./.env env_file: ./.env
networks: networks:
- inception - inception
# volumes: volumes:
# - wp_volume:/var/www/html - wp_volume:/var/www/html
build: build:
context: ./requirements/wordpress context: ./requirements/wordpress
args: args:
@@ -54,7 +62,7 @@ services:
container_name: wordpress_container container_name: wordpress_container
depends_on: depends_on:
mariadb: 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 # specify path to named volumes : https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference
volumes: volumes:

View File

@@ -30,6 +30,7 @@
# common ----------------------------------------------------- # common -----------------------------------------------------
ARG DB_HOST
ARG DB_NAME ARG DB_NAME
ARG DB_USER ARG DB_USER
ARG DB_PSWD ARG DB_PSWD
@@ -41,9 +42,10 @@ RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql && \
# configure wp database # configure wp database
COPY ./conf/create_db.sql /usr/bin/create_db.sql 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_HOST}/${DB_HOST}/g" /usr/bin/create_db.sql && \
RUN sed -i "s/\${DB_USER}/${DB_USER}/g" /usr/bin/create_db.sql sed -i "s/\${DB_NAME}/${DB_NAME}/g" /usr/bin/create_db.sql && \
RUN sed -i "s/\${DB_PSWD}/${DB_PSWD}/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" ] ENTRYPOINT [ "mysqld", "--user=mysql", "--init-file=/usr/bin/create_db.sql" ]

View File

@@ -1,5 +1,5 @@
USE mysql; USE mysql;
CREATE DATABASE IF NOT EXISTS ${DB_NAME}; CREATE DATABASE IF NOT EXISTS ${DB_NAME};
CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}'; CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PSWD}';
GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option; GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'%' with grant option;

View File

@@ -1,42 +1,43 @@
# debian (~ 180s) -------------------------------------------- # debian (~ 180s) --------------------------------------------
FROM debian:buster # FROM debian:buster
#
# vim for debug # # vim for debug
RUN apt update && apt install -y \ # RUN apt update && apt install -y \
nginx openssl \ # nginx openssl \
vim \ # vim \
&& \ # && \
rm -rf /var/lib/apt/lists/* # rm -rf /var/lib/apt/lists/*
#
# nginx conf # # nginx conf
COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf # COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf
COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/ # COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/
# alpine (~ 45s) --------------------------------------------- # alpine (~ 45s) ---------------------------------------------
# FROM alpine:3.15 FROM alpine:3.15
#
# # vim and bash for debug # vim and bash for debug
# RUN apk update && apk add \ RUN apk update && apk add \
# nginx openssl \ nginx openssl \
# vim bash \ vim bash \
# && \ && \
# rm -rf /var/cache/apk* rm -rf /var/cache/apk*
#
# # nginx conf # nginx conf
# COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf
# COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ COPY ./conf/inception_nginx.conf /etc/nginx/http.d/
#
# # create user www-data and assign it to group www-data # create user www-data and assign it to group www-data
# RUN adduser -S www-data && \ RUN adduser -S www-data && \
# adduser www-data www-data adduser www-data www-data
#
# RUN mkdir -p /var/www/html RUN mkdir -p /var/www/html
# common ----------------------------------------------------- # 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 # personalized index.html
COPY ./conf/index.html /data/www/ COPY ./conf/index.html /data/www/

View File

@@ -3,6 +3,11 @@
# user : # user :
# < user www-data # < user www-data
# > user nginx # > user nginx
#
# protocols :
#
# < ssl_protocols TLSv1.2 TLSv1.3;
# > ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
# /etc/nginx/nginx.conf # /etc/nginx/nginx.conf
@@ -59,7 +64,7 @@ http {
# Enables the specified protocols. Default is TLSv1 TLSv1.1 TLSv1.2. # Enables the specified protocols. Default is TLSv1 TLSv1.1 TLSv1.2.
# TIP: If you're not obligated to support ancient clients, remove TLSv1.1. # 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. # Path of the file with Diffie-Hellman parameters for EDH ciphers.
# TIP: Generate with: `openssl dhparam -out /etc/ssl/nginx/dh2048.pem 2048` # TIP: Generate with: `openssl dhparam -out /etc/ssl/nginx/dh2048.pem 2048`

View File

@@ -1,53 +1,58 @@
# debian ----------------------------------------------------- # debian -----------------------------------------------------
FROM debian:buster # 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
# #
# # bash and vim for debug # # bash and vim for debug
# RUN apk update && apk add \ # RUN apt update && apt install -y \
# php7 \ # php7.3 \
# php7-fpm \ # php7.3-fpm \
# php7-mysqli \ # php7.3-mysqli \
# php7-phar \ # mariadb-client \
# php7-json \
# curl \ # curl \
# bash vim # bash vim
# RUN rm -rf /var/lib/apt/lists/* # RUN rm -rf /var/lib/apt/lists/*
# #
# # fpm config # # 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/ # RUN mkdir /run/php/
# #
# # create wp directory # ENV PHP_VERSION="php-fpm7.3"
# ARG WP_DIR
# RUN mkdir -p ${WP_DIR} # alpine -----------------------------------------------------
#
# # create www-data user and add to group FROM alpine:3.15
# RUN adduser -S www-data && \
# adduser www-data www-data # bash and vim for debug
# RUN apk update && apk add \
# ENV PHP_VERSION="php-fpm7" 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 ----------------------------------------------------- # 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 # install wp-cli : https://wp-cli.org/#installing
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&\ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&\
chmod +x wp-cli.phar && \ chmod +x wp-cli.phar && \

View File

@@ -6,10 +6,10 @@ wp core download --path="${WP_DIR}" --allow-root
# create config file : # create config file :
wp config create \ wp config create \
--dbhost=mariadb \ --dbhost="${DB_HOST}" \
--dbname="${DB_NAME}" \ --dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \ --dbuser="${DB_USER}" \
--dbpass="${DB_PASS}" \ --dbpass="${DB_PSWD}" \
--path="${WP_DIR}" --allow-root --path="${WP_DIR}" --allow-root
# install wordpress : # install wordpress :
@@ -32,5 +32,5 @@ wp user create \
chown -R www-data:www-data /var/www/* chown -R www-data:www-data /var/www/*
chmod 755 -R /var/www/* chmod 755 -R /var/www/*
exec ${PHP_VERSION} -FR exec "${PHP_VERSION}" -FR