Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Image builds, testable
Jim Van Fleet
committed
Aug 31, 2016
1 parent
4f3fbcb
commit 7935104
Showing
7 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,5 @@ bin/install.sh | |
bin/rebuild.sh | ||
bin/rerun.sh | ||
bin/run.sh | ||
bin/start.sh | ||
bin/stop.sh | ||
bin/test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM tier/centos7base | ||
|
||
# Define args and set a default value | ||
ARG registry=docker.io | ||
ARG maintainer=tier | ||
ARG imagename=mariadb | ||
ARG version=5.5 | ||
|
||
MAINTAINER $maintainer | ||
LABEL Vendor="Internet2" | ||
LABEL ImageType="Database" | ||
LABEL ImageName=$imagename | ||
LABEL ImageOS=centos7 | ||
LABEL Version=$version | ||
|
||
LABEL Build docker build --rm --tag $registry/$maintainer/$imagename . | ||
|
||
# Install base deps | ||
RUN yum -y install --setopt=tsflags=nodocs mariadb-server bind-utils pwgen psmisc hostname vim | ||
|
||
# Add starters and installers | ||
ADD ./container_files /root | ||
|
||
# Add Volumes and Set permissions | ||
RUN mkdir /opt/shared && chmod 777 /opt/shared && chmod 777 /root/*.sh | ||
|
||
# Place VOLUME statement below all changes to /var/lib/mysql | ||
VOLUME /var/lib/mysql | ||
|
||
# Environment variables | ||
ENV CREATE_NEW_DATABASE "1" | ||
ENV MYSQL_ROOT_PASSWORD "123321" | ||
ENV MYSQL_DATABASE "registry" | ||
ENV MYSQL_USER "registry_user" | ||
ENV MYSQL_PASSWORD "WJzesbe3poNZ91qIbmR7" | ||
ENV MYSQL_DATADIR "/var/lib/mysqlmounted" | ||
ENV TERM "testterm" | ||
|
||
# Port | ||
EXPOSE 3306 | ||
|
||
CMD ["/root/container_start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
source common.bash . | ||
|
||
echo "Running Docker image($registry/$maintainer/$imagename)" | ||
docker run --name=$imagename -d -p 3306:3306 $maintainer/$imagename | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
maintainer="tier" | ||
imagename="imagename-replaceme-in-common-bash" | ||
imagename="mariadb" | ||
version="5.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash -x | ||
|
||
log="/tmp/start.log" | ||
|
||
echo "Starting Container: " > $log | ||
date >> $log | ||
echo "" >> $log | ||
|
||
if [ -e "/tmp/firsttimerunning" ]; then | ||
|
||
set -e | ||
|
||
echo "Checking args" >> $log | ||
if [ "${1:0:1}" = '-' ]; then | ||
set -- mysqld_safe "$@" >> $log | ||
fi | ||
|
||
echo "Setting DataDir: $MYSQL_DATADIR" >> $log | ||
|
||
if [ "$CREATE_NEW_DATABASE" == "1" ]; then | ||
|
||
echo "Installing MariaDB" >> $log | ||
|
||
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then | ||
echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set' >> $log | ||
echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?' >> $log | ||
exit 1 | ||
fi | ||
|
||
echo 'Running mysql_install_db ...' >> $log | ||
mysql_install_db --datadir="$MYSQL_DATADIR" >> $log | ||
echo 'Finished mysql_install_db' >> $log | ||
|
||
# These statements _must_ be on individual lines, and _must_ end with | ||
# semicolons (no line breaks or comments are permitted). | ||
# TODO proper SQL escaping on ALL the things D: | ||
|
||
tempSqlFile='/tmp/mysql-first-time.sql' | ||
echo "DELETE FROM mysql.user ;" > $tempSqlFile | ||
echo "CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;" >> $tempSqlFile | ||
echo "GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;" >> $tempSqlFile | ||
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';" >> $tempSqlFile | ||
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;" >> $tempSqlFile | ||
echo "DROP DATABASE IF EXISTS test ;" >> $tempSqlFile | ||
|
||
|
||
if [ "$MYSQL_DATABASE" != "" ]; then | ||
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" >> "$tempSqlFile" | ||
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'comanage.compose_i2network' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'comanage.comanage_i2network' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'comanage.config_i2network' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile" | ||
fi | ||
|
||
echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile" | ||
|
||
echo "character-set-server = utf8mb4" >> /etc/my.cnf | ||
echo "collation-server = utf8mb4_unicode_ci" >> /etc/my.cnf | ||
echo "" >> /etc/my.cnf | ||
|
||
echo "Fixing Permissions" >> $log | ||
chown -R mysql:mysql $MYSQL_DATADIR | ||
/root/fix-permissions.sh $MYSQL_DATADIR >> $log | ||
/root/fix-permissions.sh /var/log/mariadb/ >> $log | ||
/root/fix-permissions.sh /var/run/ >> $log | ||
echo "Done Fixing Permissions" >> $log | ||
|
||
/usr/bin/mysqld_safe --init-file="$tempSqlFile" --datadir="$MYSQL_DATADIR" | ||
else | ||
echo "Not Creating a MariaDB - Using Existing from DataDir: $MYSQL_DATADIR" >> $log | ||
/usr/bin/mysqld_safe --datadir="$MYSQL_DATADIR" | ||
fi | ||
|
||
rm -f /tmp/firsttimerunning | ||
else | ||
echo "Using Existing MariaDB from DataDir: $MYSQL_DATADIR" >> $log | ||
/usr/bin/mysqld_safe --datadir="$MYSQL_DATADIR" | ||
fi | ||
|
||
tail -f $log | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
log="/tmp/permissions.log" | ||
|
||
echo "Starting Container: " > $log | ||
date >> $log | ||
echo "" >> $log | ||
|
||
# Taken from https://raw.githubusercontent.com/openshift/sti-base/master/bin/fix-permissions | ||
# Fix permissions on the given directory to allow group read/write of | ||
# regular files and execute of directories. | ||
chgrp -R 0 $1 >> $log | ||
chmod -R g+rw $1 >> $log | ||
find $1 -type d -exec chmod g+x {} + >> $log | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../common | ||
|
||
@test "Data directory created" { | ||
docker run -i $maintainer/$imagename find /var/lib/mysql | ||
} | ||
|
||
@test "MariaDB service available" { | ||
docker run -i $maintainer/$imagename find /usr/lib/systemd/system/mariadb.service | ||
} |