Skip to content

Commit 6b5c285

Browse files
authored
Merge pull request #201 from hhorak/s2i-support
Implement s2i and general extendability support
2 parents cff3523 + 301111e commit 6b5c285

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+604
-114
lines changed

5.6/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM centos:centos7
1+
FROM centos/s2i-core-centos7
22

33
# MySQL image for OpenShift.
44
#
@@ -11,6 +11,7 @@ FROM centos:centos7
1111
# * $MYSQL_ROOT_PASSWORD (Optional) - Password for the 'root' MySQL account
1212

1313
ENV MYSQL_VERSION=5.6 \
14+
APP_DATA=/opt/app-root/src \
1415
HOME=/var/lib/mysql
1516

1617
ENV SUMMARY="MySQL 5.6 SQL database server" \
@@ -35,9 +36,10 @@ EXPOSE 3306
3536
# This image must forever use UID 27 for mysql user so our volumes are
3637
# safe in the future. This should *never* change, the last test is there
3738
# to make sure of that.
38-
RUN yum install -y centos-release-scl && \
39-
INSTALL_PKGS="tar rsync gettext hostname bind-utils rh-mysql56" && \
40-
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
39+
RUN yum install -y yum-utils && \
40+
yum install -y centos-release-scl && \
41+
INSTALL_PKGS="rsync tar gettext hostname bind-utils groff-base shadow-utils rh-mysql56" && \
42+
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
4143
rpm -V $INSTALL_PKGS && \
4244
yum clean all && \
4345
mkdir -p /var/lib/mysql/data && chown -R mysql.0 /var/lib/mysql && \
@@ -56,12 +58,13 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
5658
PROMPT_COMMAND=". ${CONTAINER_SCRIPTS_PATH}/scl_enable"
5759

5860
COPY 5.6/root-common /
61+
COPY 5.6/s2i-common/bin/ $STI_SCRIPTS_PATH
5962
COPY 5.6/root /
6063

