Skip to content

Commit ae0456d

Browse files
committed
init
1 parent 4d8704c commit ae0456d

File tree

12 files changed

+343
-1
lines changed

12 files changed

+343
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.twgit_features_subject
2+
/.twgit

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project follows MariaDB versioning.
6+
7+
## 10.2.14 - 2018-04-13
8+
Initial release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Osixia
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
NAME = osixia/mariadb-helper
2+
VERSION = 10.2.14
3+
4+
.PHONY: build build-nocache test tag-latest push push-latest release git-tag-version
5+
6+
build:
7+
docker build -t $(NAME):$(VERSION) --rm image
8+
9+
build-nocache:
10+
docker build -t $(NAME):$(VERSION) --no-cache --rm image
11+
12+
test:
13+
env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats
14+
15+
tag-latest:
16+
docker tag $(NAME):$(VERSION) $(NAME):latest
17+
18+
push:
19+
docker push $(NAME):$(VERSION)
20+
21+
push-latest:
22+
docker push $(NAME):latest
23+
24+
release: build test tag-latest push push-latest
25+
26+
git-tag-version: release
27+
git tag -a v$(VERSION) -m "v$(VERSION)"
28+
git push origin v$(VERSION)

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# mariadb-helper
1+
# osixia/mariadb-helper
2+
3+
[![Docker Pulls](https://img.shields.io/docker/pulls/osixia/mariadb-helper.svg)][hub]
4+
[![Docker Stars](https://img.shields.io/docker/stars/osixia/mariadb-helper.svg)][hub]
5+
[![](https://images.microbadger.com/badges/image/osixia/mariadb-helper.svg)](http://microbadger.com/images/osixia/mariadb-helper "Get your own image badge on microbadger.com")
6+
7+
[hub]: https://hub.docker.com/r/osixia/mariadb-helper/
8+
9+
## Security
10+
If you discover a security vulnerability within this docker image, please send an email to the Osixia! team at [email protected]. For minor vulnerabilities feel free to add an issue here on github.
11+
12+
Please include as many details as possible.
13+
14+
## Changelog
15+
16+
Please refer to: [CHANGELOG.md](CHANGELOG.md)

image/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Use osixia/light-baseimage
2+
# sources: https://github.com/osixia/docker-light-baseimage
3+
FROM osixia/light-baseimage:1.1.1
4+
MAINTAINER Bertrand Gouny <[email protected]>
5+
6+
# MariaDB version
7+
ARG MARIADB_MAJOR=10.2
8+
ARG MARIADB_VERSION=10.2.14+maria~stretch
9+
10+
# Add MariaDB repository
11+
RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 \
12+
&& echo "deb http://ftp.igh.cnrs.fr/pub/mariadb/repo/$MARIADB_MAJOR/debian stretch main" > /etc/apt/sources.list.d/mariadb.list \
13+
&& { \
14+
echo 'Package: *'; \
15+
echo 'Pin: release o=MariaDB'; \
16+
echo 'Pin-Priority: 999'; \
17+
} > /etc/apt/preferences.d/mariadb
18+
# add repository pinning to make sure dependencies from this MariaDB repo are preferred over Debian dependencie
19+
20+
# Add multiple process stack and ssl tools
21+
# sources: https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/add-multiple-process-stack
22+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/add-service-available
23+
#  https://github.com/osixia/docker-light-baseimage/blob/stable/image/service-available/:ssl-tools/download.sh
24+
# Install MariaDB and xtrabackup
25+
RUN apt-get -y update \
26+
&& /container/tool/add-service-available :ssl-tools \
27+
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
28+
mariadb-client=$MARIADB_VERSION \
29+
&& apt-get clean \
30+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
31+
32+
# Add service directory to /container/service
33+
ADD service /container/service
34+
35+
# Use baseimage install-service script
36+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/install-service
37+
RUN /container/tool/install-service
38+
39+
# Add default env variables
40+
ADD environment /container/environment/99-default
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
MARIADB_HOST: mariadb
2+
3+
MARIADB_FROM_DATABASE: stable
4+
MARIADB_TO_DATABASE: example-app-hotfix-0-1-19
5+
6+
MARIADB_TO_DATABASE_GRANT_USER: admin
7+
MARIADB_TO_DATABASE_GRANT_USER_HOST: 127.0.0.1
8+
MARIADB_TO_DATABASE_GRANT_PRIVILEGES: ALL
9+
10+
# Prefix MARIADB_FROM_DATABASE database with MARIADB_TO_DATABASE regex capture group
11+
# example:
12+
# MARIADB_FROM_DATABASE: stable
13+
# MARIADB_TO_DATABASE: example-app-hotfix-0-1-19
14+
# MARIADB_FROM_DATABASE_REGEX: (.*-)[feature|release|hotfix|demo].*
15+
#
16+
# MARIADB_FROM_DATABASE will becomes: example-app-stable
17+
MARIADB_FROM_DATABASE_REGEX: "(.*-)[feature|release|hotfix|demo].*"
18+
19+
MARIADB_ROOT_USER: admin
20+
MARIADB_ROOT_PASSWORD: admin
21+
22+
# ssl
23+
MARIADB_SSL: true
24+
MARIADB_SSL_CIPHER_SUITE: TLSv1.2
25+
26+
MARIADB_SSL_CRT_FILENAME: mariadb.crt
27+
MARIADB_SSL_KEY_FILENAME: mariadb.key
28+
MARIADB_SSL_CA_CRT_FILENAME: ca.crt
29+
30+
# ssl-helper environment variables prefix
31+
MARIADB_SSL_HELPER_PREFIX: database # ssl-helper first search config from DATABASE_SSL_HELPER_* variables, before SSL_HELPER_* variables.
32+
33+
DSN_EXPORT_FILE:
34+
DSN_EXPORT_VARIABLE_NAME:
35+
DSN_HOST:
36+
DSN_USER:
37+
DSN_PASSWORD:
38+
DSN_DATABASE:
39+
DSN_ARGS:

image/service/dsn-helper/startup.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
# set -x (bash debug) if log level is trace
5+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
6+
log-helper level eq trace && set -x
7+
8+
if [ -n "${DSN_EXPORT_FILE}" ]; then
9+
10+
if [ -z "${DSN_EXPORT_VARIABLE_NAME}" ]; then
11+
log-helper error "Error: DSN_EXPORT_VARIABLE_NAME must be set"
12+
exit 1
13+
fi
14+
15+
mkdir -p "$(dirname "${DSN_EXPORT_FILE}")" && touch "${DSN_EXPORT_FILE}"
16+
17+
DSN="${DSN_EXPORT_VARIABLE_NAME}=${DSN_USER}:${DSN_PASSWORD}@tcp(${DSN_HOST}:3306)/${DSN_DATABASE}${DSN_ARGS}"
18+
19+
log-helper debug "Export ${DSN} to ${DSN_EXPORT_FILE}"
20+
echo "${DSN}" > ${DSN_EXPORT_FILE}
21+
log-helper info "Done."
22+
23+
fi
24+
25+
exit 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add your ssl server certificate, key and the CA certificate (if any) here
2+
or during docker run mount a data volume with those files to /container/service/mariadb-helper/assets/certs
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
# set -x (bash debug) if log level is trace
5+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
6+
log-helper level eq trace && set -x
7+
8+
if [ -z "${MARIADB_HOST}" ]; then
9+
log-helper error "Error: MARIADB_HOST must be set."
10+
exit 0
11+
fi
12+
13+
if [ -z "${MARIADB_FROM_DATABASE}" ] || [ -z "${MARIADB_TO_DATABASE}" ]; then
14+
log-helper error "Error: MARIADB_FROM_DATABASE and MARIADB_TO_DATABASE must be set."
15+
exit 0
16+
fi
17+
18+
if [ -z "${MARIADB_ROOT_USER}" ] || [ -z "${MARIADB_ROOT_PASSWORD}" ]; then
19+
log-helper error "Error: MARIADB_ROOT_USER and MARIADB_ROOT_PASSWORD must be set."
20+
exit 0
21+
fi
22+
23+
MARIADB_SSL_CMD_ARGS=""
24+
25+
if [ "${MARIADB_SSL,,}" == "true" ]; then
26+
log-helper info "SSL config..."
27+
28+
# generate a certificate and key with ssl-helper if MARIADB_SSL_CRT_FILENAME and MARIADB_SSL_KEY_FILENAME files don't exists
29+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/service-available/:ssl-tools/assets/tool/ssl-helper
30+
ssl-helper ${MARIADB_SSL_HELPER_PREFIX} "${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_CRT_FILENAME" "${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_KEY_FILENAME" "${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_CA_CRT_FILENAME"
31+
32+
MARIADB_SSL_CMD_ARGS="--ssl --ssl-ca ${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_CA_CRT_FILENAME --ssl-cert ${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_CRT_FILENAME --ssl-key ${CONTAINER_SERVICE_DIR}/mariadb-helper/assets/certs/$MARIADB_SSL_KEY_FILENAME --ssl-cipher ${MARIADB_SSL_CIPHER_SUITE}"
33+
fi
34+
35+
MARIADB_CMD_ARGS="-h${MARIADB_HOST} -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${MARIADB_SSL_CMD_ARGS}"
36+
37+
log-helper info "Creating database ${MARIADB_TO_DATABASE} on host ${MARIADB_HOST}..."
38+
mysqladmin ${MARIADB_CMD_ARGS} create ${MARIADB_TO_DATABASE}
39+
40+
CREATE_CMD_RESULT=$?
41+
42+
if [ $CREATE_CMD_RESULT -eq 255 ]; then
43+
log-helper info "Database ${MARIADB_TO_DATABASE} already exists."
44+
exit 0
45+
elif [ $CREATE_CMD_RESULT -eq 0 ]; then
46+
log-helper info "Database ${MARIADB_TO_DATABASE} created."
47+
48+
if [ -n "${MARIADB_TO_DATABASE_GRANT_USER}" ]; then
49+
log-helper info "Grant user ${MARIADB_TO_DATABASE_GRANT_USER} permissions on database ${MARIADB_TO_DATABASE}..."
50+
mysql ${MARIADB_CMD_ARGS} -e "GRANT ${MARIADB_TO_DATABASE_GRANT_PRIVILEGES} ON \`${MARIADB_TO_DATABASE}\`.* TO '${MARIADB_TO_DATABASE_GRANT_USER}'@'${MARIADB_TO_DATABASE_GRANT_USER_HOST}' ;" ${MARIADB_TO_DATABASE}
51+
fi
52+
53+
if [ -n "${MARIADB_FROM_DATABASE_REGEX}" ]; then
54+
log-helper debug "Use regex ${MARIADB_FROM_DATABASE_REGEX} on ${MARIADB_TO_DATABASE}"
55+
56+
if ! [[ ${MARIADB_TO_DATABASE} =~ ${MARIADB_FROM_DATABASE_REGEX} ]]; then
57+
log-helper error "Enable to extract database name."
58+
exit 1
59+
else
60+
MARIADB_FROM_DATABASE="${BASH_REMATCH[1]}${MARIADB_FROM_DATABASE}"
61+
fi
62+
fi
63+
64+
if [ "${MARIADB_FROM_DATABASE}" == "${MARIADB_TO_DATABASE}" ]; then
65+
log-helper warning "MARIADB_FROM_DATABASE == MARIADB_TO_DATABASE == ${MARIADB_TO_DATABASE} copy aborted."
66+
else
67+
log-helper info "Copying database ${MARIADB_FROM_DATABASE} to ${MARIADB_TO_DATABASE}..."
68+
mysqldump ${MARIADB_CMD_ARGS} --no-create-db --events --triggers --routines --compress ${MARIADB_FROM_DATABASE} | mysql ${MARIADB_CMD_ARGS} ${MARIADB_TO_DATABASE}
69+
fi
70+
71+
else
72+
log-helper info "Error."
73+
exit 1
74+
fi
75+
76+
log-helper info "Done."
77+
78+
exit 0

0 commit comments

Comments
 (0)