Skip to content

Commit 807b04c

Browse files
committed
#38 #35 #26 bump maria to 10.4, ability to ingest sql files, ability to set password via file
1 parent 83f79bf commit 807b04c

File tree

8 files changed

+70
-22
lines changed

8 files changed

+70
-22
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG BUILD_DATE
55
ARG VERSION
66
ARG MARIADB_VERSION
77
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
8-
LABEL maintainer="sparklyballs"
8+
LABEL maintainer="thelamer"
99

1010
# environment variables
1111
ARG DEBIAN_FRONTEND="noninteractive"
@@ -20,9 +20,9 @@ RUN \
2020
echo "add mariadb repository ****" && \
2121
echo "(redundant on armhf platform, but added for consistent dockerfile on all platforms) ****" && \
2222
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 && \
23-
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
23+
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2424
/etc/apt/sources.list.d/mariadb.list && \
25-
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
25+
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2626
/etc/apt/sources.list.d/mariadb.list && \
2727
echo "**** install runtime packages ****" && \
2828
if [ -z ${MARIADB_VERSION+x} ]; then \

Dockerfile.aarch64

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG BUILD_DATE
55
ARG VERSION
66
ARG MARIADB_VERSION
77
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
8-
LABEL maintainer="sparklyballs"
8+
LABEL maintainer="thelamer"
99

1010
# environment variables
1111
ARG DEBIAN_FRONTEND="noninteractive"
@@ -20,9 +20,9 @@ RUN \
2020
echo "add mariadb repository ****" && \
2121
echo "(redundant on armhf platform, but added for consistent dockerfile on all platforms) ****" && \
2222
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 && \
23-
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
23+
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2424
/etc/apt/sources.list.d/mariadb.list && \
25-
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
25+
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2626
/etc/apt/sources.list.d/mariadb.list && \
2727
echo "**** install runtime packages ****" && \
2828
if [ -z ${MARIADB_VERSION+x} ]; then \

Dockerfile.armhf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG BUILD_DATE
55
ARG VERSION
66
ARG MARIADB_VERSION
77
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
8-
LABEL maintainer="sparklyballs"
8+
LABEL maintainer="thelamer"
99

