Added gulp task docker-image.

This commit is contained in:
Joan Sanchez 2018-04-26 15:13:56 +02:00
parent 9f3609a3be
commit e4b536e439
20 changed files with 91 additions and 52 deletions

View File

@ -411,18 +411,36 @@ gulp.task('watch', function() {
// Docker
/**
* Rebuilds the docker and it's image, if these already exist, destroys and
* rebuilds them.
* Rebuilds the docker, if already exists, destroys and
* rebuild it.
*/
gulp.task('docker', async () => {
try {
await execP('docker rm -f dblocal');
} catch (e) {}
await runSequenceP('docker-run');
});
/**
* Rebuilds the docker image, if these already exist, destroys and
* rebuilds them.
*/
gulp.task('docker-image', async () => {
try {
await execP('docker rm -f dblocal');
} catch (e) {}
try {
await execP('docker rmi dblocal:latest');
} catch (e) {}
await runSequenceP('docker-run');
log('Building image...');
await execP('docker build -t dblocal:latest ./services/db');
log('Starting container...');
await execP('docker run -d --name dblocal -p 3306:3306 dblocal');
await runSequenceP('docker-wait');
log('Making container snapshot...');
await execP('docker commit dblocal dblocal:latest');
});
/**
@ -457,7 +475,7 @@ gulp.task('docker-run', async () => {
try {
await execP('docker image inspect -f "{{json .Id}}" dblocal');
} catch (err) {
await execP('docker build -t dblocal:latest ./services/db');
await runSequenceP('docker-image');
}
await execP('docker run -d --name dblocal -p 3306:3306 dblocal');
@ -472,7 +490,7 @@ gulp.task('docker-wait', callback => {
let interval = 1;
let elapsedTime = 0;
let maxInterval = 30 * 60;
let maxInterval = 45 * 60;
log('Waiting for MySQL init process...');
checker();

View File

@ -1,6 +0,0 @@
#!/bin/bash
for file in changes/*/*.sql; do
echo "Importing $file"
mysql -u root -proot < $file
done

View File

@ -1,17 +1,11 @@
FROM mysql:5.6.37
ENV MYSQL_ROOT_PASSWORD root
FROM verdnatura/vn-mysql:latest
ENV TZ GMT-1
WORKDIR /docker-entrypoint-initdb.d
COPY *.sql ./
COPY 03-changes.sh .
COPY changes changes
RUN chmod -R 755 .
COPY install/ ./
RUN chmod -R 777 .
RUN ./install.sh
USER mysql
CMD ["mysqld"]
#HEALTHCHECK --interval=5s --timeout=10s --retries=200 \
# CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1
EXPOSE 3306

View File

@ -1,16 +1,16 @@
::IMPORTANT Any changes in this file are to applyed to mirror file export-data.sh
echo USE `account`; > 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info account role roleRole roleInherit >> 02-dumpedFixtures.sql
echo USE `salix`; >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info salix ACL >> 02-dumpedFixtures.sql
echo USE `vn`; >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc >> 02-dumpedFixtures.sql
echo USE `vn2008`; >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options >> 02-dumpedFixtures.sql
echo USE `bi`; >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> 02-dumpedFixtures.sql
echo USE `cache`; >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info cache cache >> 02-dumpedFixtures.sql
echo USE `account`; > install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info account role roleRole roleInherit >> install/dump/03-dumpedFixtures.sql
echo USE `salix`; >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info salix ACL >> install/dump/03-dumpedFixtures.sql
echo USE `vn`; >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc >> install/dump/03-dumpedFixtures.sql
echo USE `vn2008`; >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options >> install/dump/03-dumpedFixtures.sql
echo USE `bi`; >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> install/dump/03-dumpedFixtures.sql
echo USE `cache`; >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info cache cache >> install/dump/03-dumpedFixtures.sql

View File

@ -1,17 +1,17 @@
#!/bin/bash
#IMPORTANT Any changes in this file are to applyed to mirror file export-data.cmd
echo "USE \`account\`;" > 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info account role roleRole roleInherit >> 02-dumpedFixtures.sql
echo "USE \`salix\`;" >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info salix ACL >> 02-dumpedFixtures.sql
echo "USE \`vn\`;" >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc >> 02-dumpedFixtures.sql
echo "USE \`vn2008\`;" >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options >> 02-dumpedFixtures.sql
echo "USE \`bi\`;" >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> 02-dumpedFixtures.sql
echo "USE \`cache\`;" >> 02-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info cache cache >> 02-dumpedFixtures.sql
echo "USE \`account\`;" > install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info account role roleRole roleInherit >> install/dump/03-dumpedFixtures.sql
echo "USE \`salix\`;" >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info salix ACL >> install/dump/03-dumpedFixtures.sql
echo "USE \`vn\`;" >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc >> install/dump/03-dumpedFixtures.sql
echo "USE \`vn2008\`;" >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options >> install/dump/03-dumpedFixtures.sql
echo "USE \`bi\`;" >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> install/dump/03-dumpedFixtures.sql
echo "USE \`cache\`;" >> install/dump/03-dumpedFixtures.sql
mysqldump --defaults-file=connect.ini --no-create-info cache cache >> install/dump/03-dumpedFixtures.sql

View File

@ -1,2 +1,2 @@
::IMPORTANT Any changes in this file are to applyed to mirror file export-structure.sh
mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock > 01-structure.sql
mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock > install/dump/01-structure.sql

View File

@ -1,3 +1,3 @@
#!/bin/bash
#IMPORTANT Any changes in this file are to applyed to mirror file export-structure.cmd
mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock > 01-structure.sql
mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock > install/dump/01-structure.sql

View File

@ -8,7 +8,7 @@ const fs = require('fs-extra');
user: 'root',
multipleStatements: true
});
let changesDir = './changes';
let changesDir = './install/changes';
let results = await connection.query("SELECT dbVersion FROM util.config");
if (results[0].length != 1)
throw new Error('There must be exactly one row in the configuration table');

View File

@ -8,7 +8,7 @@ const fs = require('fs-extra');
user: 'root',
multipleStatements: true
});
sql = await fs.readFile(`04-fixtures.sql`, 'utf8');
sql = await fs.readFile(`install/dump/fixtures.sql`, 'utf8');
await connection.query(sql);
await connection.end();
process.exit();

View File

@ -0,0 +1,5 @@
USE `vn2008`;
-- Import compiled functions
CREATE AGGREGATE FUNCTION minacum RETURNS INT SONAME 'minacum.so';
CREATE AGGREGATE FUNCTION multimax RETURNS INT SONAME 'multimax.so';

View File

@ -0,0 +1,28 @@
#!/bin/bash
# Start MySQL service
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" >> log.txt
mysql -u root -proot < $file
done
# Import changes
for file in changes/*/*.sql; do
echo "Imported $file" >> log.txt
mysql -u root -proot < $file
done
# Import fixtures
echo "Imported fixtures.sql" >> log.txt
mysql -u root -proot < dump/fixtures.sql >> log.txt
# Remove installation
#rm -rf /docker-entrypoint-initdb.d