diff --git a/myt-run.js b/myt-run.js index b2d0c1f..2993a0d 100644 --- a/myt-run.js +++ b/myt-run.js @@ -19,7 +19,8 @@ class Run extends Command { params: { ci: 'Workaround for continuous integration system', network: 'Docker network to attach container to', - random: 'Whether to use a random container name and port' + random: 'Whether to use a random container name and port', + tmpfs: 'Whether to use tmpfs mount for MySQL data' } }; @@ -27,7 +28,8 @@ class Run extends Command { alias: { ci: 'c', network: 'n', - random: 'r' + random: 'r', + tmpfs: 'r' }, boolean: [ 'ci', @@ -107,12 +109,11 @@ class Run extends Command { } if (opts.network) - Object.assign(runOptions, {network: opts.network}); - - const runChown = process.platform != 'linux'; + runOptions.network = opts.network; + if (opts.tmpfs) + runOptions.tmpfs = '/var/lib/mysql'; Object.assign(runOptions, null, { - env: `RUN_CHOWN=${runChown}`, detach: true }); const ct = await docker.run(opts.code, null, runOptions); diff --git a/package-lock.json b/package-lock.json index 2fbfa81..4dddea1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@verdnatura/myt", - "version": "1.5.35", + "version": "1.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@verdnatura/myt", - "version": "1.5.35", + "version": "1.6.1", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 170fa72..fda0985 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@verdnatura/myt", - "version": "1.6.0", + "version": "1.6.1", "author": "Verdnatura Levante SL", "description": "MySQL version control", "license": "GPL-3.0", diff --git a/server/Dockerfile.dump b/server/Dockerfile.dump index 1b3f1e2..8d13678 100644 --- a/server/Dockerfile.dump +++ b/server/Dockerfile.dump @@ -1,15 +1,14 @@ FROM myt/server -USER root - +WORKDIR /workspace COPY .dump dump/.dump COPY dump.*.sql dump/ -RUN gosu mysql docker-init.sh +RUN mkdir -p /mysql-template \ + && chown mysql:mysql /mysql-template \ + && gosu mysql docker-init.sh RUN echo "[LOG] Import finished." \ - && rm -rf /workspace + && rm -rf dump COPY fixtures.*.sql dump/ - -USER mysql diff --git a/server/Dockerfile.server b/server/Dockerfile.server index baa28a1..7f0cb3e 100644 --- a/server/Dockerfile.server +++ b/server/Dockerfile.server @@ -1,13 +1,7 @@ FROM myt/base -USER root ENV MYSQL_ROOT_PASSWORD root -RUN mkdir /mysql-data \ - && chown -R mysql:mysql /mysql-data - -WORKDIR /workspace - COPY docker.cnf /etc/mysql/conf.d/ COPY \ docker-init.sh \ @@ -15,10 +9,7 @@ COPY \ docker-start.sh \ /usr/local/bin/ -USER mysql - ENTRYPOINT ["docker-start.sh"] - CMD ["mysqld"] HEALTHCHECK --interval=2s --timeout=10s --retries=200 \ diff --git a/server/docker-init.sh b/server/docker-init.sh index 17f96a8..7302d0d 100755 --- a/server/docker-init.sh +++ b/server/docker-init.sh @@ -1,15 +1,16 @@ #!/bin/bash +set -e . /usr/local/bin/docker-entrypoint.sh -CMD=mysqld +ARGS=(mysqld --datadir=/mysql-template) -mysql_check_config "$CMD" -docker_setup_env "$CMD" +mysql_check_config ${ARGS[@]} +docker_setup_env ${ARGS[@]} docker_create_db_directories docker_verify_minimum_env -docker_init_database_dir "$CMD" -docker_temp_server_start "$CMD" +docker_init_database_dir ${ARGS[@]} +docker_temp_server_start ${ARGS[@]} docker_setup_db docker_process_init_files /docker-entrypoint-initdb.d/* diff --git a/server/docker-start.sh b/server/docker-start.sh index 1db1933..acdb521 100755 --- a/server/docker-start.sh +++ b/server/docker-start.sh @@ -1,10 +1,12 @@ #!/bin/bash +set -e # XXX: Workaround to avoid OverlayFS bug on MacOs # https://docs.docker.com/storage/storagedriver/overlayfs-driver/#limitations-on-overlayfs-compatibility -if [ "$RUN_CHOWN" = "true" ]; then - chown -R mysql:mysql /mysql-data +if [ ! -d /var/lib/mysql/mysql ]; then + chown mysql:mysql /var/lib/mysql + cp -a /mysql-template/. /var/lib/mysql fi -exec "$@" +exec gosu mysql "$@" diff --git a/server/docker.cnf b/server/docker.cnf index 4ce94d2..97642ab 100644 --- a/server/docker.cnf +++ b/server/docker.cnf @@ -3,7 +3,6 @@ innodb_log_file_size = 4M innodb_autoextend_increment = 4 innodb_page_size = 16K log_bin_trust_function_creators = ON -datadir = /mysql-data sql_mode = NO_ENGINE_SUBSTITUTION table_definition_cache = 1024 skip-log-bin