1010
# environment variables
1111
ARG DEBIAN_FRONTEND="noninteractive"
@@ -20,9 +20,9 @@ RUN \
2020
echo "add mariadb repository ****" && \
2121
echo "(redundant on armhf platform, but added for consistent dockerfile on all platforms) ****" && \
2222
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 && \
23-
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
23+
echo "deb http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2424
/etc/apt/sources.list.d/mariadb.list && \
25-
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main" >> \
25+
echo "deb-src http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu bionic main" >> \
2626
/etc/apt/sources.list.d/mariadb.list && \
2727
echo "**** install runtime packages ****" && \
2828
apt-get update && \

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pipeline {
101101
steps{
102102
script{
103103
env.EXT_RELEASE = sh(
104-
script: ''' curl -sX GET http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu/dists/bionic/main/binary-amd64/Packages |grep -A 7 -m 1 'Package: mariadb-server' | awk -F ': ' '/Version/{print $2;exit}' ''',
104+
script: ''' curl -sX GET http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu/dists/bionic/main/binary-amd64/Packages |grep -A 7 -m 1 'Package: mariadb-server' | awk -F ': ' '/Version/{print $2;exit}' ''',
105105
returnStdout: true).trim()
106106
env.RELEASE_LINK = 'custom_command'
107107
}

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ docker create \
6767
-e MYSQL_DATABASE=<USER DB NAME> `#optional` \
6868
-e MYSQL_USER=<MYSQL USER> `#optional` \
6969
-e MYSQL_PASSWORD=<DATABASE PASSWORD> `#optional` \
70+
-e MYSQL_ROOT_PASSWORD_FILE=/location/of/file `#optional` \
71+
-e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql `#optional` \
7072
-p 3306:3306 \
7173
-v <path to data>:/config \
7274
--restart unless-stopped \
@@ -93,6 +95,8 @@ services:
9395
- MYSQL_DATABASE=<USER DB NAME> #optional
9496
- MYSQL_USER=<MYSQL USER> #optional
9597
- MYSQL_PASSWORD=<DATABASE PASSWORD> #optional
98+
- MYSQL_ROOT_PASSWORD_FILE=/location/of/file #optional
99+
- REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql #optional
96100
volumes:
97101
- <path to data>:/config
98102
ports:
@@ -114,6 +118,8 @@ Container images are configured using parameters passed at runtime (such as thos
114118
| `-e MYSQL_DATABASE=<USER DB NAME>` | Specify the name of a database to be created on image startup. |
115119
| `-e MYSQL_USER=<MYSQL USER>` | This user will have superuser access to the database specified by MYSQL_DATABASE. |
116120
| `-e MYSQL_PASSWORD=<DATABASE PASSWORD>` | Set this to the password you want to use for you MYSQL_USER (minimum 4 characters). |
121+
| `-e MYSQL_ROOT_PASSWORD_FILE=/location/of/file` | Set this to the location of a text file containing your password. |
122+
| `-e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql` | Set this to ingest sql files from an http/https endpoint (comma seperated array). |
117123
| `-v /config` | Contains the db itself and all assorted settings. |
118124

119125
## User / Group Identifiers
@@ -137,7 +143,7 @@ If you didn't set a password during installation, (see logs for warning) use
137143
`mysqladmin -u root password <PASSWORD>`
138144
to set one at the docker prompt...
139145

140-
NOTE changing the MYSQL_ROOT_PASSWORD variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
146+
NOTE changing the MYSQL_ROOT_PASSWORD or MYSQL_ROOT_PASSWORD_FILE variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
141147

142148
NOTE if you want to use (MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD) **all three** of these variables need to be set you cannot pick and choose.
143149

@@ -146,6 +152,15 @@ Unraid users, it is advisable to edit the template/webui after setup and remove
146152
Find custom.cnf in /config for config changes (restart container for them to take effect)
147153
, the databases in /config/databases and the log in /config/log/myqsl
148154

155+
### Bootstrapping a new instance
156+
157+
We support a one time run of custom sql files on init. In order to use this place `*.sql` files in:
158+
159+
```
160+
/config/initdb.d/
161+
```
162+
This will have the same effect as setting the `REMOTE_SQL` environment variable. The sql will only be run on the containers first boot and setup.
163+
149164

150165

151166
## Support Info
@@ -212,6 +227,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
212227

213228
## Versions
214229

230+
* **27.10.19:** - Bump to 10.4, ability use custom sql on initial init ,defining root passwords via file.
215231
* **23.03.19:** - Switching to new Base images, shift to arm32v7 tag.
216232
* **07.03.19:** - Add ability to setup a database and default user on first spinup.
217233
* **26.01.19:** - Add pipeline logic and multi arch.

jenkins-vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# jenkins variables
44
project_name: docker-mariadb
55
external_type: na
6-
custom_version_command: "curl -sX GET http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu/dists/bionic/main/binary-amd64/Packages |grep -A 7 -m 1 'Package: mariadb-server' | awk -F ': ' '/Version/{print $2;exit}'"
6+
custom_version_command: "curl -sX GET http://mirror.sax.uk.as61049.net/mariadb/repo/10.4/ubuntu/dists/bionic/main/binary-amd64/Packages |grep -A 7 -m 1 'Package: mariadb-server' | awk -F ': ' '/Version/{print $2;exit}'"
77
release_type: stable
88
release_tag: latest
99
ls_branch: master

readme-vars.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ opt_param_env_vars:
4040
- { env_var: "MYSQL_DATABASE", env_value: "<USER DB NAME>", desc: "Specify the name of a database to be created on image startup." }
4141
- { env_var: "MYSQL_USER", env_value: "<MYSQL USER>", desc: "This user will have superuser access to the database specified by MYSQL_DATABASE." }
4242
- { env_var: "MYSQL_PASSWORD", env_value: "<DATABASE PASSWORD>", desc: "Set this to the password you want to use for you MYSQL_USER (minimum 4 characters)." }
43+
- { env_var: "MYSQL_ROOT_PASSWORD_FILE", env_value: "/location/of/file", desc: "Set this to the location of a text file containing your password." }
44+
- { env_var: "REMOTE_SQL", env_value: "http://URL1/your.sql,https://URL2/your.sql", desc: "Set this to ingest sql files from an http/https endpoint (comma seperated array)." }
4345
opt_param_usage_include_vols: false
4446
opt_param_usage_include_ports: false
4547
opt_param_device_map: false
@@ -53,7 +55,7 @@ app_setup_block: |
5355
`mysqladmin -u root password <PASSWORD>`
5456
to set one at the docker prompt...
5557
56-
NOTE changing the MYSQL_ROOT_PASSWORD variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
58+
NOTE changing the MYSQL_ROOT_PASSWORD or MYSQL_ROOT_PASSWORD_FILE variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
5759
5860
NOTE if you want to use (MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD) **all three** of these variables need to be set you cannot pick and choose.
5961
@@ -62,8 +64,18 @@ app_setup_block: |
6264
Find custom.cnf in /config for config changes (restart container for them to take effect)
6365
, the databases in /config/databases and the log in /config/log/myqsl
6466
67+
### Bootstrapping a new instance
68+
69+
We support a one time run of custom sql files on init. In order to use this place `*.sql` files in:
70+
71+
```
72+
/config/initdb.d/
73+
```
74+
This will have the same effect as setting the `REMOTE_SQL` environment variable. The sql will only be run on the containers first boot and setup.
75+
6576
# changelog
6677
changelogs:
78+
- { date: "27.10.19:", desc: "Bump to 10.4, ability use custom sql on initial init ,defining root passwords via file." }
6779
- { date: "23.03.19:", desc: "Switching to new Base images, shift to arm32v7 tag." }
6880
- { date: "07.03.19:", desc: "Add ability to setup a database and default user on first spinup." }
6981
- { date: "26.01.19:", desc: "Add pipeline logic and multi arch." }

root/etc/cont-init.d/40-initialise-db

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,26 @@ EOFPASS
3434

3535
# test for empty password variable, if it's set to 0 or less than 4 characters
3636
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
37-
TEST_LEN="0"
37+
if [ -f "$MYSQL_ROOT_PASSWORD_FILE" ]; then
38+
MYSQL_ROOT_PASSWORD=$(< "$MYSQL_ROOT_PASSWORD_FILE")
39+
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
40+
else
41+
TEST_LEN="0"
42+
fi
3843
else
39-
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
44+
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
4045
fi
4146
if [ "$TEST_LEN" -lt "4" ]; then
42-
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;"
47+
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;"
4348
else
44-
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;"
49+
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;"
4550
fi
4651

4752
# Make sure all user and database settings are set and pass is more than 4 characters
4853
if [ "${MYSQL_USER+x}" ] && \
4954
[ "${MYSQL_DATABASE+x}" ] && \
5055
[ "${MYSQL_PASSWORD+x}" ] && \
51-
[ "${#MYSQL_PASSWORD}" -gt "4" ]; then
56+
[ "${#MYSQL_PASSWORD}" -gt "3" ]; then
5257
read -r -d '' MYSQL_DB_SETUP << EOM
5358
CREATE DATABASE \`${MYSQL_DATABASE}\`;
5459
CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
@@ -65,6 +70,21 @@ $MYSQL_DB_SETUP
6570
EONEWSQL
6671
echo "Setting Up Initial Databases"
6772

73+
# add all sql from a user defined directory on first init
74+
if ([ -e "/config/initdb.d" ] && [ -n "$(/bin/ls -A /config/initdb.d/*.sql 2>/dev/null)" ]); then
75+
cat /config/initdb.d/*.sql >> "$tempSqlFile"
76+
fi
77+
78+
# ingest remote sql if REMOTE_SQL is set
79+
if [ -n "${REMOTE_SQL+set}" ]; then
80+
IFS=, read -ra URLS <<< "${REMOTE_SQL}"
81+
for URL in "${URLS[@]}"; do
82+
if [ $(curl -I -sL -w "%{http_code}" "${URL}" -o /dev/null) == 200 ]; then
83+
curl -sL "${URL}" >> "$tempSqlFile"
84+
fi
85+
done
86+
fi
87+
cat "$tempSqlFile"
6888
# set some permissions needed before we begin initialising
6989
chown -R abc:abc /config/log/mysql /var/run/mysqld
7090
chmod -R 777 /config/log/mysql /var/run/mysqld
@@ -82,8 +102,8 @@ echo "Database Setup Completed"
82102

83103
# display a message about password if not set or too short
84104
if [ "$TEST_LEN" -lt "4" ]; then
85-
printf '\n\n\n%s\n\n\n' "$(</tmp/no-pass.nfo)"
86-
sleep 5s
105+
printf '\n\n\n%s\n\n\n' "$(</tmp/no-pass.nfo)"
106+
sleep 5s
87107
fi
88108

89109
# do some more owning to finish our first run sequence
@@ -96,11 +116,11 @@ chown -R abc:abc /var/run/mysqld
96116

97117
# clean up any old install files from /tmp
98118
if [ -f "/tmp/no-pass.nfo" ]; then
99-
rm /tmp/no-pass.nfo
119+
rm /tmp/no-pass.nfo
100120
fi
101121

102122
if [ -f "/tmp/mysql-first-time.sql" ]; then
103-
rm /tmp/mysql-first-time.sql
123+
rm /tmp/mysql-first-time.sql
104124
fi
105125

106126
chown -R abc:abc /config

0 commit comments

Comments
 (0)