Skip to content

Instantly share code, notes, and snippets.

@trajano
Created July 16, 2020 19:19
Show Gist options
  • Save trajano/163673d7bb5123f0b32f90581dc92ba8 to your computer and use it in GitHub Desktop.
Save trajano/163673d7bb5123f0b32f90581dc92ba8 to your computer and use it in GitHub Desktop.
Preloaded anonymized data
#!/bin/bash
head -n -1 /usr/local/bin/docker-entrypoint.sh > /d2.sh
chmod +x /d2.sh
exec bash -x /d2.sh \
--skip-character-set-client-handshake \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci \
--lower_case_table_names=1 \
--innodb-flush-log-at-trx-commit=2 \
--sql-mode="" \
--innodb_buffer_pool_size=268435456 \
--innodb_log_file_size=52428800 \
--innodb_flush_method=nosync \
--datadir=/data
# This is only used for development. The production will use AWS RDS
FROM mysql:5.7.23 as prep
# Copy your anonymized files
COPY *.anon.sql /docker-entrypoint-initdb.d/
# zz.grant-all-to-sample-user.sql script that to change the permissions on the anonymized data in case it is not owned by the test user
# grant all on *.* TO 'sampleuser'@'%';
COPY scripts/*.sql /docker-entrypoint-initdb.d/
# zz.mysqld.cnf file that looks like this to configure runtime settings for the database
# [mysqld]
# character-set-client-handshake=0
# character-set-server=utf8mb4
# collation-server=utf8mb4_unicode_ci
# lower_case_table_names=1
# sql-mode=""
# datadir=/data
# max_connections = 500
COPY scripts/*.cnf /etc/mysql/mysql.conf.d/
# build-db.sh strips off the last line of docker-entrypoint which starts up mysqld. So it terminates the container after it does the initial load (I think I'll add this as RUN commands in a future version now that I look at this)
# #!/bin/bash
# head -n -1 /usr/local/bin/docker-entrypoint.sh > /d2.sh
# chmod +x /d2.sh
# exec bash -x /d2.sh --skip-character-set-client-handshake --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1 --innodb-flush-log-at-trx-commit=2 --sql-mode="" --innodb_buffer_pool_size=268435456 --innodb_log_file_size=52428800 --innodb_flush_method=nosync --datadir=/data
COPY scripts/build-db.sh /
ARG MYSQL_ROOT_PASSWORD=mypassword
ARG MYSQL_USER=sampleuser
ARG MYSQL_PASSWORD=password123
RUN chmod u+x /build-db.sh
RUN /build-db.sh
FROM mysql:5.7.23
# Only copy the important ones
COPY scripts/zz.grant-all-to-sample-user.sql /docker-entrypoint-initdb.d/
COPY scripts/zz.mysqld.cnf /etc/mysql/mysql.conf.d/
# Finally preload the data that was originally built
COPY --from=prep /data/ /data/
[mysqld]
character-set-client-handshake=0
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
lower_case_table_names=1
sql-mode=""
datadir=/data
max_connections = 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment