commit 93a367106e96125644e00c71f96ddcd8233ccde0 Author: Arnaud Lier Date: Sat Jan 25 11:41:12 2025 +0100 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f0adb96 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +up: + docker compose -f 'srcs/docker-compose.yml' up --build --detach \ No newline at end of file diff --git a/srcs/.env b/srcs/.env new file mode 100644 index 0000000..997a413 --- /dev/null +++ b/srcs/.env @@ -0,0 +1,7 @@ +DOMAIN_NAME=alier.42.fr +TITLE=42 News +ADMIN_EMAIL=alier@student.42mulhouse.fr +ADMIN_USER=arnaudlier +DATA_PATH=/Users/arnaudlier/data +DB_USER=wordpress +DB_DB=wordpress \ No newline at end of file diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml new file mode 100644 index 0000000..1bd8d3e --- /dev/null +++ b/srcs/docker-compose.yml @@ -0,0 +1,67 @@ +name: inception + +volumes: + wordpress: + driver: local + driver_opts: + device: $DATA_PATH/wordpress + o: bind + type: none + +services: + mariadb: + restart: on-failure + build: + context: ./requirements/mariadb + dockerfile: Dockerfile + volumes: + - type: bind + source: $DATA_PATH/mariadb + target: /var/lib/mysql + networks: + - inception + env_file: .env + secrets: + - db_root_password + - db_password + nginx: + restart: on-failure + ports: + - 443:443 + build: + context: ./requirements/nginx + dockerfile: Dockerfile + depends_on: + wordpress: + condition: service_healthy + restart: true + volumes: + - wordpress:/var/www/wordpress + networks: + - inception + env_file: .env + wordpress: + restart: on-failure + depends_on: + mariadb: + condition: service_healthy + restart: true + build: + context: ./requirements/wordpress + dockerfile: Dockerfile + volumes: + - wordpress:/var/www/wordpress + networks: + - inception + secrets: + - db_password + env_file: .env + +secrets: + db_password: + file: ../secrets/db_password.txt + db_root_password: + file: ../secrets/db_root_password.txt + +networks: + inception: diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile new file mode 100644 index 0000000..41129bb --- /dev/null +++ b/srcs/requirements/mariadb/Dockerfile @@ -0,0 +1,26 @@ +FROM alpine:3.21.2 + +LABEL org.opencontainers.image.authors="alier@student.42mulhouse.fr" + +RUN apk add mariadb mariadb-client + +RUN mkdir -p /run/mysqld \ + && mkdir -p /var/lib/mysql \ + && chown -R mysql:mysql /run/mysqld \ + && chown -R mysql:mysql /var/lib/mysql + +COPY ./tools/docker-entrypoint.sh /docker-entrypoint.sh +COPY ./conf/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf + +VOLUME [ "/var/lib/mysql" ] + +ENTRYPOINT [ "/docker-entrypoint.sh" ] + +EXPOSE 3306 + +HEALTHCHECK --start-period=5s \ + CMD mariadb -e 'SELECT @@datadir;' || exit 1 + +USER mysql + +CMD ["mariadbd"] \ No newline at end of file diff --git a/srcs/requirements/mariadb/conf/mariadb-server.cnf b/srcs/requirements/mariadb/conf/mariadb-server.cnf new file mode 100644 index 0000000..0282805 --- /dev/null +++ b/srcs/requirements/mariadb/conf/mariadb-server.cnf @@ -0,0 +1,41 @@ +# +# These groups are read by MariaDB server. +# Use it for options that only the server (but not clients) should see + +# this is read by the standalone daemon and embedded servers +[server] + +# this is only for the mysqld standalone daemon +[mysqld] +#skip-networking + +# Galera-related settings +[galera] +# Mandatory settings +#wsrep_on=ON +#wsrep_provider= +#wsrep_cluster_address= +#binlog_format=row +#default_storage_engine=InnoDB +#innodb_autoinc_lock_mode=2 +# +# Allow server to accept connections on all interfaces. +# +bind-address=0.0.0.0 +# +# Optional setting +#wsrep_slave_threads=1 +#innodb_flush_log_at_trx_commit=0 + +# this is only for embedded server +[embedded] + +# This group is only read by MariaDB servers, not by MySQL. +# If you use the same .cnf file for MySQL and MariaDB, +# you can put MariaDB-only options here +[mariadb] + +# This group is only read by MariaDB-10.5 servers. +# If you use the same .cnf file for MariaDB of different versions, +# use this group for options that older servers don't understand +[mariadb-10.5] \ No newline at end of file diff --git a/srcs/requirements/mariadb/tools/docker-entrypoint.sh b/srcs/requirements/mariadb/tools/docker-entrypoint.sh new file mode 100755 index 0000000..06fa759 --- /dev/null +++ b/srcs/requirements/mariadb/tools/docker-entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +if [ ! -e /var/lib/mysql/mysql ]; then + cd /var/lib/mysql + mariadb-install-db --auth-root-authentication-method=normal \ + --datadir /var/lib/mysql +fi + +if [ ! -e /var/lib/mysql/wordpress ]; then + mariadbd & + + sleep 5 + + mariadb --user root <}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t +; %T: time the log has been written (the request has finished) +; it can accept a strftime(3) format: +; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsulated in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t +; %u: basic auth user if specified in Authorization header +; +; Default: "%R - %u %t \"%m %r\" %s" +;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{milli}d %{kilo}M %C%%" + +; A list of request_uri values which should be filtered from the access log. +; +; As a security precaution, this setting will be ignored if: +; - the request method is not GET or HEAD; or +; - there is a request body; or +; - there are query parameters; or +; - the response code is outwith the successful range of 200 to 299 +; +; Note: The paths are matched against the output of the access.format tag "%r". +; On common configurations, this may look more like SCRIPT_NAME than the +; expected pre-rewrite URI. +; +; Default Value: not set +;access.suppress_path[] = /ping +;access.suppress_path[] = /health_check.php + +; The log file for slow requests +; Default Value: not set +; Note: slowlog is mandatory if request_slowlog_timeout is set +;slowlog = log/php84/$pool.slow.log + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +;request_slowlog_timeout = 0 + +; Depth of slow log stack trace. +; Default Value: 20 +;request_slowlog_trace_depth = 20 + +; The timeout for serving a single request after which the worker process will +; be killed. This option should be used when the 'max_execution_time' ini option +; does not stop script execution for some reason. A value of '0' means 'off'. +; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) +; Default Value: 0 +;request_terminate_timeout = 0 + +; The timeout set by 'request_terminate_timeout' ini option is not engaged after +; application calls 'fastcgi_finish_request' or when application has finished and +; shutdown functions are being called (registered via register_shutdown_function). +; This option will enable timeout limit to be applied unconditionally +; even in such cases. +; Default Value: no +;request_terminate_timeout_track_finished = no + +; Set open file descriptor rlimit. +; Default Value: system defined value +;rlimit_files = 1024 + +; Set max core size rlimit. +; Possible Values: 'unlimited' or an integer greater or equal to 0 +; Default Value: system defined value +;rlimit_core = 0 + +; Chroot to this directory at the start. This value must be defined as an +; absolute path. When this value is not set, chroot is not used. +; Note: you can prefix with '$prefix' to chroot to the pool prefix or one +; of its subdirectories. If the pool prefix is not set, the global prefix +; will be used instead. +; Note: chrooting is a great security feature and should be used whenever +; possible. However, all PHP paths will be relative to the chroot +; (error_log, sessions.save_path, ...). +; Default Value: not set +;chroot = + +; Chdir to this directory at the start. +; Note: relative path can be used. +; Default Value: current directory or / when chroot +;chdir = /var/www + +; Redirect worker stdout and stderr into main error log. If not set, stdout and +; stderr will be redirected to /dev/null according to FastCGI specs. +; Note: on highloaded environment, this can cause some delay in the page +; process time (several ms). +; Default Value: no +;catch_workers_output = yes + +; Decorate worker output with prefix and suffix containing information about +; the child that writes to the log and if stdout or stderr is used as well as +; log level and time. This options is used only if catch_workers_output is yes. +; Settings to "no" will output data as written to the stdout or stderr. +; Default value: yes +;decorate_workers_output = no + +; Clear environment in FPM workers +; Prevents arbitrary environment variables from reaching FPM worker processes +; by clearing the environment in workers before env vars specified in this +; pool configuration are added. +; Setting to "no" will make all environment variables available to PHP code +; via getenv(), $_ENV and $_SERVER. +; Default Value: yes +;clear_env = no + +; Limits the extensions of the main script FPM will allow to parse. This can +; prevent configuration mistakes on the web server side. You should only limit +; FPM to .php extensions to prevent malicious users to use other extensions to +; execute php code. +; Note: set an empty value to allow all extensions. +; Default Value: .php +;security.limit_extensions = .php .php3 .php4 .php5 .php7 + +; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from +; the current environment. +; Default Value: clean env +;env[HOSTNAME] = $HOSTNAME +;env[PATH] = /usr/local/bin:/usr/bin:/bin +;env[TMP] = /tmp +;env[TMPDIR] = /tmp +;env[TEMP] = /tmp + +; Additional php.ini defines, specific to this pool of workers. These settings +; overwrite the values previously defined in the php.ini. The directives are the +; same as the PHP SAPI: +; php_value/php_flag - you can set classic ini defines which can +; be overwritten from PHP call 'ini_set'. +; php_admin_value/php_admin_flag - these directives won't be overwritten by +; PHP call 'ini_set' +; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. + +; Defining 'extension' will load the corresponding shared extension from +; extension_dir. Defining 'disable_functions' or 'disable_classes' will not +; overwrite previously defined php.ini values, but will append the new value +; instead. + +; Note: path INI options can be relative and will be expanded with the prefix +; (pool, global or /usr) + +; Default Value: nothing is defined by default except the values in php.ini and +; specified at startup with the -d argument +;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com +;php_flag[display_errors] = off +;php_admin_value[error_log] = /var/log/php84/$pool.error.log +;php_admin_flag[log_errors] = on +;php_admin_value[memory_limit] = 32M \ No newline at end of file diff --git a/srcs/requirements/wordpress/tools/setup_wordpress.sh b/srcs/requirements/wordpress/tools/setup_wordpress.sh new file mode 100644 index 0000000..1f73ece --- /dev/null +++ b/srcs/requirements/wordpress/tools/setup_wordpress.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ ! -e '/var/www/wordpress/wp-config.php' ]; then + wp core download --path=/var/www/wordpress + + cd /var/www/wordpress + wp config create --dbname="$DB_DB" --dbuser="$DB_USER" --dbpass="$(cat /run/secrets/db_password)" --dbhost=mariadb + wp core install --url="$DOMAIN_NAME" --title="$TITLE" --admin_user="$ADMIN_USER" --admin_email="$ADMIN_EMAIL" --admin_password="password" +fi + +exec php-fpm84 --nodaemonize \ No newline at end of file