diff --git a/gulpfile.js b/gulpfile.js index 5d86d5972..a27d8f9c2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -433,9 +433,12 @@ gulp.task('docker-build', async () => { try { await execP('docker rmi dblocal:latest'); } catch (e) {} + try { + await execP('docker volume rm data'); + } catch (e) {} log('Building image...'); - log(await execP('docker build -t dblocal:latest ./services/db > ./services/db/docker.log')); + await execP('docker build -t dblocal:latest ./services/db'); }); /** @@ -469,7 +472,7 @@ gulp.task('docker-start', async () => { gulp.task('docker-run', async () => { try { await execP('docker image inspect -f "{{json .Id}}" dblocal'); - await execP('docker run -d --name dblocal -p 3306:3306 dblocal'); + await execP('docker run -d --name dblocal --volume data:/data -p 3306:3306 dblocal'); await runSequenceP('docker-wait'); } catch (err) { await runSequenceP('docker-build'); @@ -484,7 +487,7 @@ gulp.task('docker-wait', callback => { let interval = 1; let elapsedTime = 0; - let maxInterval = 45 * 60; + let maxInterval = 30 * 60; log('Waiting for MySQL init process...'); checker(); diff --git a/services/db/Dockerfile b/services/db/Dockerfile index a738c8aef..52ff33253 100644 --- a/services/db/Dockerfile +++ b/services/db/Dockerfile @@ -1,10 +1,12 @@ FROM verdnatura/vn-mysql:latest +ENV MYSQL_ROOT_PASSWORD root ENV TZ GMT-1 WORKDIR /docker-entrypoint-initdb.d -COPY install/ ./ +COPY install ./ RUN chmod -R 777 . -RUN ./install.sh -CMD ./boot.sh +RUN mkdir /data +RUN chmod 777 /data +CMD ["mysqld"] #HEALTHCHECK --interval=5s --timeout=10s --retries=200 \ # CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1 EXPOSE 3306 \ No newline at end of file diff --git a/services/db/install/boot.sh b/services/db/install/boot.sh index 47dd15e13..208b5e4bc 100644 --- a/services/db/install/boot.sh +++ b/services/db/install/boot.sh @@ -1,8 +1,26 @@ #!/bin/bash -find /var/lib/mysql -type f -exec touch {} \; && service mysql start +if [ -d /data/mysql ]; then + cp -R /data/mysql /var/lib + echo "Restored database to default state" +else -# Disable SQL strict mode -mysql -u root -proot -e "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" + # Dump structure + for file in dump/*-*.sql; do + echo "Imported $file" + mysql -u root -proot < $file + done -sleep infinity \ No newline at end of file + # Import changes + for file in changes/*/*.sql; do + echo "Imported $file" + mysql -u root -proot < $file + done + + # Import fixtures + echo "Imported fixtures.sql" + mysql -u root -proot < dump/fixtures.sql + + # Copy dumpted data to volume + cp -R /var/lib/mysql /data +fi \ No newline at end of file diff --git a/services/db/install/install.sh b/services/db/install/install.sh deleted file mode 100644 index b99c6e387..000000000 --- a/services/db/install/install.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Start MySQL service -find /var/lib/mysql -type f -exec touch {} \; && service mysql start - -# Disable SQL strict mode -mysql -u root -proot -e "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" - -# Dump structure -for file in dump/*-*.sql; do - echo "Imported $file" - mysql -u root -proot < $file -done - -# Import changes -for file in changes/*/*.sql; do - echo "Imported $file" - mysql -u root -proot < $file -done - -# Import fixtures -echo "Imported fixtures.sql" -mysql -u root -proot < dump/fixtures.sql - - -# Remove installation -rm -rf changes dump install.sh \ No newline at end of file