From 49a136c709000f4403d11ee44897aebf6d5c5d64 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 12 Jun 2025 18:26:18 +0200 Subject: [PATCH] add: mariadb docker, wordpress now works :)))) --- Makefile | 4 + TODO | 3 + srcs/docker-compose.yml | 8 ++ srcs/requirements/mariadb/Dockerfile | 22 ++++ .../mariadb/conf/mariadb-server.cnf | 10 ++ srcs/requirements/mariadb/run.sh | 34 ++++++ srcs/requirements/nginx/Dockerfile | 2 +- srcs/requirements/wordpress/Dockerfile | 2 +- srcs/www/wp-config.php | 102 ++++++++++++++++++ 9 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 TODO create mode 100644 srcs/requirements/mariadb/Dockerfile create mode 100644 srcs/requirements/mariadb/conf/mariadb-server.cnf create mode 100755 srcs/requirements/mariadb/run.sh create mode 100644 srcs/www/wp-config.php diff --git a/Makefile b/Makefile index 2127a26..6d93a95 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,10 @@ uninstall : echoo "Removing $(WWW_PATH)..." rm -r $(WWW_PATH) || true + # TODO(ugly) + -docker container prune + -docker volume rm my-awesome-compose_db + ## 'uninstall' then 'install' re : uninstall install diff --git a/TODO b/TODO new file mode 100644 index 0000000..7392ecc --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +TODO later +- dependencies between containers and check if its is working +- volume www to normal volume, and create it in docker diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 9455888..1559459 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -16,6 +16,13 @@ services: build: ./requirements/wordpress volumes: - www:/www:rw + depends_on: + - mariadb + + mariadb: + build: ./requirements/mariadb + volumes: + - db:/db:rw volumes: www: @@ -24,6 +31,7 @@ volumes: o: bind type: none device: "${INCEPTION_WWW_PATH:?error}" + db: ### services ### # image: diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile new file mode 100644 index 0000000..116af2e --- /dev/null +++ b/srcs/requirements/mariadb/Dockerfile @@ -0,0 +1,22 @@ +# TODO(any)(latest) +FROM alpine:latest + +RUN apk update +RUN apk add mariadb +RUN apk fix + +RUN rm -rf /etc/my.cnf.d/ +RUN mkdir -p /etc/my.cnf.d/ +COPY conf/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf +COPY run.sh /run.sh + +# TODO(secret) +RUN addgroup -S www && adduser -S www www +RUN mkdir /db +RUN chmod -R 666 /db + +EXPOSE 3306 + +# start +CMD ["/run.sh"] +#CMD ["ls", "-AlF", "/"] diff --git a/srcs/requirements/mariadb/conf/mariadb-server.cnf b/srcs/requirements/mariadb/conf/mariadb-server.cnf new file mode 100644 index 0000000..ce6f9a1 --- /dev/null +++ b/srcs/requirements/mariadb/conf/mariadb-server.cnf @@ -0,0 +1,10 @@ +[client-server] +socket=/tmp/mysql.sock +port=3306 + +[mysqld] +# fix from https://stackoverflow.com/questions/75696472/aborted-connection-3-to-db-unconnected-user-unauthenticated-host-172-21 +skip-grant-tables + +[mariadb] +datadir=/db diff --git a/srcs/requirements/mariadb/run.sh b/srcs/requirements/mariadb/run.sh new file mode 100755 index 0000000..d18bd1d --- /dev/null +++ b/srcs/requirements/mariadb/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +echo + +dirisempty() +{ + [ -z "$( ls -A "$1" )" ] +} + +# install database if doesn't exist +if dirisempty /db +then + echo "database doesn't exist. creating it..." + echo + chmod -R 777 /db + mariadb-install-db --user=www --datadir=/db + # TODO(secret) + echo ' + FLUSH PRIVILEGES; + CREATE DATABASE wp; + GRANT ALL PRIVILEGES ON wp.* TO wwsw IDENTIFIED BY "ultraPassword"; + FLUSH PRIVILEGES; + ' | mariadbd -u root --bootstrap + echo + echo "database created!" + echo +fi + +echo "to recreate a new database, remove the db volume of this compose." +echo + +# run mariadb +mariadbd -u root diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 1a5d8b2..70a88e2 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -20,7 +20,7 @@ RUN printf "%s%s%s%s\n" \ RUN curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub RUN mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/ RUN apk update -RUN apk add nginx@nginx +RUN apk add nginx@nginx mysql-client RUN apk fix # add config diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index d51e8e8..7eb1a7b 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -6,7 +6,7 @@ EXPOSE 9000 # install packages RUN apk update -RUN apk add php-fpm +RUN apk add php-fpm php-mysqli RUN apk fix RUN addgroup -S www diff --git a/srcs/www/wp-config.php b/srcs/www/wp-config.php new file mode 100644 index 0000000..b86e80c --- /dev/null +++ b/srcs/www/wp-config.php @@ -0,0 +1,102 @@ +c]EE<+5BAo{3/)5Oc|(U30#2An'); +define('NONCE_KEY', 'EwQ+Jo#/Zr-I_,nJu|)i1.Bfzm:b!5d.ku%%+Ihw.)l-]0y 2^;=4HR1XB$B!;m66'); +define('AUTH_SALT', 'p_&.BA.mTs]RQEM(Q@F0yB`.@INfW@6L-<%%cd*@I-w iOlEqC@[I0aLbuYNLk}O9'); +define('SECURE_AUTH_SALT', '$H?b*kvJ:uA6DyPLwAJsh8:n}P.:[-N<,$/zl?,|`Vu++qC}F,{YKw&8CM`@@d*t'); +define('LOGGED_IN_SALT', ',6~y7[-Z}Hj/d&C!M[_|FD]R0>YMTO)s}xD`?.{ Ich:>5j!W`T9~~wef-WLJ:U#'); +define('NONCE_SALT', '%%-8d||zvI0s,giZmR7Lk(nhG|uH8c~U{kdB|2.v?Z+@3hr&nlk<@V22;.Ef8chSv'); + +/**#@-*/ + +/** + * WordPress database table prefix. + * + * You can have multiple installations in one database if you give each + * a unique prefix. Only numbers, letters, and underscores please! + * + * At the installation time, database tables are created with the specified prefix. + * Changing this value after WordPress is installed will make your site think + * it has not been installed. + * + * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix + */ +$table_prefix = 'wp_'; + +/** + * For developers: WordPress debugging mode. + * + * Change this to true to enable the display of notices during development. + * It is strongly recommended that plugin and theme developers use WP_DEBUG + * in their development environments. + * + * For information on other constants that can be used for debugging, + * visit the documentation. + * + * @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/ + */ +define( 'WP_DEBUG', true ); # TODO(debug) + +/* Add any custom values between this line and the "stop editing" line. */ + + + +/* That's all, stop editing! Happy publishing. */ + +/** Absolute path to the WordPress directory. */ +if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', __DIR__ . '/' ); +} + +/** Sets up WordPress vars and included files. */ +require_once ABSPATH . 'wp-settings.php';