Skip to content

Commit

Permalink
Merge branch 'master' of github.com:amazeeio/lagoon into 103-refactor…
Browse files Browse the repository at this point in the history
…-cli-for-new-api
  • Loading branch information
karlhorky committed Mar 19, 2018
2 parents b7e4e4d + b8a974f commit a5afaec
Show file tree
Hide file tree
Showing 80 changed files with 10,487 additions and 400 deletions.
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: '3.2'
services:
api-db:
image: ${IMAGE_REPO:-lagoon}/api-db
volumes:
- ./services/api-db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./services/api-db/rerun_initdb.sh:/rerun_initdb.sh
# volumes:
# - ./services/api-db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
# - ./services/api-db/rerun_initdb.sh:/rerun_initdb.sh
ports:
- "3306:3306"
labels:
Expand Down
Empty file modified images/commons/lagoon/entrypoints/00-umask.sh
100644 → 100755
Empty file.
99 changes: 92 additions & 7 deletions images/mariadb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ COPY --from=commons /lagoon /lagoon
COPY --from=commons /bin/fix-permissions /bin/ep /bin/docker-sleep /bin/
COPY --from=commons /home /home

RUN chmod g+w /etc/passwd \
&& mkdir -p /home

# When Bash is invoked via `sh` it behaves like the old Bourne Shell and sources a file that is given in `ENV`
# When Bash is invoked as non-interactive (like `bash -c command`) it sources a file that is given in `BASH_ENV`
ENV TMPDIR=/tmp TMP=/tmp HOME=/home ENV=/home/.bashrc BASH_ENV=/home/.bashrc
Expand All @@ -18,22 +21,104 @@ ENV BACKUPS_DIR="/var/lib/mysql/backup"

ENV MARIADB_DATABASE=lagoon \
MARIADB_USER=lagoon \
MARIADB_PASSWORD=lagoon
MARIADB_PASSWORD=lagoon \
MARIADB_ROOT_PASSWORD=Lag00n

