From 193c18c47a2c0387601fc2028c1cda40560af294 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sat, 7 Oct 2023 17:01:56 +0200 Subject: [PATCH] upgrade makefile, add env var to mariadb --- Makefile | 5 ++++- srcs/docker-compose.yml | 3 +++ srcs/mariadb/Dockerfile | 4 ++-- srcs/mariadb/entrypoint.sh | 6 ++++++ srcs/mariadb/init.sql | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 srcs/mariadb/entrypoint.sh diff --git a/Makefile b/Makefile index 0522a75..d799a5d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,16 @@ all: up run: + @mkdir -p /home/cchauvet/data/wp-files + @mkdir -p /home/cchauvet/data/wp-db docker-compose -f srcs/docker-compose.yml up --build -d fclean: -docker rm -f `docker ps -aq` -docker volume rm -f `docker volume ls -q` -docker image rm -f `docker image ls -aq` - -docker network rm -f `docker network ls -q` + -docker network rm `docker network ls -q` -docker builder prune --all --force + rm -rf /home/cchauvet/data/wp-files /home/cchauvet/data/wp-db up: run diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index ca6506e..f18d83d 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -12,6 +12,7 @@ services: - wordpress networks: - inception + restart: always wordpress: container_name: wordpress @@ -25,6 +26,7 @@ services: - .env networks: - inception + restart: always mariadb: container_name: mariadb @@ -36,6 +38,7 @@ services: - .env networks: - inception + restart: always volumes: diff --git a/srcs/mariadb/Dockerfile b/srcs/mariadb/Dockerfile index f1c9f70..a06292c 100644 --- a/srcs/mariadb/Dockerfile +++ b/srcs/mariadb/Dockerfile @@ -5,6 +5,6 @@ RUN apk update RUN apk add mariadb RUN mariadb-install-db RUN mkdir /run/mysqld -COPY init.sql /etc +COPY init.sql entrypoint.sh /etc/ -ENTRYPOINT ["mariadbd", "--no-defaults", "--user=root", "--datadir=/data", "--init-file=/etc/init.sql"] +ENTRYPOINT ["sh", "/etc/entrypoint.sh"] diff --git a/srcs/mariadb/entrypoint.sh b/srcs/mariadb/entrypoint.sh new file mode 100644 index 0000000..73fb287 --- /dev/null +++ b/srcs/mariadb/entrypoint.sh @@ -0,0 +1,6 @@ +sed -i "s/DB_USER/$DB_USER/g" /etc/init.sql +sed -i "s/DB_PASS/$DB_PASS/g" /etc/init.sql + +cat /etc/init.sql >/dev/stderr + +exec mariadbd --no-defaults --user=root --datadir=/data --init-file=/etc/init.sql diff --git a/srcs/mariadb/init.sql b/srcs/mariadb/init.sql index 10c29ec..ff7b820 100644 --- a/srcs/mariadb/init.sql +++ b/srcs/mariadb/init.sql @@ -1,2 +1,2 @@ CREATE DATABASE wordpress; -GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%' IDENTIFIED BY 'wordpress'; +GRANT ALL PRIVILEGES ON wordpress.* TO 'DB_USER'@'%' IDENTIFIED BY 'DB_PASS';