mariadb and nginx works both with debian and alpine

+ makefile a little clean up
This commit is contained in:
hugo gogo
2022-09-18 16:39:13 +02:00
parent 5d01ad0fdc
commit 9708715bb5
9 changed files with 134 additions and 67 deletions

View File

@@ -24,32 +24,17 @@ RESET = "\e[0m"
COMPOSE = ./srcs/docker-compose.yml
IMAGES = nginx \
mariadb \
wordpress
HOME_D = $(shell echo $(HOME))
VOLUMES_D = $(VOLUMES:%=$(HOME_D)/%)
VOLUMES = v_wp_site \
v_wp_db
CONTAINERS = $(IMAGES:%=my%)
CONT = mytest
SUDO =
# for rule super-clean, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
STOP = $(shell $(SUDO) docker ps -q)
# list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
RUNNING = $(shell $(SUDO) docker ps -q)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# use 'make' to launch and relaunch the project #
# use 'make re' to relaunch and clean the dungling images #
# use 'make fre' to start all over again (images) #
# use 'make super-clean' if you want to delete all dockers on com- #
# puter even if not related to the project #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: build $(VOLUMES_D) up
@@ -73,38 +58,18 @@ list:
@$(SUDO) docker volume ls
@echo ""
# remove project images
rm-images:
$(SUDO) docker image rm -f $(IMAGES)
# stop project containers
stop:
- $(SUDO) docker stop $(CONTAINERS)
# remove all stopped containers and dangling images (dangling images, see : https://projectatomic.io/blog/2015/07/what-are-docker-none-none-images/)
prune:
# remove project images and containers not used
clean:
- $(SUDO) docker stop $(RUNNING)
$(SUDO) docker system prune -f
# remove project images and containers
clean: stop prune
# remove project volumes
rm-volumes:
- $(SUDO) docker volume rm -f $(VOLUMES)
/bin/rm -rf $(VOLUMES_D)
# remove project
fclean: rm-images clean rm-volumes
# remove all dockers, even not related to the project
super-clean:
- $(SUDO) docker stop $(STOP)
# remove every dockers
fclean:
- $(SUDO) docker stop $(RUNNING)
$(SUDO) docker system prune -af --volumes
/bin/rm -rf $(VOLUMES_D)
re: clean all
re: fclean all
fre: fclean all
.PHONY : all build up $(VOLUMES_D) list rm-images stop rm-containers close-nginx prune clean rm-volumes fclean super-clean re fre
.PHONY : all $(VOLUMES_D) build up list clean fclean re

View File

@@ -1,26 +1,48 @@
FROM debian:buster
# debian -----------------------------------------------------
ARG DB_NAME
ARG DB_USER
ARG DB_PSWD
# FROM debian:buster
#
# ARG DB_NAME
# ARG DB_USER
# ARG DB_PSWD
#
# RUN apt update && apt install -y \
# mariadb-client \
# mariadb-server \
# && \
# rm -rf /var/lib/apt/lists/*
#
# # config file .cnf :
# COPY ./conf/50-server.cnf.debian /etc/mysql/mariadb.conf.d/50-server.cnf
RUN apt update && apt install -y \
mariadb-client \
mariadb-server
RUN rm -rf /var/lib/apt/lists/*
# alpine -----------------------------------------------------
FROM alpine:3.15
ARG DB_NAME
ARG DB_USER
ARG DB_PSWD
# vim and bash for debug
RUN apk update && apk add \
mariadb \
mariadb-client \
vim bash \
&& \
rm -rf /var/cache/apk*
# config file .cnf :
COPY ./conf/mariadb-server.cnf.alpine /etc/my.cnf.d/mariadb-server.cnf
# common -----------------------------------------------------
# init mysql database
RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql && \
mkdir -p /var/run/mysqld && \
chown -R mysql:root /var/run/mysqld
# configure wp database
RUN service mysql start && \
mariadb --execute="CREATE DATABASE ${DB_NAME};" && \
mariadb --execute="CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}';" && \
mariadb --execute="GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option;"
COPY ./conf/create_db.sql /usr/bin/create_db.sql
# # config file 50-server.cnf :
# # uncomment port = 3306
# RUN sed -i "s/^#port/port /g" /etc/mysql/mariadb.conf.d/50-server.cnf
# # comment bind-address = 127.0.0.1
# RUN sed -i "s/^bind-address /#bind-address/g" /etc/mysql/mariadb.conf.d/50-server.cnf
COPY ./conf/50-server.cnf ./
ENTRYPOINT [ "mysqld" ]
ENTRYPOINT [ "mysqld", "--user=mysql", "--init-file=/usr/bin/create_db.sql" ]

View File

@@ -1,3 +1,12 @@
# inception modifications :
#
# [mysqld] :
# < port = 3306
# > #port = 3306
# ---
# < #bind-address = 127.0.0.1
# > bind-address = 127.0.0.1
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see

View File

@@ -0,0 +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;

View File

@@ -0,0 +1,62 @@
# https://wiki.alpinelinux.org/wiki/MariaDB
# inception modifications :
#
# [mysqld] :
# < skip-networking = false
# > skip-networking
# ---
# < datadir = /var/lib/mysql
# >
# ---
# < port = 3306
# >
# ---
# < socket=/var/lib/mysql/mysql.sock
# >
#
# 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 = false
datadir = /var/lib/mysql
port = 3306
socket=/var/lib/mysql/mysql.sock
# 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]

View File

@@ -10,7 +10,7 @@
# rm -rf /var/lib/apt/lists/*
#
# # nginx conf
# COPY ./conf/nginx_debian.conf /etc/nginx/nginx.conf
# COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf
# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/
# alpine (~ 45s) ---------------------------------------------
@@ -25,7 +25,7 @@
rm -rf /var/cache/apk*
# nginx conf
COPY ./conf/nginx_alpine.conf /etc/nginx/nginx.conf
COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf
COPY ./conf/inception_nginx.conf /etc/nginx/http.d/
# common -----------------------------------------------------

View File

@@ -4,6 +4,10 @@
mkdir -p ${WP_DIR}
wp core download --path="${WP_DIR}" --allow-root
# mariadb --execute="CREATE DATABASE ${DB_NAME};" && \
# mariadb --execute="CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}';" && \
# mariadb --execute="GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option;"
## create config file :
wp config create \
--dbhost=mariadb \