Skip to content

Commit

Permalink
Include Dockerfile that extends original image, add test and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorak committed Apr 26, 2017
1 parent 0356737 commit 83e68a9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
15 changes: 15 additions & 0 deletions 10.1/root/usr/share/container-scripts/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ During `s2i build` all provided files are copied into `/opt/app-root/src` direct

Same configuration directory structure can be used to customize the image every time the image is started using `docker run`. The directory has to be mounted into `/opt/app-root/src/` in the image (`-v ./image-configuration/:/opt/app-root/src/`). This overwrites customization built into the image.

It is also possible to use a `Dockerfile` to add the additional files into the new image. This is in particular helpful when we need to change the user for some commands (like installing additional RPMs). A `Dockerfile` that installs an additional RPM and adds a directory `./image-configuration` as s2i source, may look like this:

```
FROM rhscl/mariadb-101-rhel7
USER 0
RUN INSTALL_PKGS="openssh-server" && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum clean all
USER 27
COPY image-configuration /opt/app-root/src
```

To build such a Dockerfile, use either appropriate strategy in OpenShift or `docker build` command directly.


Changing the replication binlog_format
--------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions 10.1/test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Extending the image using s2i concept can be done with a new Dockerfile as well
# This way we can for example install additional RPM packages
FROM __IMAGE_NAME__
USER 0
RUN INSTALL_PKGS="openssh-server" && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum clean all
USER 27
COPY test-app /opt/app-root/src

26 changes: 21 additions & 5 deletions 10.1/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ run_change_password_test
run_replication_test
run_doc_test
run_s2i_test
run_dockerfile_build_test
"

IMAGE_NAME=${IMAGE_NAME-centos/mariadb-101-centos7-candidate}
Expand Down Expand Up @@ -350,7 +351,7 @@ function run_configuration_tests() {
echo " Success!"
}

test_scl_usage() {
function test_scl_usage() {
local name="$1"
local run_cmd="$2"
local expected="$3"
Expand Down Expand Up @@ -401,7 +402,7 @@ function run_tests() {
test_mysql "$container_ip" "$USER" "$PASS"
}

run_doc_test() {
function run_doc_test() {
local tmpdir=$(mktemp -d)
local f
echo " Testing documentation in the container image"
Expand All @@ -425,7 +426,7 @@ run_doc_test() {
echo
}

_s2i_test_image() {
function _s2i_test_image() {
local container_name="$1"
local mount_opts="$2"
echo " Testing s2i app image with invalid configuration"
Expand All @@ -452,7 +453,7 @@ _s2i_test_image() {
docker stop "$(get_cid $container_name)" >/dev/null
}

run_s2i_test() {
function run_s2i_test() {
echo " Testing s2i usage"
s2i usage ${s2i_args} ${IMAGE_NAME} &>/dev/null

Expand All @@ -461,7 +462,6 @@ run_s2i_test() {
local image_name_backup=${IMAGE_NAME}
export IMAGE_NAME=${IMAGE_NAME}-testapp

local container_name=s2i_config_build
_s2i_test_image "s2i_config_build" ""

# return back original value for IMAGE_NAME
Expand All @@ -476,6 +476,22 @@ run_s2i_test() {
echo " Success!"
}

function run_dockerfile_build_test() {
sed -e "s/__IMAGE_NAME__/${IMAGE_NAME}/g" ${test_dir}/Dockerfile > ${test_dir}/Dockerfile.expanded
docker build -t ${IMAGE_NAME}-docker_build -f ${test_dir}/Dockerfile.expanded ${test_dir}
docker run --rm ${IMAGE_NAME}-docker_build bash -c 'rpm -qa' | grep openssh-server

local image_name_backup=${IMAGE_NAME}
export IMAGE_NAME=${IMAGE_NAME}-docker_build

_s2i_test_image "s2i_config_build" ""

# return back original value for IMAGE_NAME
export IMAGE_NAME=${image_name_backup}

rm -f ${test_dir}/Dockerfile.expanded
}

function run_general_tests() {
# Set lower buffer pool size to avoid running out of memory.
export CONTAINER_ARGS="run-mysqld --innodb_buffer_pool_size=5242880"
Expand Down

0 comments on commit 83e68a9

Please sign in to comment.