Skip to content

Commit b8d3b49

Browse files
committed
SLT-17: Periodical drush SQL-Dump using gdpr-dump; Fallback to standard drush sql-dump when the gdpr.json file can't be located; Documentation;
1 parent b54ba9b commit b8d3b49

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

.circleci/config.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ jobs:
2222
keys:
2323
- v1-dependencies-{{ checksum "composer.lock" }}
2424

25-
- run: composer install -n --prefer-dist --ignore-platform-reqs --no-dev
25+
- run: |
26+
composer install -n --prefer-dist --ignore-platform-reqs --no-dev
27+
composer config repositories.gdpr-dump-mods git https://github.com/Jancis/gdpr-dump
28+
composer require machbarmacher/gdpr-dump:dev-mods -n --ignore-platform-reqs
2629
2730
- save_cache:
2831
paths:

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Dockerfile for the Drupal container.
22
FROM wunderio/drupal-php-fpm:v0.1
33

4+
USER root
5+
RUN mkdir -p /var/backups/db
6+
RUN chown www-data:www-data /var/backups/db
7+
48
COPY --chown=www-data:www-data . /var/www/html
59
USER www-data
610
RUN mkdir -p -m +w /var/www/html/web/sites/default/files

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project template is an opinionated fork of the popular [Drupal-composer tem
88

99
- Copy this repository and push it to our organization.
1010
- Log in to CircleCI using your Github account and add the new project.
11-
11+
- Create and maintain a Personal Data mapping list for automatic data sanitization in `gdpr.json` file. See GDPR sanitization section for more information.
1212

1313
## How it works
1414

@@ -21,3 +21,35 @@ Have a look at the file for details, but in short this is how it works:
2121
- Create a custom docker image for Drupal and nginx, and push those to a docker registry (typically that of your cloud provider).
2222
- Install or update our helm chart while passing our custom images as parameters.
2323
- The helm chart executes the usual drush deployment commands.
24+
25+
## GDPR sanitization
26+
27+
SQL data dump for developers is parsed with [GDPR Tools](https://github.com/machbarmacher/gdpr-dump) project.
28+
You can create a `/gdpr.json` file with [Faker](https://packagist.org/packages/fzaninotto/faker) formatters that will allow replacing data as it's dumped from database using `mysqldump` / `drush sql-dump` command.
29+
30+
```
31+
{
32+
"users_field_data": {
33+
"name": {"formatter": "name"},
34+
"pass": {"formatter": "password"},
35+
"mail": {"formatter": "email"},
36+
"init": {"formatter": "clear"}
37+
}
38+
}
39+
```
40+
Available formatters:
41+
```
42+
**name** - generates a name
43+
**phoneNumber** - generates a phone number
44+
**username** - generates a random user name
45+
**password** - generates a random password
46+
**email** - generates a random email address
47+
**date** - generates a date
48+
**longText** - generates a sentence
49+
**number** - generates a number
50+
**randomText** - generates a sentence
51+
**text** - generates a paragraph
52+
**uri** - generates a URI
53+
**clear** - generates an empty string
54+
```
55+
You can also add extra elements and attributes, like `_cookies`, `_description` or `_purpose` to enrich the Personal Data information. Just make sure it's marked or prefixed so that it does not mess up GDPR dump when it looks for table data replacements.

chart/templates/_helpers.tpl

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ volumeMounts:
2121
- name: drupal-private-files
2222
mountPath: /var/www/html/private
2323
{{- end }}
24+
- name: drupal-dbdump-volume
25+
mountPath: /var/backups/db
2426
- name: php-conf
2527
mountPath: /etc/php7/php.ini
2628
readOnly: true
@@ -44,6 +46,9 @@ volumeMounts:
4446
persistentVolumeClaim:
4547
claimName: {{ .Release.Name }}-private-files
4648
{{- end }}
49+
- name: drupal-dbdump-volume
50+
persistentVolumeClaim:
51+
claimName: {{ .Release.Namespace }}-dbdump
4752
- name: php-conf
4853
configMap:
4954
name: {{ .Release.Name }}-php-conf
@@ -64,6 +69,10 @@ imagePullSecrets:
6469
{{- end }}
6570

6671
{{- define "drupal.env" }}
72+
- name: BRANCHNAME
73+
value: {{ .Values.branchname }}
74+
- name: PRODUCTION_BRANCHNAME
75+
value: {{ .Values.production_branchname | default "production" }}
6776
{{- if .Values.mariadb.enabled }}
6877
- name: DB_USER
6978
value: "{{ .Values.mariadb.db.user }}"

chart/values.yaml

+20-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,24 @@ drupal:
1313

1414
cron:
1515
- schedule: '0 * * * *'
16-
command: 'drush cron'
16+
command: 'bootstrapped=$(drush status --field=bootstrap);
17+
if [[ $bootstrapped = "Successful" ]];
18+
then
19+
drush cron;
20+
fi;'
21+
- schedule: '0 3 * * *'
22+
command: 'bootstrapped=$(drush status --field=bootstrap);
23+
if [[ $bootstrapped = "Successful" ]] && [[ "$BRANCHNAME" = "$PRODUCTION_BRANCHNAME" ]];
24+
then
25+
DUMP_PATH=/var/backups/db/${BRANCHNAME//[^[:alnum:]]/-}-latest.sql;
26+
rm $DUMP_PATH;
27+
if [ -f ../gdpr.json ]; then
28+
export PATH=../vendor/bin:$PATH;
29+
drush sql-dump --extra-dump="--gdpr-replacements-file=../gdpr.json" --result-file $DUMP_PATH;
30+
else
31+
drush sql-dump --result-file $DUMP_PATH;
32+
fi
33+
fi;'
1734

1835
# will be generated random hashsalt if not provided here
1936
# need to be base64 encoded
@@ -75,4 +92,5 @@ clusterDomain: "silta.wdr.io"
7592
# See https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
7693
imagePullSecrets: []
7794

78-
branchname: "default"
95+
branchname: "default"
96+
production_branchname: "master"

gdpr.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"users_field_data": {
3+
"name": {"formatter": "name"},
4+
"pass": {"formatter": "password"},
5+
"mail": {"formatter": "email"},
6+
"init": {"formatter": "clear"}
7+
}
8+
}

0 commit comments

Comments
 (0)