Skip to content

Latest commit

 

History

History
100 lines (75 loc) · 2.27 KB

README.md

File metadata and controls

100 lines (75 loc) · 2.27 KB

MySQL Toolkit

Toolkit for exporting, sanitizing and packaging MySQL database.

Scenario

The following example scenario showcase multiple mtk tools:

In the following scenario we will be dumping a sanitized version of the database and packaging the image into a container image which can then be consumed by developers using Docker Compose.

The benefits for this approach are:

  • Safe - The database are sanitized for safety.
  • Repeatable - Images can be recreated very quickly given they are packaged as an image.
  • Easy - Integrates with Docker Compose.

Dump

View the rules

The following rules cover some common Drupal 7/8 scenarios were data should be sanitized or dropped.

$ cat mtk.yml

---
rewrite:
  # Drupal 8.
  users_field_data:
    mail: concat(uid, "@localhost")
    # Quoting here denotes an explicit string rather than mysql expression. 
    pass: '"password"'
  # Drupal 7.
  users:
    mail: concat(uid, "@localhost")
    pass: '"password"'

nodata:
  - cache*
  - captcha_sessions
  - history
  - flood
  - batch
  - queue
  - sessions
  - semaphore
  - search_api_task
  - search_dataset
  - search_index
  - search_total

ignore:
  - __ACQUIA_MONITORING__

Dump the database

The following command will dump a sanitized version of the database using the below environment variables.

$ export MTK_DUMP_CONFIG=mtk.yml
$ export MTK_DUMP_HOSTNAME=127.0.0.1
$ export MTK_DUMP_USERNAME=root
$ export MTK_DUMP_PASSWORD=password
$ export MTK_DUMP_DATABASE=test

$ mtk-dump > db.sql

Build

$ docker run -it -v $HOME/.docker:/kaniko/.docker \
                 -v $(pwd):/workspace \
                 skpr/mtk-build:latest --context=/workspace \
                                       --dockerfile=/Dockerfile \
                                       --single-snapshot \
                                       --verbosity fatal \
                                       --destination=docker.io/my/image:latest \
                                       --destination=docker.io/my/image:$(date +%F)

Integrate

$ cat docker-compose.yml

---
version: "3"

services:

  # Services used as part of the local development environment.
  mysql:
    image: docker.io/my/image:latest