RUN apk add --no-cache bash mariadb-client mariadb mariadb-common pwgen && rm -rf /var/cache/apk/*
# fix some environmental items
RUN mkdir -p /usr/include/bits; mkdir -p /usr/
COPY root/usr/include/bits/wordsize.h /usr/include/bits/wordsize.h

RUN for i in /run/mysqld /var/lib/mysql /etc/mysql/conf.d /docker-entrypoint-initdb.d/ "${BACKUPS_DIR}"; \
do mkdir -p $i; chown mysql $i; /bin/fix-permissions $i; done
RUN apk add --no-cache --virtual .common-run-deps \
asio \
bash \
boost \
curl \
findutils \
gnutls \
libaio \
libgcrypt \
libstdc++ \
libuuid \
lsof \
mariadb \
mariadb-client \
mariadb-common \
procps \
pwgen \
rsync \
sqlite-libs \
tzdata \
wget && \
apk add --no-cache --virtual .galera-build-deps \
asio-dev && \
apk add --no-cache --virtual .common-build-deps \
attr \
autoconf \
bison \
boost-dev \
build-base \
cmake \
coreutils \
curl-dev \
flex \
git \
gnutls-dev \
libaio-dev \
libgcrypt-dev \
linux-headers \
make \
musl-dev \
ncurses-dev \
patch \
readline-dev \
scons \
sqlite-dev \
tcl tcl-dev \
util-linux-dev \
zlib-dev && \
cd /tmp && git clone https://github.com/libcheck/check.git && cd check && mkdir build && cd build && cmake ../ && make && make install && \
cd /tmp && git clone -b mariadb-3.x https://github.com/MariaDB/galera.git && \
cd /tmp/galera && sed -i s/PAGE_SIZE/PAGE_SIZE_64K/g galerautils/src/gu_alloc.cpp && sed -i '/#include <limits>/a #include <stdint.h>' galerautils/src/gu_datetime.hpp && \
cd /tmp/galera && ./scripts/build.sh --so strict_build_flags=0 && \
mkdir -p /usr/lib64/galera && mv /tmp/galera/libgalera_smm.so /usr/lib64/galera/libgalera_smm.so && \
apk del --purge .galera-build-deps && \
apk add --no-cache --virtual .maxscale-run-deps \
openssl openssl-dev && \
echo "#define _UTSNAME_SYSNAME_LENGTH 65" >> /usr/include/sys/utsname.h && \
cd /tmp && git clone --branch=2.2.2 --single-branch https://github.com/rtprio/MaxScale.git maxscale && cd /tmp/ && mkdir maxscale-build && cd maxscale-build && cmake ../maxscale -DBUILD_TESTS=Y -DWITH_SCRIPTS=N -DBUILD_MAXCTRL=N && \
cd /tmp/maxscale-build && make && make install && \
apk del --purge .common-build-deps && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/*

COPY docker-entrypoint.sh /lagoon/entrypoints/90-mariadb-entrypoint
COPY docker-entrypoint.bash /lagoon/entrypoints/90-mariadb-entrypoint
COPY maxscale-entrypoint.sh /lagoon/entrypoints/80-maxscale
COPY maxscale.sql /docker-entrypoint-initdb.d/maxscale.sql
COPY maxscale.cnf /etc/maxscale.cnf
COPY maxscale-start.sh /usr/local/bin/maxscale-start
COPY mysql-backup.sh /lagoon/

COPY my.cnf /etc/mysql/my.cnf

RUN ln -s /var/lib/mysql/.my.cnf /home/.my.cnf
RUN for i in /var/run/mysqld /var/lib/mysql /etc/my.cnf.d /etc/mysql/conf.d /docker-entrypoint-initdb.d/ "${BACKUPS_DIR}"; \
do mkdir -p $i; chown mysql $i; /bin/fix-permissions $i; \
done && \
for i in /var/lib/maxscale /var/log/maxscale /var/cache/maxscale /var/run/maxscale; \
do mkdir -p $i; /bin/fix-permissions $i; \
done && \
/bin/fix-permissions /etc/maxscale.cnf && \
ln -s /var/lib/mysql/.my.cnf /home/.my.cnf && \
sed -i 's/#!\/bin\/bash -ue/#!\/bin\/bash -e/' /usr/bin/wsrep_sst_rsync

COPY root/usr/bin/peer-finder /usr/bin/peer-finder
COPY root/usr/share/container-scripts/mysql/readiness-probe.sh /usr/share/container-scripts/mysql/readiness-probe.sh
COPY root/usr/share/container-scripts/mysql/galera.cnf /usr/share/container-scripts/mysql/galera.cnf
COPY root/usr/share/container-scripts/mysql/configure-galera.sh /usr/share/container-scripts/mysql/configure-galera.sh
COPY root/etc/mysql/conf.d/galera.cnf /etc/mysql/conf.d/galera.cnf

### we cannot start mysql as root, we add the user mysql to the group root and change the user of the Docker Image to this user
RUN addgroup mysql root
USER mysql
ENV USER_NAME mysql

WORKDIR /var/lib/mysql
VOLUME /var/lib/mysql
Expand Down
128 changes: 128 additions & 0 deletions images/mariadb/docker-entrypoint.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env bash

set -eo pipefail

# Locations
CONTAINER_SCRIPTS_DIR="/usr/share/container-scripts/mysql"
EXTRA_DEFAULTS_FILE="/etc/my.cnf.d/galera.cnf"

# Check if the container runs in Kubernetes/OpenShift
if [ -z "$POD_NAMESPACE" ]; then
# Single container runs in docker
echo "POD_NAMESPACE not set, spin up single node"
else
# Is running in Kubernetes/OpenShift, so find all other pods
# belonging to the namespace
echo "Galera: Finding peers"
K8S_SVC_NAME=$(hostname -f | cut -d"." -f2)
echo "Using service name: ${K8S_SVC_NAME}"
# copy the pristine version to the one that can be edited
cp ${CONTAINER_SCRIPTS_DIR}/galera.cnf ${EXTRA_DEFAULTS_FILE}
/usr/bin/peer-finder -on-start="${CONTAINER_SCRIPTS_DIR}/configure-galera.sh" -service=${K8S_SVC_NAME}
fi

if [ "${1:0:1}" = '-' ]; then
set -- mysqld "$@"
fi

wantHelp=
for arg; do
case "$arg" in
-'?'|--help|--print-defaults|-V|--version)
wantHelp=1
break
;;
esac
done



if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
if [ ! -d "/run/mysqld" ]; then
mkdir -p /run/mysqld
chown -R mysql:mysql /run/mysqld
fi

if [ -d /var/lib/mysql/mysql ]; then
echo "MySQL directory already present, skipping creation"
else
echo "MySQL data directory not found, creating initial DBs"

mysql_install_db --skip-name-resolve --skip-auth-anonymous-user

echo "starting mysql for initdb.d import."
/usr/bin/mysqld --skip-networking --wsrep_on=OFF &
pid="$!"
echo "pid is $pid"

for i in {30..0}; do
if echo 'SELECT 1' | mysql &> /dev/null; then
break
fi
echo 'MySQL init process in progress...'
sleep 1
done

if [ "$MARIADB_ROOT_PASSWORD" = "" ]; then
MARIADB_ROOT_PASSWORD=`pwgen 16 1`
echo "[i] MySQL root Password: $MARIADB_ROOT_PASSWORD"
fi

MARIADB_DATABASE=${MARIADB_DATABASE:-""}
MARIADB_USER=${MARIADB_USER:-""}
MARIADB_PASSWORD=${MARIADB_PASSWORD:-""}

tfile=`mktemp`
if [ ! -f "$tfile" ]; then
return 1
fi

cat << EOF > $tfile
DROP DATABASE IF EXISTS test;
USE mysql;
UPDATE mysql.user SET PASSWORD=PASSWORD("$MARIADB_ROOT_PASSWORD") WHERE user="root";
FLUSH PRIVILEGES;
EOF

if [ "$MARIADB_DATABASE" != "" ]; then
echo "[i] Creating database: $MARIADB_DATABASE"
echo "CREATE DATABASE IF NOT EXISTS \`$MARIADB_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
if [ "$MARIADB_USER" != "" ]; then
echo "[i] Creating user: $MARIADB_USER with password $MARIADB_PASSWORD"
echo "GRANT ALL ON \`$MARIADB_DATABASE\`.* to '$MARIADB_USER'@'%' IDENTIFIED BY '$MARIADB_PASSWORD';" >> $tfile
fi
fi


cat $tfile
cat $tfile | mysql -v -u root
rm -v -f $tfile

for f in `ls /docker-entrypoint-initdb.d/*`; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; cat $f| tee | mysql -u root -p${MARIADB_ROOT_PASSWORD}; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

echo "[client]" >> /var/lib/mysql/.my.cnf
echo "user=root" >> /var/lib/mysql/.my.cnf
echo "password=${MARIADB_ROOT_PASSWORD}" >> /var/lib/mysql/.my.cnf
echo "[mysql]" >> /var/lib/mysql/.my.cnf
echo "database=${MARIADB_DATABASE}" >> /var/lib/mysql/.my.cnf

if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'MySQL init process failed.'
exit 1
fi

fi

echo "done, now starting daemon"

fi

exec $@
110 changes: 0 additions & 110 deletions images/mariadb/docker-entrypoint.sh

This file was deleted.

3 changes: 3 additions & 0 deletions images/mariadb/maxscale-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/bin/ep /etc/maxscale.cnf
2 changes: 2 additions & 0 deletions images/mariadb/maxscale-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec maxscale -lstdout -d
Loading

0 comments on commit a5afaec

Please sign in to comment.