6164
# this is needed due to issues with squash
6265
# when this directory gets rm'd by the container-setup
6366
# script.
64-
RUN rm -rf /etc/my.cnf.d/*
67+
RUN rm -rf /etc/my.cnf.d/*
6568
RUN /usr/libexec/container-setup
6669

6770
VOLUME ["/var/lib/mysql/data"]

5.6/Dockerfile.rhel7

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rhel7
1+
FROM rhscl/s2i-core-rhel7
22

33
# MySQL image for OpenShift.
44
#
@@ -11,6 +11,7 @@ FROM rhel7
1111
# * $MYSQL_ROOT_PASSWORD (Optional) - Password for the 'root' MySQL account
1212

1313
ENV MYSQL_VERSION=5.6 \
14+
APP_DATA=/opt/app-root/src \
1415
HOME=/var/lib/mysql
1516

1617
ENV SUMMARY="MySQL 5.6 SQL database server" \
@@ -43,7 +44,7 @@ RUN yum repolist > /dev/null && \
4344
yum-config-manager --enable rhel-7-server-rpms && \
4445
yum-config-manager --enable rhel-7-server-optional-rpms && \
4546
yum-config-manager --enable rhel-server-rhscl-7-rpms && \
46-
INSTALL_PKGS="rsync tar gettext hostname bind-utils rh-mysql56" && \
47+
INSTALL_PKGS="rsync tar gettext hostname bind-utils groff-base shadow-utils rh-mysql56" && \
4748
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
4849
rpm -V $INSTALL_PKGS && \
4950
yum clean all && \
@@ -63,12 +64,13 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
6364
PROMPT_COMMAND=". ${CONTAINER_SCRIPTS_PATH}/scl_enable"
6465

6566
COPY 5.6/root-common /
67+
COPY 5.6/s2i-common/bin/ $STI_SCRIPTS_PATH
6668
COPY 5.6/root /
6769

6870
# this is needed due to issues with squash
6971
# when this directory gets rm'd by the container-setup
7072
# script.
71-
RUN rm -rf /etc/my.cnf.d/*
73+
RUN rm -rf /etc/my.cnf.d/*
7274
RUN /usr/libexec/container-setup
7375

7476
VOLUME ["/var/lib/mysql/data"]

5.6/root/usr/share/container-scripts/mysql/README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ or if it was already present, `mysqld` is executed and will run as PID 1. You ca
4444
stop the detached container by running `docker stop mysql_database`.
4545

4646

47-
4847
Environment variables and volumes
4948
---------------------------------
5049

@@ -142,6 +141,81 @@ location is `/etc/my.cnf` but you can change it to `/etc/mysql/my.cnf` by settin
142141
`MYSQL_DEFAULTS_FILE=/etc/mysql/my.cnf`
143142

144143

144+
Extending image
145+
---------------
146+
This image can be extended using [source-to-image](https://github.com/openshift/source-to-image).
147+
148+
For example, to build a customized MariaDB database image `my-mysql-rhel7`
149+
with a configuration in `~/image-configuration/` run:
150+
151+
```
152+
$ s2i build ~/image-configuration/ rhscl/mysql-56-rhel7 my-mysql-rhel7
153+
```
154+
155+
The directory passed to `s2i build` can contain these directories:
156+
157+
`mysql-cfg/`
158+
When starting the container, files from this directory will be used as
159+
a configuration for the `mysqld` daemon.
160+
`envsubst` command is run on this file to still allow customization of
161+
the image using environmental variables
162+
163+
`mysql-pre-init/`
164+
Shell scripts (`*.sh`) available in this directory are sourced before
165+
`mysqld` daemon is started.
166+
167+
`mysql-init/`
168+
Shell scripts (`*.sh`) available in this directory are sourced when
169+
`mysqld` daemon is started locally. In this phase, use `${mysql_flags}`
170+
to connect to the locally running daemon, for example `mysql $mysql_flags < dump.sql`
171+
172+
Variables that can be used in the scripts provided to s2i:
173+
174+
`$mysql_flags`
175+
arguments for the `mysql` tool that will connect to the locally running `mysqld` during initialization
176+
177+
`$MYSQL_RUNNING_AS_MASTER`
178+
variable defined when the container is run with `run-mysqld-master` command
179+
180+
`$MYSQL_RUNNING_AS_SLAVE`
181+
variable defined when the container is run with `run-mysqld-slave` command
182+
183+
`$MYSQL_DATADIR_FIRST_INIT`
184+
variable defined when the container was initialized from the empty data dir
185+
186+
During `s2i build` all provided files are copied into `/opt/app-root/src`
187+
directory into the resulting image. If some configuration files are present
188+
in the destination directory, files with the same name are overwritten.
189+
Also only one file with the same name can be used for customization and user
190+
provided files are preferred over default files in
191+
`/usr/share/container-scripts/mysql/`- so it is possible to overwrite them.
192+
193+
Same configuration directory structure can be used to customize the image
194+
every time the image is started using `docker run`. The directory has to be
195+
mounted into `/opt/app-root/src/` in the image
196+
(`-v ./image-configuration/:/opt/app-root/src/`).
197+
This overwrites customization built into the image.
198+
199+
200+
Securing the connection with SSL
201+
--------------------------------
202+
In order to secure the connection with SSL, use the extending feature described
203+
above. In particular, put the SSL certificates into a separate directory:
204+
205+
sslapp/mysql-certs/server-cert-selfsigned.pem
206+
sslapp/mysql-certs/server-key.pem
207+
208+
And then put a separate configuration file into mysql-cfg:
209+
210+
$> cat sslapp/mysql-cfg/ssl.cnf
211+
[mysqld]
212+
ssl-key=${APP_DATA}/mysql-certs/server-key.pem
213+
ssl-cert=${APP_DATA}/mysql-certs/server-cert-selfsigned.pem
214+
215+
Such a directory `sslapp` can then be mounted into the container with -v,
216+
or a new container image can be built using s2i.
217+
218+
145219
Changing the replication binlog_format
146220
--------------------------------------
147221
Some applications may wish to use `row` binlog_formats (for example, those built

5.6/s2i-common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../s2i-common/

5.7/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM centos:centos7
1+
FROM centos/s2i-core-centos7
22

33
# MySQL image for OpenShift.
44
#
@@ -11,6 +11,7 @@ FROM centos:centos7
1111
# * $MYSQL_ROOT_PASSWORD (Optional) - Password for the 'root' MySQL account
1212

1313
ENV MYSQL_VERSION=5.7 \
14+
APP_DATA=/opt/app-root/src \
1415
HOME=/var/lib/mysql
1516

1617
ENV SUMMARY="MySQL 5.7 SQL database server" \
@@ -37,8 +38,7 @@ EXPOSE 3306
3738
# to make sure of that.
3839
RUN yum install -y yum-utils && \
3940
yum install -y centos-release-scl && \
40-
yum-config-manager --enable centos-sclo-rh-testing && \
41-
INSTALL_PKGS="rsync tar gettext hostname bind-utils rh-mysql57" && \
41+
INSTALL_PKGS="rsync tar gettext hostname bind-utils groff-base shadow-utils rh-mysql57" && \
4242
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
4343
rpm -V $INSTALL_PKGS && \
4444
yum clean all && \
@@ -58,6 +58,7 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
5858
PROMPT_COMMAND=". ${CONTAINER_SCRIPTS_PATH}/scl_enable"
5959

6060
COPY 5.7/root-common /
61+
COPY 5.7/s2i-common/bin/ $STI_SCRIPTS_PATH
6162
COPY 5.7/root /
6263

6364
# this is needed due to issues with squash

5.7/Dockerfile.fedora

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.fedoraproject.org/fedora:26
1+
FROM registry.fedoraproject.org/f26/s2i-core:latest
22

33
# MySQL image for OpenShift.
44
#
@@ -11,6 +11,7 @@ FROM registry.fedoraproject.org/fedora:26
1111
# * $MYSQL_ROOT_PASSWORD (Optional) - Password for the 'root' MySQL account
1212

1313
ENV MYSQL_VERSION=5.7 \
14+
APP_DATA=/opt/app-root/src \
1415
HOME=/var/lib/mysql
1516

1617
ENV SUMMARY="MySQL 5.7 SQL database server" \
@@ -47,7 +48,7 @@ RUN ln -s /usr/bin/python3 /usr/bin/python
4748
# This image must forever use UID 27 for mysql user so our volumes are
4849
# safe in the future. This should *never* change, the last test is there
4950
# to make sure of that.
50-
RUN INSTALL_PKGS="rsync tar gettext hostname bind-utils community-mysql-server policycoreutils" && \
51+
RUN INSTALL_PKGS="rsync tar gettext hostname bind-utils groff-base shadow-utils community-mysql-server policycoreutils" && \
5152
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
5253
rpm -V $INSTALL_PKGS && \
5354
yum clean all && \
@@ -59,6 +60,7 @@ ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/mysql \
5960
MYSQL_PREFIX=/usr
6061

6162
COPY 5.7/root-common /
63+
COPY 5.7/s2i-common/bin/ $STI_SCRIPTS_PATH
6264
COPY 5.7/root /
6365

6466
# this is needed due to issues with squash

5.7/Dockerfile.rhel7

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rhel7
1+
FROM rhscl/s2i-core-rhel7
22

33
# MySQL image for OpenShift.
44
#
@@ -11,6 +11,7 @@ FROM rhel7
1111
# * $MYSQL_ROOT_PASSWORD (Optional) - Password for the 'root' MySQL account
1212

1313
ENV MYSQL_VERSION=5.7 \
14+
APP_DATA=/opt/app-root/src \
1415
HOME=/var/lib/mysql
1516

1617
ENV SUMMARY="MySQL 5.7 SQL database server" \
@@ -43,7 +44,7 @@ RUN yum repolist > /dev/null && \
4344
yum-config-manager --enable rhel-7-server-rpms && \
4445
yum-config-manager --enable rhel-7-server-optional-rpms && \
4546
yum-config-manager --enable rhel-server-rhscl-7-rpms && \
46-
INSTALL_PKGS="rsync tar gettext hostname bind-utils rh-mysql57" && \
47+
INSTALL_PKGS="rsync tar gettext hostname bind-utils groff-base shadow-utils rh-mysql57" && \
4748
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
4849
rpm -V $INSTALL_PKGS && \
4950
yum clean all && \
@@ -63,6 +64,7 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \
6364
PROMPT_COMMAND=". ${CONTAINER_SCRIPTS_PATH}/scl_enable"
6465

6566
COPY 5.7/root-common /
67+
COPY 5.7/s2i-common/bin/ $STI_SCRIPTS_PATH
6668
COPY 5.7/root /
6769

6870
# this is needed due to issues with squash

5.7/root/usr/share/container-scripts/mysql/README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ or if it was already present, `mysqld` is executed and will run as PID 1. You ca
4444
stop the detached container by running `docker stop mysql_database`.
4545

4646

47-
4847
Environment variables and volumes
4948
---------------------------------
5049

@@ -142,6 +141,81 @@ location is `/etc/my.cnf` but you can change it to `/etc/mysql/my.cnf` by settin
142141
`MYSQL_DEFAULTS_FILE=/etc/mysql/my.cnf`
143142

144143

144+
Extending image
145+
---------------
146+
This image can be extended using [source-to-image](https://github.com/openshift/source-to-image).
147+
148+
For example, to build a customized MariaDB database image `my-mysql-rhel7`
149+
with a configuration in `~/image-configuration/` run:
150+
151+
```
152+
$ s2i build ~/image-configuration/ rhscl/mysql-57-rhel7 my-mysql-rhel7
153+
```
154+
155+
The directory passed to `s2i build` can contain these directories:
156+
157+
`mysql-cfg/`
158+
When starting the container, files from this directory will be used as
159+
a configuration for the `mysqld` daemon.
160+
`envsubst` command is run on this file to still allow customization of
161+
the image using environmental variables
162+
163+
`mysql-pre-init/`
164+
Shell scripts (`*.sh`) available in this directory are sourced before
165+
`mysqld` daemon is started.
166+
167+
`mysql-init/`
168+
Shell scripts (`*.sh`) available in this directory are sourced when
169+
`mysqld` daemon is started locally. In this phase, use `${mysql_flags}`
170+
to connect to the locally running daemon, for example `mysql $mysql_flags < dump.sql`
171+
172+
Variables that can be used in the scripts provided to s2i:
173+
174+
`$mysql_flags`
175+
arguments for the `mysql` tool that will connect to the locally running `mysqld` during initialization
176+
177+
`$MYSQL_RUNNING_AS_MASTER`
178+
variable defined when the container is run with `run-mysqld-master` command
179+
180+
`$MYSQL_RUNNING_AS_SLAVE`
181+
variable defined when the container is run with `run-mysqld-slave` command
182+
183+
`$MYSQL_DATADIR_FIRST_INIT`
184+
variable defined when the container was initialized from the empty data dir
185+
186+
During `s2i build` all provided files are copied into `/opt/app-root/src`
187+
directory into the resulting image. If some configuration files are present
188+
in the destination directory, files with the same name are overwritten.
189+
Also only one file with the same name can be used for customization and user
190+
provided files are preferred over default files in
191+
`/usr/share/container-scripts/mysql/`- so it is possible to overwrite them.
192+
193+
Same configuration directory structure can be used to customize the image
194+
every time the image is started using `docker run`. The directory has to be
195+
mounted into `/opt/app-root/src/` in the image
196+
(`-v ./image-configuration/:/opt/app-root/src/`).
197+
This overwrites customization built into the image.
198+
199+
200+
Securing the connection with SSL
201+
--------------------------------
202+
In order to secure the connection with SSL, use the extending feature described
203+
above. In particular, put the SSL certificates into a separate directory:
204+
205+
sslapp/mysql-certs/server-cert-selfsigned.pem
206+
sslapp/mysql-certs/server-key.pem
207+
208+
And then put a separate configuration file into mysql-cfg:
209+
210+
$> cat sslapp/mysql-cfg/ssl.cnf
211+
[mysqld]
212+
ssl-key=${APP_DATA}/mysql-certs/server-key.pem
213+
ssl-cert=${APP_DATA}/mysql-certs/server-cert-selfsigned.pem
214+
215+
Such a directory `sslapp` can then be mounted into the container with -v,
216+
or a new container image can be built using s2i.
217+
218+
145219
Changing the replication binlog_format
146220
--------------------------------------
147221
Some applications may wish to use `row` binlog_formats (for example, those built

5.7/s2i-common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../s2i-common/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mysqld]
2+
query-cache-limit=262144
3+

0 commit comments

Comments
 (0)