Skip to content

Commit 749b39c

Browse files
committed
Initialization without external script
1 parent 4a94abd commit 749b39c

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

db/Dockerfile

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,38 @@ ARG MYSQL_USER
44
ARG SETUP_SQL=IUB_setup.sql
55
ARG SETUP_SCRIPT=build.sh
66

7-
#Trying to initialize the DB as explained here: https://stackoverflow.com/questions/32482780/how-to-create-populated-mysql-docker-image-on-build-time
8-
# No success
9-
#COPY ${SETUP_SQL} /docker-entrypoint-initdb.d/${SETUP_SQL}
10-
#RUN chmod +x /docker-entrypoint-initdb.d/${SETUP_SQL}
11-
#RUN sed -i 's|/var/lib/mysql|/var/lib/mysql2|g' /etc/mysql/my.cnf
12-
#RUN /entrypoint.sh mysqld & sleep 30 && killall mysqld
13-
#RUN rm /docker-entrypoint-initdb.d/${SETUP_SQL}
14-
15-
#Running a custom script after built
16-
RUN mkdir -p /setup
17-
COPY ${SETUP_SQL} /setup/${SETUP_SQL}
18-
COPY ${SETUP_SCRIPT} /setup/${SETUP_SCRIPT}
19-
20-
#Using env variable
21-
#RUN sed -i "s|§ROOT_PSW§|${MYSQL_ROOT_PASSWORD}|g" /setup/${SETUP_SCRIPT}
22-
23-
RUN sed -i "s|§SETUP_SQL§|${SETUP_SQL}|g" /setup/${SETUP_SCRIPT}
24-
RUN sed -i "s|§MYSQL_USER§|${MYSQL_USER}|g" /setup/${SETUP_SQL}
25-
RUN chmod +x /setup/${SETUP_SCRIPT}
7+
## Trying to initialize the DB as explained here: https://stackoverflow.com/questions/32482780/how-to-create-populated-mysql-docker-image-on-build-time
8+
## No success
9+
10+
# COPY sql_files/${SETUP_SQL} /docker-entrypoint-initdb.d/${SETUP_SQL}
11+
# RUN chmod +x /docker-entrypoint-initdb.d/${SETUP_SQL}
12+
# RUN sed -i 's|/var/lib/mysql|/var/lib/mysql2|g' /etc/mysql/my.cnf
13+
# RUN /entrypoint.sh mysqld & sleep 30 && killall mysqld
14+
# RUN rm /docker-entrypoint-initdb.d/${SETUP_SQL}
15+
16+
17+
## Running a custom script after built
18+
19+
# RUN mkdir -p /setup
20+
# COPY sql_files/${SETUP_SQL} /setup/${SETUP_SQL}
21+
# COPY ${SETUP_SCRIPT} /setup/${SETUP_SCRIPT}
22+
#
23+
# #Using env variable
24+
# #RUN sed -i "s|§ROOT_PSW§|${MYSQL_ROOT_PASSWORD}|g" /setup/${SETUP_SCRIPT}
25+
#
26+
# RUN sed -i "s|§SETUP_SQL§|${SETUP_SQL}|g" /setup/${SETUP_SCRIPT}
27+
# RUN sed -i "s|§MYSQL_USER§|${MYSQL_USER}|g" /setup/${SETUP_SQL}
28+
# RUN chmod +x /setup/${SETUP_SCRIPT}
29+
30+
## Tring mounting
31+
32+
# VOLUME /docker-entrypoint-initdb.d
33+
# RUN sed -i "s|§MYSQL_USER§|${MYSQL_USER}|g" /docker-entrypoint-initdb.d/${SETUP_SQL}
34+
# RUN chown mysql:root /var/log/mysql
35+
36+
## No mounting - only copy
37+
38+
COPY sql_files/${SETUP_SQL} /docker-entrypoint-initdb.d/${SETUP_SQL}
39+
RUN sed -i "s|§MYSQL_USER§|${MYSQL_USER}|g" /docker-entrypoint-initdb.d/${SETUP_SQL}
40+
RUN chown mysql:root /var/log/mysql
41+

db/IUB_setup.sql renamed to db/sql_files/IUB_setup.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- CREATE DATABASE test_env;
1+
CREATE DATABASE test_env;
22
--GRANT Alter ON *.* TO '§MYSQL_USER§'@'%';
33
--GRANT Create ON *.* TO '§MYSQL_USER§'@'%';
44
--GRANT Create view ON *.* TO '§MYSQL_USER§'@'%';

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ services:
2020
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
2121
ports:
2222
- ${MYSQL_PORT}:3306
23+
volumes:
24+
# - ./db/sql_files:/docker-entrypoint-initdb.d
25+
- ./db/mysql:/var/lib/mysql
2326

2427
web:
2528
image: php:7.3.13-apache

resetDB.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#Remove DB created placeholder
1010
echo "Removing placeholder"
1111
sudo rm -f site/Private/DB_created
12+
1213
#Remove DB
13-
echo "Deleting DB"
14-
mysql -uroot -p -h127.0.0.1 -P33060 -e "DROP SCHEMA my_IUB;"
14+
#~ echo "Deleting DB"
15+
#~ mysql -uroot -p -h127.0.0.1 -P33060 -e "DROP SCHEMA my_IUB;"
16+
17+
#Remove the entire DB
18+
echo "Removing the entire DB"
19+
sudo rm -rf db/mysql/*

0 commit comments

Comments
 (0)