mariadb and nginx works both with debian and alpine
+ makefile a little clean up
This commit is contained in:
55
Makefile
55
Makefile
@@ -24,32 +24,17 @@ RESET = "\e[0m"
|
|||||||
|
|
||||||
COMPOSE = ./srcs/docker-compose.yml
|
COMPOSE = ./srcs/docker-compose.yml
|
||||||
|
|
||||||
IMAGES = nginx \
|
|
||||||
mariadb \
|
|
||||||
wordpress
|
|
||||||
|
|
||||||
HOME_D = $(shell echo $(HOME))
|
HOME_D = $(shell echo $(HOME))
|
||||||
|
|
||||||
VOLUMES_D = $(VOLUMES:%=$(HOME_D)/%)
|
VOLUMES_D = $(VOLUMES:%=$(HOME_D)/%)
|
||||||
VOLUMES = v_wp_site \
|
|
||||||
v_wp_db
|
|
||||||
|
|
||||||
CONTAINERS = $(IMAGES:%=my%)
|
|
||||||
|
|
||||||
CONT = mytest
|
|
||||||
|
|
||||||
SUDO =
|
SUDO =
|
||||||
|
|
||||||
# for rule super-clean, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
|
# list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile
|
||||||
STOP = $(shell $(SUDO) docker ps -q)
|
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
|
all: build $(VOLUMES_D) up
|
||||||
@@ -73,38 +58,18 @@ list:
|
|||||||
@$(SUDO) docker volume ls
|
@$(SUDO) docker volume ls
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
# remove project images
|
# remove project images and containers not used
|
||||||
rm-images:
|
clean:
|
||||||
$(SUDO) docker image rm -f $(IMAGES)
|
- $(SUDO) docker stop $(RUNNING)
|
||||||
|
|
||||||
# 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:
|
|
||||||
$(SUDO) docker system prune -f
|
$(SUDO) docker system prune -f
|
||||||
|
|
||||||
# remove project images and containers
|
# remove every dockers
|
||||||
clean: stop prune
|
fclean:
|
||||||
|
- $(SUDO) docker stop $(RUNNING)
|
||||||
# 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)
|
|
||||||
$(SUDO) docker system prune -af --volumes
|
$(SUDO) docker system prune -af --volumes
|
||||||
/bin/rm -rf $(VOLUMES_D)
|
/bin/rm -rf $(VOLUMES_D)
|
||||||
|
|
||||||
re: clean all
|
re: fclean all
|
||||||
|
|
||||||
fre: fclean all
|
.PHONY : all $(VOLUMES_D) build up list clean fclean re
|
||||||
|
|
||||||
.PHONY : all build up $(VOLUMES_D) list rm-images stop rm-containers close-nginx prune clean rm-volumes fclean super-clean re fre
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,48 @@
|
|||||||
FROM debian:buster
|
# debian -----------------------------------------------------
|
||||||
|
|
||||||
ARG DB_NAME
|
# FROM debian:buster
|
||||||
ARG DB_USER
|
#
|
||||||
ARG DB_PSWD
|
# 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 \
|
# alpine -----------------------------------------------------
|
||||||
mariadb-client \
|
|
||||||
mariadb-server
|
FROM alpine:3.15
|
||||||
RUN rm -rf /var/lib/apt/lists/*
|
|
||||||
|
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
|
# configure wp database
|
||||||
RUN service mysql start && \
|
COPY ./conf/create_db.sql /usr/bin/create_db.sql
|
||||||
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;"
|
|
||||||
|
|
||||||
# # config file 50-server.cnf :
|
ENTRYPOINT [ "mysqld", "--user=mysql", "--init-file=/usr/bin/create_db.sql" ]
|
||||||
# # 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" ]
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
# These groups are read by MariaDB server.
|
||||||
# Use it for options that only the server (but not clients) should see
|
# Use it for options that only the server (but not clients) should see
|
||||||
5
srcs/requirements/mariadb/conf/create_db.sql
Normal file
5
srcs/requirements/mariadb/conf/create_db.sql
Normal 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;
|
||||||
62
srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine
Normal file
62
srcs/requirements/mariadb/conf/mariadb-server.cnf.alpine
Normal 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]
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
# rm -rf /var/lib/apt/lists/*
|
# rm -rf /var/lib/apt/lists/*
|
||||||
#
|
#
|
||||||
# # nginx conf
|
# # 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/
|
# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/
|
||||||
|
|
||||||
# alpine (~ 45s) ---------------------------------------------
|
# alpine (~ 45s) ---------------------------------------------
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
rm -rf /var/cache/apk*
|
rm -rf /var/cache/apk*
|
||||||
|
|
||||||
# nginx conf
|
# 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/
|
COPY ./conf/inception_nginx.conf /etc/nginx/http.d/
|
||||||
|
|
||||||
# common -----------------------------------------------------
|
# common -----------------------------------------------------
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
mkdir -p ${WP_DIR}
|
mkdir -p ${WP_DIR}
|
||||||
wp core download --path="${WP_DIR}" --allow-root
|
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 :
|
## create config file :
|
||||||
wp config create \
|
wp config create \
|
||||||
--dbhost=mariadb \
|
--dbhost=mariadb \
|
||||||
|
|||||||
Reference in New Issue
Block a user