mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-24 16:41:25 +01:00
Rebuild Harbor DB docker image on top of Maria DB
This change reworked the vmware/harbor-db image to build it on top of vmware/mariadb-photon. Also made minor change in the entrypoint script of mariadb image to execute upgrade script during bootstrap, and fix a file permission issue in the bootstrap scripts.
This commit is contained in:
parent
bda38bd72e
commit
2cedfff4b3
@ -1,8 +1,6 @@
|
|||||||
FROM mysql:5.6.35
|
FROM vmware/mariadb-photon:10.2.8
|
||||||
|
|
||||||
WORKDIR /tmp
|
COPY registry.sql /docker-entrypoint-initdb.d/
|
||||||
|
COPY registry-flag.sh /docker-entrypoint-initdb.d/
|
||||||
|
COPY upgrade.sh /docker-entrypoint-updatedb.d/
|
||||||
|
|
||||||
ADD registry.sql r.sql
|
|
||||||
|
|
||||||
ADD docker-entrypoint.sh /entrypoint.sh
|
|
||||||
RUN chmod u+x /entrypoint.sh
|
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ ! -d '/var/lib/mysql/mysql' -a "${1%_safe}" = 'mysqld' ]; then
|
|
||||||
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then
|
|
||||||
echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set'
|
|
||||||
echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ? v2'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mysql_install_db --user=mysql --datadir=/var/lib/mysql
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
printf -v MYSQL_ROOT_PASSWORD "%q" ${MYSQL_ROOT_PASSWORD}
|
|
||||||
TEMP_FILE='/tmp/mysql-first-time.sql'
|
|
||||||
cat > "$TEMP_FILE" <<-EOSQL
|
|
||||||
DELETE FROM mysql.user ;
|
|
||||||
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
|
|
||||||
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
|
|
||||||
DROP DATABASE IF EXISTS test ;
|
|
||||||
EOSQL
|
|
||||||
|
|
||||||
if [ "$MYSQL_DATABASE" ]; then
|
|
||||||
echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE ;" >> "$TEMP_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
|
|
||||||
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$TEMP_FILE"
|
|
||||||
|
|
||||||
if [ "$MYSQL_DATABASE" ]; then
|
|
||||||
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%' ;" >> "$TEMP_FILE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE"
|
|
||||||
cat /tmp/r.sql >> "$TEMP_FILE"
|
|
||||||
|
|
||||||
set -- "$@" --init-file="$TEMP_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
chown -R mysql:mysql /var/lib/mysql
|
|
||||||
exec "$@"
|
|
3
make/common/db/registry-flag.sh
Normal file
3
make/common/db/registry-flag.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
touch /var/lib/mysql/created_in_mariadb.flag
|
||||||
|
echo "dumped flag for MariaDB"
|
28
make/common/db/upgrade.sh
Executable file
28
make/common/db/upgrade.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set +e
|
||||||
|
if [ ! -f /var/lib/mysql/created_in_mariadb.flag ]; then
|
||||||
|
echo "Maria DB flag not found, the DB was created in mysql image, running upgrade..."
|
||||||
|
mysqld >/dev/null 2>&1 &
|
||||||
|
pid="$!"
|
||||||
|
for i in {30..0}; do
|
||||||
|
mysqladmin -uroot -p$MYSQL_ROOT_PASSWORD processlist >/dev/null 2>&1
|
||||||
|
if [ $? = 0 ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo 'Waiting for MySQL start...'
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ "$i" = 0 ]; then
|
||||||
|
echo >&2 'MySQL failed to start.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
set -e
|
||||||
|
mysql_upgrade -p$MYSQL_ROOT_PASSWORD
|
||||||
|
echo 'Finished upgrading'
|
||||||
|
if ! kill -s TERM "$pid" || ! wait "$pid"; then
|
||||||
|
echo >&2 'Failed to stop MySQL for upgrading.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "DB was created in Maria DB, skip upgrade."
|
||||||
|
fi
|
@ -1,16 +1,16 @@
|
|||||||
FROM vmware/photon:1.0-20170928
|
FROM vmware/photon:1.0
|
||||||
|
|
||||||
#The Docker Daemon has to be running with storage backend btrfs when building the image
|
#The Docker Daemon has to be running with storage backend btrfs when building the image
|
||||||
|
|
||||||
RUN tdnf distro-sync -y \
|
RUN tdnf distro-sync -y || echo \
|
||||||
&& tdnf install -y sed shadow procps-ng gawk gzip sudo net-tools \
|
&& tdnf install -y sed shadow procps-ng gawk gzip sudo net-tools \
|
||||||
&& groupadd -r -g 999 mysql && useradd --no-log-init -r -g 999 -u 999 mysql \
|
&& groupadd -r -g 999 mysql && useradd --no-log-init -r -g 999 -u 999 mysql \
|
||||||
&& tdnf install -y mariadb-server mariadb \
|
&& tdnf install -y mariadb-server mariadb \
|
||||||
&& mkdir /docker-entrypoint-initdb.d \
|
&& mkdir /docker-entrypoint-initdb.d /docker-entrypoint-updatedb.d \
|
||||||
&& rm -fr /var/lib/mysql \
|
&& rm -fr /var/lib/mysql \
|
||||||
&& mkdir -p /var/lib/mysql /var/run/mysqld \
|
&& mkdir -p /var/lib/mysql /var/run/mysqld \
|
||||||
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
|
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
|
||||||
&& chmod 777 /var/run/mysqld /docker-entrypoint-initdb.d \
|
&& chmod 777 /var/run/mysqld /docker-entrypoint-initdb.d /docker-entrypoint-updatedb.d \
|
||||||
&& tdnf clean all
|
&& tdnf clean all
|
||||||
|
|
||||||
COPY docker-entrypoint.sh /usr/local/bin/
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
@ -21,7 +21,5 @@ RUN ln -s usr/local/bin/docker-entrypoint.sh /
|
|||||||
VOLUME /var/lib/mysql
|
VOLUME /var/lib/mysql
|
||||||
EXPOSE 3306
|
EXPOSE 3306
|
||||||
|
|
||||||
USER mysql
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||||
CMD ["mysqld"]
|
CMD ["mysqld"]
|
||||||
|
@ -68,7 +68,13 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
|
|||||||
DATADIR="$(_get_config 'datadir' "$@")"
|
DATADIR="$(_get_config 'datadir' "$@")"
|
||||||
mkdir -p "$DATADIR"
|
mkdir -p "$DATADIR"
|
||||||
chown -R mysql:mysql "$DATADIR"
|
chown -R mysql:mysql "$DATADIR"
|
||||||
exec sudo -u mysql -E "$BASH_SOURCE" "$@"
|
if [ -d '/docker-entrypoint-initdb.d' ]; then
|
||||||
|
chmod -R +rx /docker-entrypoint-updatedb.d
|
||||||
|
fi
|
||||||
|
if [ -d '/docker-entrypoint-updatedb.d' ]; then
|
||||||
|
chmod -R +rx /docker-entrypoint-updatedb.d
|
||||||
|
fi
|
||||||
|
exec sudo -u mysql -E "$BASH_SOURCE" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
|
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
|
||||||
@ -86,8 +92,6 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$DATADIR"
|
mkdir -p "$DATADIR"
|
||||||
echo "##### Current user id: $(id -u)"
|
|
||||||
|
|
||||||
echo 'Initializing database'
|
echo 'Initializing database'
|
||||||
cd /usr
|
cd /usr
|
||||||
mysql_install_db --datadir="$DATADIR" --rpm
|
mysql_install_db --datadir="$DATADIR" --rpm
|
||||||
@ -184,6 +188,16 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
|
|||||||
echo 'MySQL init process done. Ready for start up.'
|
echo 'MySQL init process done. Ready for start up.'
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
for f in /docker-entrypoint-updatedb.d/*; do
|
||||||
|
case "$f" in
|
||||||
|
*.sh) echo "$0: running $f"; . "$f" ;;
|
||||||
|
### Not supported for now... until needed
|
||||||
|
# *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
|
||||||
|
# *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
|
||||||
|
*) echo "$0: ignoring $f" ;;
|
||||||
|
esac
|
||||||
|
echo
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
FROM vmware/photon:1.0
|
FROM vmware/photon:1.0
|
||||||
|
|
||||||
RUN tdnf distro-sync -y \
|
RUN tdnf distro-sync -y || echo \
|
||||||
&& tdnf install -y nginx \
|
&& tdnf install -y nginx \
|
||||||
&& ln -sf /dev/stdout /var/log/nginx/access.log \
|
&& ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||||
&& ln -sf /dev/stderr /var/log/nginx/error.log \
|
&& ln -sf /dev/stderr /var/log/nginx/error.log \
|
||||||
|
@ -3,7 +3,7 @@ FROM vmware/photon:1.0
|
|||||||
ENV PGDATA /var/lib/postgresql/data
|
ENV PGDATA /var/lib/postgresql/data
|
||||||
|
|
||||||
RUN touch /etc/localtime.bak \
|
RUN touch /etc/localtime.bak \
|
||||||
&& tdnf distro-sync -y \
|
&& tdnf distro-sync -y || echo \
|
||||||
&& tdnf install -y sed shadow gzip postgresql\
|
&& tdnf install -y sed shadow gzip postgresql\
|
||||||
&& groupadd -r postgres --gid=999 \
|
&& groupadd -r postgres --gid=999 \
|
||||||
&& useradd -r -g postgres --uid=999 postgres \
|
&& useradd -r -g postgres --uid=999 postgres \
|
||||||
|
@ -2,7 +2,7 @@ FROM vmware/photon:1.0
|
|||||||
|
|
||||||
#base image for rsyslog base on photon
|
#base image for rsyslog base on photon
|
||||||
|
|
||||||
RUN tdnf distro-sync -y \
|
RUN tdnf distro-sync -y || echo \
|
||||||
&& tdnf install -y cronie rsyslog shadow tar gzip \
|
&& tdnf install -y cronie rsyslog shadow tar gzip \
|
||||||
&& mkdir /etc/rsyslog.d/ \
|
&& mkdir /etc/rsyslog.d/ \
|
||||||
&& mkdir /var/spool/rsyslog \
|
&& mkdir /var/spool/rsyslog \
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
FROM vmware/photon:1.0-20170928
|
FROM vmware/photon:1.0
|
||||||
|
|
||||||
RUN tdnf erase vim -y \
|
RUN tdnf erase vim -y \
|
||||||
&& tdnf distro-sync -y \
|
&& tdnf distro-sync -y || echo \
|
||||||
&& tdnf clean all \
|
&& tdnf clean all \
|
||||||
&& mkdir /harbor/
|
&& mkdir /harbor/
|
||||||
COPY ./make/dev/adminserver/harbor_adminserver /harbor/
|
COPY ./make/dev/adminserver/harbor_adminserver /harbor/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
FROM vmware/photon:1.0-20170928
|
FROM vmware/photon:1.0
|
||||||
|
|
||||||
RUN mkdir /harbor/ \
|
RUN mkdir /harbor/ \
|
||||||
&& tdnf distro-sync -y \
|
&& tdnf distro-sync -y || echo \
|
||||||
&& tdnf clean all
|
&& tdnf clean all
|
||||||
COPY ./make/dev/jobservice/harbor_jobservice /harbor/
|
COPY ./make/dev/jobservice/harbor_jobservice /harbor/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user