Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add official container for YOURLS #3752

Merged
merged 1 commit into from
Jul 18, 2018
Merged

Add official container for YOURLS #3752

merged 1 commit into from
Jul 18, 2018

Conversation

LeoColomb
Copy link
Contributor

@LeoColomb LeoColomb commented Nov 29, 2017

Summary

This pull request adds the requested file for the YOURLS container. I also submitted a pull request in the docs repository.

Repo: https://github.com/YOURLS/docker-yourls
Project: https://github.com/YOURLS/YOURLS

Checklist for Review

💌

@tianon
Copy link
Member

tianon commented Jan 4, 2018

It's clear you've done your homework on our process and expectations; thank you for that! ❤️ ❤️

Overall, the Dockerization looks pretty good (very similar to wordpress 😏), although I have a few comments (if I didn't, I wouldn't really be me 😅).

I see that the repository includes config-docker.php, but it doesn't get included into the image anywhere I can see, so that's probably important to fix. 😄 If you update the Dockerfile to drop it directly into /usr/src/yourls/config.php (with appropriate permissions), then you could drop all reference to it in the entrypoint script (since the initial tar will copy it over as necessary). The only downside to that I can think of is that folks couldn't then bring-their-own YOURLS install, but I think the expectation there would be that it already includes an appropriate config.php so that seems fine IMO. (Since this is upstream-maintained, I love the idea of the environment variables of the image being supported directly via config.php reading them from getenv. 😄)

All the haveConfig logic is probably unnecessary, since you don't actually update an existing configuration file (and simply add a sane default which reads environment variables dynamically), so that code could all go.

Additionally, you don't need the section for # linking backwards-compatibility unless you want it and want to continue to maintain it (since there's no precedent for an image existing, so this would really only be to simplify the docs currently).

The comment above uniqueEnvs is amusing and very familiar (:laughing:), but references a YOURLS_AUTH_KEY which doesn't exist. Since there's only one of these type of variables, it might be simpler to skip the Bash array entirely and simply have a single if check for that one specific variable, but definitely not going to mandate one or the other (just pointing out things I noticed).

Copying in config-docker.php if config.php doesn't exist should probably happen regardless of whether there are environment variables specified or not, right? (probably even including the environment variable default values, but those appear to exist in config-docker.php as well)

That php block at the end which connects to the database should reasonably be able to require '/var/www/html/config.php directly, shouldn't it? (since unlike WordPress, the config.php for YOURLS is simply a bunch of defines, and doesn't include any extra require or include logic, which is what makes that unsuitable for WordPress) That way it'd be able to provide value even for users who aren't using the environment variables (and are instead providing their own configuration file).

Isn't list($host, $socket) = explode(':', getenv('YOURLS_DB_HOST'), 2); accounting for a WordPress-specific syntax for connecting to a unix socket MySQL server instead of TCP (https://codex.wordpress.org/Editing_wp-config.php#MySQL_Sockets_or_Pipes)? Does YOURLS support the same syntax?

Several recent-ish WordPress PRs which are probably worth looking at for borrowing interesting and/or useful ideas:

@tianon

This comment has been minimized.

LeoColomb added a commit to YOURLS/containers that referenced this pull request Jan 28, 2018
cleaning old and/or out of scope scripts
ref docker-library/official-images#3752
@LeoColomb
Copy link
Contributor Author

LeoColomb commented Jan 28, 2018

thank you for that

It's me, thanks for your reply, @tianon!

very similar to wordpress

Hehe, yes, you're right! 😏

config-docker.php, but it doesn't get included

Oops, good catch, fixed, thanks! 😇

All the haveConfig logic is probably unnecessary
Additionally, you don't need the section for # linking backwards-compatibility

Re-checked and yes, again, you're right. Next time I took inspiration from another repo, I need to review more the code, right? 😆
Anyway, cleaned up.

YOURLS_AUTH_KEY

Yep, simplified. Even more than your suggestion. 💪

should reasonably be able to require

Really good idea, thanks!

Does YOURLS support the same syntax?

Yes.


Thanks A LOT for your very complete review, and for your time! 👍 🙏
Everything has been updated, let me know if I've well respected your precious pieces of advice. Thanks again.

@LeoColomb
Copy link
Contributor Author

Hmm, actually, the section regarding "backwards-compatibility" for mysql container seems needed to pass the tests.
How we should access MySQL env variables in a moderne way?

@ravikancherla
Copy link

Hi, I am looking forward for this. Any idea when this is going to be available ?

@LeoColomb
Copy link
Contributor Author

@tianon Hey! Any news? 😇 Thanks!

@tianon
Copy link
Member

tianon commented May 21, 2018

We've gotten way behind, but this is great and I'm happy with where it's at (and how diligent you've been in keeping it updated even though we're terrible ❤️ ❤️).

Updated Diff:
diff --git a/_bashbrew-arches b/_bashbrew-arches
index e69de29..05b2f99 100644
--- a/_bashbrew-arches
+++ b/_bashbrew-arches
@@ -0,0 +1,2 @@
+yourls:fpm @ amd64
+yourls:latest @ amd64
diff --git a/_bashbrew-list b/_bashbrew-list
index e69de29..771c164 100644
--- a/_bashbrew-list
+++ b/_bashbrew-list
@@ -0,0 +1,12 @@
+yourls:1
+yourls:1-apache
+yourls:1-fpm
+yourls:1.7
+yourls:1.7-apache
+yourls:1.7-fpm
+yourls:1.7.2
+yourls:1.7.2-apache
+yourls:1.7.2-fpm
+yourls:apache
+yourls:fpm
+yourls:latest
diff --git a/yourls_fpm/Dockerfile b/yourls_fpm/Dockerfile
new file mode 100644
index 0000000..e57428d
--- /dev/null
+++ b/yourls_fpm/Dockerfile
@@ -0,0 +1,48 @@
+FROM php:5.6-fpm
+
+# install the PHP extensions we need
+RUN set -ex; \
+    \
+    apt-get update; \
+    apt-get install -y --no-install-recommends \
+		bzip2 \
+		libcurl4-openssl-dev \
+		libmemcached-dev \
+		libxml2-dev \
+    ; \
+    rm -rf /var/lib/apt/lists/*; \
+    \
+    docker-php-ext-install mbstring opcache pdo pdo_mysql mysqli
+
+# set recommended PHP.ini settings
+# see https://secure.php.net/manual/en/opcache.installation.php
+RUN { \
+		echo 'opcache.memory_consumption=128'; \
+		echo 'opcache.interned_strings_buffer=8'; \
+		echo 'opcache.max_accelerated_files=4000'; \
+		echo 'opcache.revalidate_freq=60'; \
+		echo 'opcache.fast_shutdown=1'; \
+		echo 'opcache.enable_cli=1'; \
+	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
+
+
+VOLUME /var/www/html
+
+ENV YOURLS_VERSION 1.7.2
+#ENV YOURLS_SHA256 %%SHA256%%
+
+RUN set -ex; \
+	curl -o yourls.tar.gz -fsSL "https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz"; \
+	#echo "YOURLS_SHA256 *yourls.tar.gz" | sha256sum -c -; \
+# upstream tarballs include ./YOURLS-${YOURLS_VERSION}/ so this gives us /usr/src/YOURLS-${YOURLS_VERSION}
+	tar -xzf yourls.tar.gz -C /usr/src/; \
+# move back to a common /usr/src/yourls
+	mv "/usr/src/YOURLS-${YOURLS_VERSION}" /usr/src/yourls; \
+	rm yourls.tar.gz; \
+	chown -R www-data:www-data /usr/src/yourls
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY config-docker.php /var/www/html/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+CMD ["php-fpm"]
diff --git a/yourls_fpm/config-docker.php b/yourls_fpm/config-docker.php
new file mode 100644
index 0000000..7a7c665
--- /dev/null
+++ b/yourls_fpm/config-docker.php
@@ -0,0 +1,93 @@
+<?php
+/* This is a sample config file.
+ * Edit this file with your own settings and save it as "config.php"
+ *
+ * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
+ * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
+ */
+
+/*
+ ** MySQL settings - You can get this info from your web host
+ */
+
+/** MySQL database username */
+define( 'YOURLS_DB_USER', getenv('YOURLS_DB_USER') );
+
+/** MySQL database password */
+define( 'YOURLS_DB_PASS', getenv('YOURLS_DB_PASS') );
+
+/** The name of the database for YOURLS */
+define( 'YOURLS_DB_NAME', getenv('YOURLS_DB_NAME') );
+
+/** MySQL hostname.
+ ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
+define( 'YOURLS_DB_HOST', getenv('YOURLS_DB_HOST') ?: 'localhost' );
+
+/** MySQL tables prefix */
+define( 'YOURLS_DB_PREFIX', getenv('YOURLS_DB_PREFIX') ?: 'yourls_' );
+
+/*
+ ** Site options
+ */
+
+/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
+ ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
+define( 'YOURLS_SITE', getenv('YOURLS_SITE') ?: 'http://your-own-domain-here.com' );
+
+/** Server timezone GMT offset */
+define( 'YOURLS_HOURS_OFFSET', getenv('YOURLS_HOURS_OFFSET') ?: 0 );
+
+/** YOURLS language
+ ** Change this setting to use a translation file for your language, instead of the default English.
+ ** That translation file (a .mo file) must be installed in the user/language directory.
+ ** See http://yourls.org/translations for more information */
+define( 'YOURLS_LANG', getenv('YOURLS_LANG') ?: '' );
+
+/** Allow multiple short URLs for a same long URL
+ ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
+ ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
+define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') ?: true );
+
+/** Private means the Admin area will be protected with login/pass as defined below.
+ ** Set to false for public usage (eg on a restricted intranet or for test setups)
+ ** Read http://yourls.org/privatepublic for more details if you're unsure */
+define( 'YOURLS_PRIVATE', getenv('YOURLS_PRIVATE') ?: true );
+
+/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
+define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with something random' );
+
+/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
+ ** YOURLS will auto encrypt plain text passwords in this file
+ ** Read http://yourls.org/userpassword for more information */
+$yourls_user_passwords = array(
+  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),
+);
+
+/** Debug mode to output some internal information
+ ** Default is false for live site. Enable when coding or before submitting a new issue */
+define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false );
+
+/*
+ ** URL Shortening settings
+ */
+
+/** URL shortening method: 36 or 62 */
+define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 );
+/*
+ * 36: generates all lowercase keywords (ie: 13jkm)
+ * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
+ * Stick to one setting. It's best not to change after you've started creating links.
+ */
+
+/**
+* Reserved keywords (so that generated URLs won't match them)
+* Define here negative, unwanted or potentially misleading keywords.
+*/
+$yourls_reserved_URL = array(
+	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
+);
+
+/*
+ ** Personal settings would go after here.
+ */
+
diff --git a/yourls_fpm/docker-entrypoint.sh b/yourls_fpm/docker-entrypoint.sh
new file mode 100755
index 0000000..bed092c
--- /dev/null
+++ b/yourls_fpm/docker-entrypoint.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ ! -e /var/www/html/yourls-loader.php ]; then
+	tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
+	chown -R www-data:www-data /var/www/html
+fi
+
+# if not specified, let's use the default
+: "${YOURLS_DB_USER:=mysql}"
+: "${YOURLS_DB_PASS:=}"
+: "${YOURLS_DB_NAME:=yourls}"
+# if not specified, let's generate a random value
+: "${YOURLS_COOKIEKEY:=$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)}"
+
+if [ ! -e /var/www/html/user/config.php ]; then
+    cp /var/www/html/config-docker.php /var/www/html/user/config.php
+    chown www-data:www-data /var/www/html/user/config.php
+fi
+
+: "${YOURLS_USER:=}"
+: "${YOURLS_PASS:=}"
+if [ "${YOURLS_USER}" -a "${YOURLS_PASS}" ]; then
+    sed -i "s/  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),/  '${YOURLS_USER}' => '${YOURLS_PASS}',/g" /var/www/html/user/config.php
+fi
+
+TERM=dumb php -- <<'EOPHP'
+<?php
+// database might not exist, so let's try creating it (just to be safe)
+
+$stderr = fopen('php://stderr', 'w');
+
+require '/var/www/html/user/config.php';
+
+list($host, $socket) = explode(':', YOURLS_DB_HOST, 2);
+$port = 0;
+if (is_numeric($socket)) {
+	$port = (int) $socket;
+	$socket = null;
+}
+
+$maxTries = 10;
+do {
+	$mysql = new mysqli($host, YOURLS_DB_USER, YOURLS_DB_PASS, '', $port, $socket);
+	if ($mysql->connect_error) {
+		fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
+		--$maxTries;
+		if ($maxTries <= 0) {
+			exit(1);
+		}
+		sleep(3);
+	}
+} while ($mysql->connect_error);
+
+if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `'.$mysql->real_escape_string(YOURLS_DB_NAME).'`')) {
+	fwrite($stderr, "\nMySQL \"CREATE DATABASE\" Error: {$mysql->error}\n");
+	$mysql->close();
+	exit(1);
+}
+
+$mysql->close();
+EOPHP
+
+exec "$@"
diff --git a/yourls_latest/Dockerfile b/yourls_latest/Dockerfile
new file mode 100644
index 0000000..c98faf5
--- /dev/null
+++ b/yourls_latest/Dockerfile
@@ -0,0 +1,49 @@
+FROM php:5.6-apache
+
+# install the PHP extensions we need
+RUN set -ex; \
+    \
+    apt-get update; \
+    apt-get install -y --no-install-recommends \
+		bzip2 \
+		libcurl4-openssl-dev \
+		libmemcached-dev \
+		libxml2-dev \
+    ; \
+    rm -rf /var/lib/apt/lists/*; \
+    \
+    docker-php-ext-install mbstring opcache pdo pdo_mysql mysqli
+
+# set recommended PHP.ini settings
+# see https://secure.php.net/manual/en/opcache.installation.php
+RUN { \
+		echo 'opcache.memory_consumption=128'; \
+		echo 'opcache.interned_strings_buffer=8'; \
+		echo 'opcache.max_accelerated_files=4000'; \
+		echo 'opcache.revalidate_freq=60'; \
+		echo 'opcache.fast_shutdown=1'; \
+		echo 'opcache.enable_cli=1'; \
+	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
+
+RUN a2enmod rewrite expires
+
+VOLUME /var/www/html
+
+ENV YOURLS_VERSION 1.7.2
+#ENV YOURLS_SHA256 %%SHA256%%
+
+RUN set -ex; \
+	curl -o yourls.tar.gz -fsSL "https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz"; \
+	#echo "YOURLS_SHA256 *yourls.tar.gz" | sha256sum -c -; \
+# upstream tarballs include ./YOURLS-${YOURLS_VERSION}/ so this gives us /usr/src/YOURLS-${YOURLS_VERSION}
+	tar -xzf yourls.tar.gz -C /usr/src/; \
+# move back to a common /usr/src/yourls
+	mv "/usr/src/YOURLS-${YOURLS_VERSION}" /usr/src/yourls; \
+	rm yourls.tar.gz; \
+	chown -R www-data:www-data /usr/src/yourls
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY config-docker.php /var/www/html/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+CMD ["apache2-foreground"]
diff --git a/yourls_latest/config-docker.php b/yourls_latest/config-docker.php
new file mode 100644
index 0000000..7a7c665
--- /dev/null
+++ b/yourls_latest/config-docker.php
@@ -0,0 +1,93 @@
+<?php
+/* This is a sample config file.
+ * Edit this file with your own settings and save it as "config.php"
+ *
+ * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
+ * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
+ */
+
+/*
+ ** MySQL settings - You can get this info from your web host
+ */
+
+/** MySQL database username */
+define( 'YOURLS_DB_USER', getenv('YOURLS_DB_USER') );
+
+/** MySQL database password */
+define( 'YOURLS_DB_PASS', getenv('YOURLS_DB_PASS') );
+
+/** The name of the database for YOURLS */
+define( 'YOURLS_DB_NAME', getenv('YOURLS_DB_NAME') );
+
+/** MySQL hostname.
+ ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
+define( 'YOURLS_DB_HOST', getenv('YOURLS_DB_HOST') ?: 'localhost' );
+
+/** MySQL tables prefix */
+define( 'YOURLS_DB_PREFIX', getenv('YOURLS_DB_PREFIX') ?: 'yourls_' );
+
+/*
+ ** Site options
+ */
+
+/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
+ ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
+define( 'YOURLS_SITE', getenv('YOURLS_SITE') ?: 'http://your-own-domain-here.com' );
+
+/** Server timezone GMT offset */
+define( 'YOURLS_HOURS_OFFSET', getenv('YOURLS_HOURS_OFFSET') ?: 0 );
+
+/** YOURLS language
+ ** Change this setting to use a translation file for your language, instead of the default English.
+ ** That translation file (a .mo file) must be installed in the user/language directory.
+ ** See http://yourls.org/translations for more information */
+define( 'YOURLS_LANG', getenv('YOURLS_LANG') ?: '' );
+
+/** Allow multiple short URLs for a same long URL
+ ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
+ ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
+define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') ?: true );
+
+/** Private means the Admin area will be protected with login/pass as defined below.
+ ** Set to false for public usage (eg on a restricted intranet or for test setups)
+ ** Read http://yourls.org/privatepublic for more details if you're unsure */
+define( 'YOURLS_PRIVATE', getenv('YOURLS_PRIVATE') ?: true );
+
+/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
+define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with something random' );
+
+/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
+ ** YOURLS will auto encrypt plain text passwords in this file
+ ** Read http://yourls.org/userpassword for more information */
+$yourls_user_passwords = array(
+  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),
+);
+
+/** Debug mode to output some internal information
+ ** Default is false for live site. Enable when coding or before submitting a new issue */
+define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false );
+
+/*
+ ** URL Shortening settings
+ */
+
+/** URL shortening method: 36 or 62 */
+define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 );
+/*
+ * 36: generates all lowercase keywords (ie: 13jkm)
+ * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
+ * Stick to one setting. It's best not to change after you've started creating links.
+ */
+
+/**
+* Reserved keywords (so that generated URLs won't match them)
+* Define here negative, unwanted or potentially misleading keywords.
+*/
+$yourls_reserved_URL = array(
+	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
+);
+
+/*
+ ** Personal settings would go after here.
+ */
+
diff --git a/yourls_latest/docker-entrypoint.sh b/yourls_latest/docker-entrypoint.sh
new file mode 100755
index 0000000..bed092c
--- /dev/null
+++ b/yourls_latest/docker-entrypoint.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ ! -e /var/www/html/yourls-loader.php ]; then
+	tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
+	chown -R www-data:www-data /var/www/html
+fi
+
+# if not specified, let's use the default
+: "${YOURLS_DB_USER:=mysql}"
+: "${YOURLS_DB_PASS:=}"
+: "${YOURLS_DB_NAME:=yourls}"
+# if not specified, let's generate a random value
+: "${YOURLS_COOKIEKEY:=$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)}"
+
+if [ ! -e /var/www/html/user/config.php ]; then
+    cp /var/www/html/config-docker.php /var/www/html/user/config.php
+    chown www-data:www-data /var/www/html/user/config.php
+fi
+
+: "${YOURLS_USER:=}"
+: "${YOURLS_PASS:=}"
+if [ "${YOURLS_USER}" -a "${YOURLS_PASS}" ]; then
+    sed -i "s/  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),/  '${YOURLS_USER}' => '${YOURLS_PASS}',/g" /var/www/html/user/config.php
+fi
+
+TERM=dumb php -- <<'EOPHP'
+<?php
+// database might not exist, so let's try creating it (just to be safe)
+
+$stderr = fopen('php://stderr', 'w');
+
+require '/var/www/html/user/config.php';
+
+list($host, $socket) = explode(':', YOURLS_DB_HOST, 2);
+$port = 0;
+if (is_numeric($socket)) {
+	$port = (int) $socket;
+	$socket = null;
+}
+
+$maxTries = 10;
+do {
+	$mysql = new mysqli($host, YOURLS_DB_USER, YOURLS_DB_PASS, '', $port, $socket);
+	if ($mysql->connect_error) {
+		fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
+		--$maxTries;
+		if ($maxTries <= 0) {
+			exit(1);
+		}
+		sleep(3);
+	}
+} while ($mysql->connect_error);
+
+if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `'.$mysql->real_escape_string(YOURLS_DB_NAME).'`')) {
+	fwrite($stderr, "\nMySQL \"CREATE DATABASE\" Error: {$mysql->error}\n");
+	$mysql->close();
+	exit(1);
+}
+
+$mysql->close();
+EOPHP
+
+exec "$@"

@tianon
Copy link
Member

tianon commented May 21, 2018

Ah crap, small snag in the entrypoint script: (it's doing the MySQL bits even when the command is bash, so you'll probably want something like https://github.com/docker-library/wordpress/blob/47c785a349228b2528b81f352dbc27d2146ee69f/docker-entrypoint.sh#L26)

Build test of #3752; c28fd1ab; amd64 (yourls):

$ bashbrew build yourls:1.7.2-apache
Building bashbrew/cache:eeec49218ca9cc35b1d3870715d4b9c3cf0922b8acafd9cf21506d5f8d100b66 (yourls:1.7.2-apache)
Tagging yourls:1.7.2-apache
Tagging yourls:1.7-apache
Tagging yourls:1-apache
Tagging yourls:apache
Tagging yourls:1.7.2
Tagging yourls:1.7
Tagging yourls:1
Tagging yourls:latest

$ test/run.sh yourls:1.7.2-apache
testing yourls:1.7.2-apache
	'utc' [1/4]...passed
	'cve-2014--shellshock' [2/4]...passed
	'no-hard-coded-passwords' [3/4]...passed
	'override-cmd' [4/4]...
MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory
failed


$ bashbrew build yourls:1.7.2-fpm
Building bashbrew/cache:eccf778c931dd337e2f7a64326bbf800315f4316c10c6f75e17cc9b8d08d85aa (yourls:1.7.2-fpm)
Tagging yourls:1.7.2-fpm
Tagging yourls:1.7-fpm
Tagging yourls:1-fpm
Tagging yourls:fpm

$ test/run.sh yourls:1.7.2-fpm
testing yourls:1.7.2-fpm
	'utc' [1/4]...passed
	'cve-2014--shellshock' [2/4]...passed
	'no-hard-coded-passwords' [3/4]...passed
	'override-cmd' [4/4]...
MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory

MySQL Connection Error: (2002) No such file or directory
failed

The following images failed at least one test:

  • yourls:
    • yourls:1.7.2-apache
    • yourls:1.7.2-fpm

@LeoColomb
Copy link
Contributor Author

it's doing the MySQL bits even when the command is bash, so you'll probably want something like docker-library/wordpress:docker-entrypoint.sh@47c785a#L26

Yes, good suggestion, thanks.
So everything is clean and working now (hopefully 😇)!
Thanks again! 😸

@ravikancherla
Copy link

@tianon @LeoColomb - Any estimate on when this is going to be available ?

@LeoColomb
Copy link
Contributor Author

@ravikancherla Not at all. We're waiting for a validation, but I think @tianon and others are very busy! 🙂

@docker-library-bot
Copy link
Member

Hello! ✨

Thanks for your interest in contributing to the official images program. 💭

As you may have noticed, we've usually got a pretty decently sized queue of new images (not to mention image updates and maintenance of images under @docker-library which are maintained by the core official images team). As such, it may be some time before we get to reviewing this image (image updates get priority both because users expect them and because reviewing new images is a more involved process than reviewing updates), so we apologize in advance! Please be patient with us (and avoid poking us about your image via other communication means -- rest assured, we've seen your PR and it's in the queue). ❤️

We do try to proactively add and update the "new image checklist" on each PR, so if you haven't looked at it yet, that's a good use of time while you wait. ☔

Thanks! 💖 💙 💚 ❤️

@tianon
Copy link
Member

tianon commented Jul 18, 2018

Thanks @docker-library-bot ❤️

This looks good, let's do this. Thanks so much for being patient and responsive! ❤️ ❤️

Updated Updated Diff:
diff --git a/_bashbrew-arches b/_bashbrew-arches
index e69de29..7cd5750 100644
--- a/_bashbrew-arches
+++ b/_bashbrew-arches
@@ -0,0 +1,3 @@
+yourls:fpm @ amd64
+yourls:fpm-alpine @ amd64
+yourls:latest @ amd64
diff --git a/_bashbrew-list b/_bashbrew-list
index e69de29..33e5ade 100644
--- a/_bashbrew-list
+++ b/_bashbrew-list
@@ -0,0 +1,16 @@
+yourls:1
+yourls:1-apache
+yourls:1-fpm
+yourls:1-fpm-alpine
+yourls:1.7
+yourls:1.7-apache
+yourls:1.7-fpm
+yourls:1.7-fpm-alpine
+yourls:1.7.2
+yourls:1.7.2-apache
+yourls:1.7.2-fpm
+yourls:1.7.2-fpm-alpine
+yourls:apache
+yourls:fpm
+yourls:fpm-alpine
+yourls:latest
diff --git a/yourls_fpm-alpine/Dockerfile b/yourls_fpm-alpine/Dockerfile
new file mode 100644
index 0000000..9cce6e3
--- /dev/null
+++ b/yourls_fpm-alpine/Dockerfile
@@ -0,0 +1,39 @@
+FROM php:7.2-fpm-alpine
+
+# install the PHP extensions we need
+RUN set -ex; \
+    docker-php-ext-install opcache pdo_mysql mysqli
+
+# set recommended PHP.ini settings
+# see https://secure.php.net/manual/en/opcache.installation.php
+RUN { \
+		echo 'opcache.memory_consumption=128'; \
+		echo 'opcache.interned_strings_buffer=8'; \
+		echo 'opcache.max_accelerated_files=4000'; \
+		echo 'opcache.revalidate_freq=60'; \
+		echo 'opcache.fast_shutdown=1'; \
+		echo 'opcache.enable_cli=1'; \
+	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
+
+RUN apk add --no-cache bash
+
+VOLUME /var/www/html
+
+ENV YOURLS_VERSION 1.7.2
+#ENV YOURLS_SHA256 %%SHA256%%
+
+RUN set -ex; \
+	curl -o yourls.tar.gz -fsSL "https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz"; \
+	#echo "YOURLS_SHA256 *yourls.tar.gz" | sha256sum -c -; \
+# upstream tarballs include ./YOURLS-${YOURLS_VERSION}/ so this gives us /usr/src/YOURLS-${YOURLS_VERSION}
+	tar -xzf yourls.tar.gz -C /usr/src/; \
+# move back to a common /usr/src/yourls
+	mv "/usr/src/YOURLS-${YOURLS_VERSION}" /usr/src/yourls; \
+	rm yourls.tar.gz; \
+	chown -R www-data:www-data /usr/src/yourls
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY config-docker.php /var/www/html/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+CMD ["php-fpm"]
diff --git a/yourls_fpm-alpine/config-docker.php b/yourls_fpm-alpine/config-docker.php
new file mode 100644
index 0000000..a69ec33
--- /dev/null
+++ b/yourls_fpm-alpine/config-docker.php
@@ -0,0 +1,93 @@
+<?php
+/* This is a sample config file.
+ * Edit this file with your own settings and save it as "config.php"
+ *
+ * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
+ * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
+ */
+
+/*
+ ** MySQL settings - You can get this info from your web host
+ */
+
+/** MySQL database username */
+define( 'YOURLS_DB_USER', getenv('YOURLS_DB_USER') );
+
+/** MySQL database password */
+define( 'YOURLS_DB_PASS', getenv('YOURLS_DB_PASS') );
+
+/** The name of the database for YOURLS */
+define( 'YOURLS_DB_NAME', getenv('YOURLS_DB_NAME') );
+
+/** MySQL hostname.
+ ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
+define( 'YOURLS_DB_HOST', getenv('YOURLS_DB_HOST') ?: '127.0.0.1' );
+
+/** MySQL tables prefix */
+define( 'YOURLS_DB_PREFIX', getenv('YOURLS_DB_PREFIX') ?: 'yourls_' );
+
+/*
+ ** Site options
+ */
+
+/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
+ ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
+define( 'YOURLS_SITE', getenv('YOURLS_SITE') ?: 'http://your-own-domain-here.com' );
+
+/** Server timezone GMT offset */
+define( 'YOURLS_HOURS_OFFSET', getenv('YOURLS_HOURS_OFFSET') ?: 0 );
+
+/** YOURLS language
+ ** Change this setting to use a translation file for your language, instead of the default English.
+ ** That translation file (a .mo file) must be installed in the user/language directory.
+ ** See http://yourls.org/translations for more information */
+define( 'YOURLS_LANG', getenv('YOURLS_LANG') ?: '' );
+
+/** Allow multiple short URLs for a same long URL
+ ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
+ ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
+define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') ?: true );
+
+/** Private means the Admin area will be protected with login/pass as defined below.
+ ** Set to false for public usage (eg on a restricted intranet or for test setups)
+ ** Read http://yourls.org/privatepublic for more details if you're unsure */
+define( 'YOURLS_PRIVATE', getenv('YOURLS_PRIVATE') ?: true );
+
+/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
+define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with something random' );
+
+/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
+ ** YOURLS will auto encrypt plain text passwords in this file
+ ** Read http://yourls.org/userpassword for more information */
+$yourls_user_passwords = array(
+  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),
+);
+
+/** Debug mode to output some internal information
+ ** Default is false for live site. Enable when coding or before submitting a new issue */
+define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false );
+
+/*
+ ** URL Shortening settings
+ */
+
+/** URL shortening method: 36 or 62 */
+define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 );
+/*
+ * 36: generates all lowercase keywords (ie: 13jkm)
+ * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
+ * Stick to one setting. It's best not to change after you've started creating links.
+ */
+
+/**
+* Reserved keywords (so that generated URLs won't match them)
+* Define here negative, unwanted or potentially misleading keywords.
+*/
+$yourls_reserved_URL = array(
+	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
+);
+
+/*
+ ** Personal settings would go after here.
+ */
+
diff --git a/yourls_fpm-alpine/docker-entrypoint.sh b/yourls_fpm-alpine/docker-entrypoint.sh
new file mode 100755
index 0000000..68bebe9
--- /dev/null
+++ b/yourls_fpm-alpine/docker-entrypoint.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ ! -e /var/www/html/yourls-loader.php ]; then
+	tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
+	chown -R www-data:www-data /var/www/html
+fi
+
+if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
+	if [ "$(id -u)" = '0' ]; then
+		# if not specified, let's use the default
+		: "${YOURLS_DB_USER:=mysql}"
+		if [ "$YOURLS_DB_USER" = 'root' ]; then
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
+		else
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
+		fi
+		: "${YOURLS_DB_NAME:=yourls}"
+		# if not specified, let's generate a random value
+		: "${YOURLS_COOKIEKEY:=$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)}"
+
+		if [ ! -e /var/www/html/user/config.php ]; then
+			cp /var/www/html/config-docker.php /var/www/html/user/config.php
+			chown www-data:www-data /var/www/html/user/config.php
+		fi
+
+		: "${YOURLS_USER:=}"
+		: "${YOURLS_PASS:=}"
+		if [ "${YOURLS_USER}" -a "${YOURLS_PASS}" ]; then
+			sed -i "s/  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),/  '${YOURLS_USER}' => '${YOURLS_PASS}',/g" /var/www/html/user/config.php
+		fi
+
+		TERM=dumb php -- <<'EOPHP'
+<?php
+// database might not exist, so let's try creating it (just to be safe)
+
+$stderr = fopen('php://stderr', 'w');
+
+require '/var/www/html/user/config.php';
+
+list($host, $socket) = explode(':', YOURLS_DB_HOST, 2);
+$port = 0;
+if (is_numeric($socket)) {
+	$port = (int) $socket;
+	$socket = null;
+}
+
+$maxTries = 10;
+do {
+	$mysql = new mysqli($host, YOURLS_DB_USER, YOURLS_DB_PASS, '', $port, $socket);
+	if ($mysql->connect_error) {
+		fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
+		--$maxTries;
+		if ($maxTries <= 0) {
+			exit(1);
+		}
+		sleep(3);
+	}
+} while ($mysql->connect_error);
+
+if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `'.$mysql->real_escape_string(YOURLS_DB_NAME).'`')) {
+	fwrite($stderr, "\nMySQL \"CREATE DATABASE\" Error: {$mysql->error}\n");
+	$mysql->close();
+	exit(1);
+}
+
+$mysql->close();
+EOPHP
+	fi
+fi
+
+exec "$@"
diff --git a/yourls_fpm/Dockerfile b/yourls_fpm/Dockerfile
new file mode 100644
index 0000000..efbd067
--- /dev/null
+++ b/yourls_fpm/Dockerfile
@@ -0,0 +1,38 @@
+FROM php:7.2-fpm
+
+# install the PHP extensions we need
+RUN set -ex; \
+    docker-php-ext-install opcache pdo_mysql mysqli
+
+# set recommended PHP.ini settings
+# see https://secure.php.net/manual/en/opcache.installation.php
+RUN { \
+		echo 'opcache.memory_consumption=128'; \
+		echo 'opcache.interned_strings_buffer=8'; \
+		echo 'opcache.max_accelerated_files=4000'; \
+		echo 'opcache.revalidate_freq=60'; \
+		echo 'opcache.fast_shutdown=1'; \
+		echo 'opcache.enable_cli=1'; \
+	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
+
+
+VOLUME /var/www/html
+
+ENV YOURLS_VERSION 1.7.2
+#ENV YOURLS_SHA256 %%SHA256%%
+
+RUN set -ex; \
+	curl -o yourls.tar.gz -fsSL "https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz"; \
+	#echo "YOURLS_SHA256 *yourls.tar.gz" | sha256sum -c -; \
+# upstream tarballs include ./YOURLS-${YOURLS_VERSION}/ so this gives us /usr/src/YOURLS-${YOURLS_VERSION}
+	tar -xzf yourls.tar.gz -C /usr/src/; \
+# move back to a common /usr/src/yourls
+	mv "/usr/src/YOURLS-${YOURLS_VERSION}" /usr/src/yourls; \
+	rm yourls.tar.gz; \
+	chown -R www-data:www-data /usr/src/yourls
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY config-docker.php /var/www/html/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+CMD ["php-fpm"]
diff --git a/yourls_fpm/config-docker.php b/yourls_fpm/config-docker.php
new file mode 100644
index 0000000..a69ec33
--- /dev/null
+++ b/yourls_fpm/config-docker.php
@@ -0,0 +1,93 @@
+<?php
+/* This is a sample config file.
+ * Edit this file with your own settings and save it as "config.php"
+ *
+ * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
+ * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
+ */
+
+/*
+ ** MySQL settings - You can get this info from your web host
+ */
+
+/** MySQL database username */
+define( 'YOURLS_DB_USER', getenv('YOURLS_DB_USER') );
+
+/** MySQL database password */
+define( 'YOURLS_DB_PASS', getenv('YOURLS_DB_PASS') );
+
+/** The name of the database for YOURLS */
+define( 'YOURLS_DB_NAME', getenv('YOURLS_DB_NAME') );
+
+/** MySQL hostname.
+ ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
+define( 'YOURLS_DB_HOST', getenv('YOURLS_DB_HOST') ?: '127.0.0.1' );
+
+/** MySQL tables prefix */
+define( 'YOURLS_DB_PREFIX', getenv('YOURLS_DB_PREFIX') ?: 'yourls_' );
+
+/*
+ ** Site options
+ */
+
+/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
+ ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
+define( 'YOURLS_SITE', getenv('YOURLS_SITE') ?: 'http://your-own-domain-here.com' );
+
+/** Server timezone GMT offset */
+define( 'YOURLS_HOURS_OFFSET', getenv('YOURLS_HOURS_OFFSET') ?: 0 );
+
+/** YOURLS language
+ ** Change this setting to use a translation file for your language, instead of the default English.
+ ** That translation file (a .mo file) must be installed in the user/language directory.
+ ** See http://yourls.org/translations for more information */
+define( 'YOURLS_LANG', getenv('YOURLS_LANG') ?: '' );
+
+/** Allow multiple short URLs for a same long URL
+ ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
+ ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
+define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') ?: true );
+
+/** Private means the Admin area will be protected with login/pass as defined below.
+ ** Set to false for public usage (eg on a restricted intranet or for test setups)
+ ** Read http://yourls.org/privatepublic for more details if you're unsure */
+define( 'YOURLS_PRIVATE', getenv('YOURLS_PRIVATE') ?: true );
+
+/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
+define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with something random' );
+
+/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
+ ** YOURLS will auto encrypt plain text passwords in this file
+ ** Read http://yourls.org/userpassword for more information */
+$yourls_user_passwords = array(
+  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),
+);
+
+/** Debug mode to output some internal information
+ ** Default is false for live site. Enable when coding or before submitting a new issue */
+define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false );
+
+/*
+ ** URL Shortening settings
+ */
+
+/** URL shortening method: 36 or 62 */
+define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 );
+/*
+ * 36: generates all lowercase keywords (ie: 13jkm)
+ * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
+ * Stick to one setting. It's best not to change after you've started creating links.
+ */
+
+/**
+* Reserved keywords (so that generated URLs won't match them)
+* Define here negative, unwanted or potentially misleading keywords.
+*/
+$yourls_reserved_URL = array(
+	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
+);
+
+/*
+ ** Personal settings would go after here.
+ */
+
diff --git a/yourls_fpm/docker-entrypoint.sh b/yourls_fpm/docker-entrypoint.sh
new file mode 100755
index 0000000..68bebe9
--- /dev/null
+++ b/yourls_fpm/docker-entrypoint.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ ! -e /var/www/html/yourls-loader.php ]; then
+	tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
+	chown -R www-data:www-data /var/www/html
+fi
+
+if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
+	if [ "$(id -u)" = '0' ]; then
+		# if not specified, let's use the default
+		: "${YOURLS_DB_USER:=mysql}"
+		if [ "$YOURLS_DB_USER" = 'root' ]; then
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
+		else
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
+		fi
+		: "${YOURLS_DB_NAME:=yourls}"
+		# if not specified, let's generate a random value
+		: "${YOURLS_COOKIEKEY:=$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)}"
+
+		if [ ! -e /var/www/html/user/config.php ]; then
+			cp /var/www/html/config-docker.php /var/www/html/user/config.php
+			chown www-data:www-data /var/www/html/user/config.php
+		fi
+
+		: "${YOURLS_USER:=}"
+		: "${YOURLS_PASS:=}"
+		if [ "${YOURLS_USER}" -a "${YOURLS_PASS}" ]; then
+			sed -i "s/  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),/  '${YOURLS_USER}' => '${YOURLS_PASS}',/g" /var/www/html/user/config.php
+		fi
+
+		TERM=dumb php -- <<'EOPHP'
+<?php
+// database might not exist, so let's try creating it (just to be safe)
+
+$stderr = fopen('php://stderr', 'w');
+
+require '/var/www/html/user/config.php';
+
+list($host, $socket) = explode(':', YOURLS_DB_HOST, 2);
+$port = 0;
+if (is_numeric($socket)) {
+	$port = (int) $socket;
+	$socket = null;
+}
+
+$maxTries = 10;
+do {
+	$mysql = new mysqli($host, YOURLS_DB_USER, YOURLS_DB_PASS, '', $port, $socket);
+	if ($mysql->connect_error) {
+		fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
+		--$maxTries;
+		if ($maxTries <= 0) {
+			exit(1);
+		}
+		sleep(3);
+	}
+} while ($mysql->connect_error);
+
+if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `'.$mysql->real_escape_string(YOURLS_DB_NAME).'`')) {
+	fwrite($stderr, "\nMySQL \"CREATE DATABASE\" Error: {$mysql->error}\n");
+	$mysql->close();
+	exit(1);
+}
+
+$mysql->close();
+EOPHP
+	fi
+fi
+
+exec "$@"
diff --git a/yourls_latest/Dockerfile b/yourls_latest/Dockerfile
new file mode 100644
index 0000000..2e19841
--- /dev/null
+++ b/yourls_latest/Dockerfile
@@ -0,0 +1,39 @@
+FROM php:7.2-apache
+
+# install the PHP extensions we need
+RUN set -ex; \
+    docker-php-ext-install opcache pdo_mysql mysqli
+
+# set recommended PHP.ini settings
+# see https://secure.php.net/manual/en/opcache.installation.php
+RUN { \
+		echo 'opcache.memory_consumption=128'; \
+		echo 'opcache.interned_strings_buffer=8'; \
+		echo 'opcache.max_accelerated_files=4000'; \
+		echo 'opcache.revalidate_freq=60'; \
+		echo 'opcache.fast_shutdown=1'; \
+		echo 'opcache.enable_cli=1'; \
+	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
+
+RUN a2enmod rewrite expires
+
+VOLUME /var/www/html
+
+ENV YOURLS_VERSION 1.7.2
+#ENV YOURLS_SHA256 %%SHA256%%
+
+RUN set -ex; \
+	curl -o yourls.tar.gz -fsSL "https://github.com/YOURLS/YOURLS/archive/${YOURLS_VERSION}.tar.gz"; \
+	#echo "YOURLS_SHA256 *yourls.tar.gz" | sha256sum -c -; \
+# upstream tarballs include ./YOURLS-${YOURLS_VERSION}/ so this gives us /usr/src/YOURLS-${YOURLS_VERSION}
+	tar -xzf yourls.tar.gz -C /usr/src/; \
+# move back to a common /usr/src/yourls
+	mv "/usr/src/YOURLS-${YOURLS_VERSION}" /usr/src/yourls; \
+	rm yourls.tar.gz; \
+	chown -R www-data:www-data /usr/src/yourls
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY config-docker.php /var/www/html/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+CMD ["apache2-foreground"]
diff --git a/yourls_latest/config-docker.php b/yourls_latest/config-docker.php
new file mode 100644
index 0000000..a69ec33
--- /dev/null
+++ b/yourls_latest/config-docker.php
@@ -0,0 +1,93 @@
+<?php
+/* This is a sample config file.
+ * Edit this file with your own settings and save it as "config.php"
+ *
+ * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
+ * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
+ */
+
+/*
+ ** MySQL settings - You can get this info from your web host
+ */
+
+/** MySQL database username */
+define( 'YOURLS_DB_USER', getenv('YOURLS_DB_USER') );
+
+/** MySQL database password */
+define( 'YOURLS_DB_PASS', getenv('YOURLS_DB_PASS') );
+
+/** The name of the database for YOURLS */
+define( 'YOURLS_DB_NAME', getenv('YOURLS_DB_NAME') );
+
+/** MySQL hostname.
+ ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
+define( 'YOURLS_DB_HOST', getenv('YOURLS_DB_HOST') ?: '127.0.0.1' );
+
+/** MySQL tables prefix */
+define( 'YOURLS_DB_PREFIX', getenv('YOURLS_DB_PREFIX') ?: 'yourls_' );
+
+/*
+ ** Site options
+ */
+
+/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
+ ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
+define( 'YOURLS_SITE', getenv('YOURLS_SITE') ?: 'http://your-own-domain-here.com' );
+
+/** Server timezone GMT offset */
+define( 'YOURLS_HOURS_OFFSET', getenv('YOURLS_HOURS_OFFSET') ?: 0 );
+
+/** YOURLS language
+ ** Change this setting to use a translation file for your language, instead of the default English.
+ ** That translation file (a .mo file) must be installed in the user/language directory.
+ ** See http://yourls.org/translations for more information */
+define( 'YOURLS_LANG', getenv('YOURLS_LANG') ?: '' );
+
+/** Allow multiple short URLs for a same long URL
+ ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
+ ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
+define( 'YOURLS_UNIQUE_URLS', getenv('YOURLS_UNIQUE_URLS') ?: true );
+
+/** Private means the Admin area will be protected with login/pass as defined below.
+ ** Set to false for public usage (eg on a restricted intranet or for test setups)
+ ** Read http://yourls.org/privatepublic for more details if you're unsure */
+define( 'YOURLS_PRIVATE', getenv('YOURLS_PRIVATE') ?: true );
+
+/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
+define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with something random' );
+
+/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
+ ** YOURLS will auto encrypt plain text passwords in this file
+ ** Read http://yourls.org/userpassword for more information */
+$yourls_user_passwords = array(
+  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),
+);
+
+/** Debug mode to output some internal information
+ ** Default is false for live site. Enable when coding or before submitting a new issue */
+define( 'YOURLS_DEBUG', getenv('YOURLS_DEBUG') ?: false );
+
+/*
+ ** URL Shortening settings
+ */
+
+/** URL shortening method: 36 or 62 */
+define( 'YOURLS_URL_CONVERT', getenv('YOURLS_URL_CONVERT') ?: 36 );
+/*
+ * 36: generates all lowercase keywords (ie: 13jkm)
+ * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
+ * Stick to one setting. It's best not to change after you've started creating links.
+ */
+
+/**
+* Reserved keywords (so that generated URLs won't match them)
+* Define here negative, unwanted or potentially misleading keywords.
+*/
+$yourls_reserved_URL = array(
+	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
+);
+
+/*
+ ** Personal settings would go after here.
+ */
+
diff --git a/yourls_latest/docker-entrypoint.sh b/yourls_latest/docker-entrypoint.sh
new file mode 100755
index 0000000..68bebe9
--- /dev/null
+++ b/yourls_latest/docker-entrypoint.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+set -euo pipefail
+
+if [ ! -e /var/www/html/yourls-loader.php ]; then
+	tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
+	chown -R www-data:www-data /var/www/html
+fi
+
+if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
+	if [ "$(id -u)" = '0' ]; then
+		# if not specified, let's use the default
+		: "${YOURLS_DB_USER:=mysql}"
+		if [ "$YOURLS_DB_USER" = 'root' ]; then
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
+		else
+			: "${YOURLS_DB_PASS:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
+		fi
+		: "${YOURLS_DB_NAME:=yourls}"
+		# if not specified, let's generate a random value
+		: "${YOURLS_COOKIEKEY:=$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)}"
+
+		if [ ! -e /var/www/html/user/config.php ]; then
+			cp /var/www/html/config-docker.php /var/www/html/user/config.php
+			chown www-data:www-data /var/www/html/user/config.php
+		fi
+
+		: "${YOURLS_USER:=}"
+		: "${YOURLS_PASS:=}"
+		if [ "${YOURLS_USER}" -a "${YOURLS_PASS}" ]; then
+			sed -i "s/  getenv('YOURLS_USER') => getenv('YOURLS_PASS'),/  '${YOURLS_USER}' => '${YOURLS_PASS}',/g" /var/www/html/user/config.php
+		fi
+
+		TERM=dumb php -- <<'EOPHP'
+<?php
+// database might not exist, so let's try creating it (just to be safe)
+
+$stderr = fopen('php://stderr', 'w');
+
+require '/var/www/html/user/config.php';
+
+list($host, $socket) = explode(':', YOURLS_DB_HOST, 2);
+$port = 0;
+if (is_numeric($socket)) {
+	$port = (int) $socket;
+	$socket = null;
+}
+
+$maxTries = 10;
+do {
+	$mysql = new mysqli($host, YOURLS_DB_USER, YOURLS_DB_PASS, '', $port, $socket);
+	if ($mysql->connect_error) {
+		fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
+		--$maxTries;
+		if ($maxTries <= 0) {
+			exit(1);
+		}
+		sleep(3);
+	}
+} while ($mysql->connect_error);
+
+if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `'.$mysql->real_escape_string(YOURLS_DB_NAME).'`')) {
+	fwrite($stderr, "\nMySQL \"CREATE DATABASE\" Error: {$mysql->error}\n");
+	$mysql->close();
+	exit(1);
+}
+
+$mysql->close();
+EOPHP
+	fi
+fi
+
+exec "$@"

Build test of #3752; 1242342; amd64 (yourls):

$ bashbrew build yourls:1.7.2-apache
Building bashbrew/cache:7faee2b714b91be459b9b493c51ee4ccb53b3cd4ec50a12d3552e827714094af (yourls:1.7.2-apache)
Tagging yourls:1.7.2-apache
Tagging yourls:1.7-apache
Tagging yourls:1-apache
Tagging yourls:apache
Tagging yourls:1.7.2
Tagging yourls:1.7
Tagging yourls:1
Tagging yourls:latest

$ test/run.sh yourls:1.7.2-apache
testing yourls:1.7.2-apache
	'utc' [1/4]...passed
	'cve-2014--shellshock' [2/4]...passed
	'no-hard-coded-passwords' [3/4]...passed
	'override-cmd' [4/4]...passed


$ bashbrew build yourls:1.7.2-fpm
Building bashbrew/cache:22e22da43e20b88dfa9c7be633221ce04b1f32b09efd560e9a41e16a8d54b979 (yourls:1.7.2-fpm)
Tagging yourls:1.7.2-fpm
Tagging yourls:1.7-fpm
Tagging yourls:1-fpm
Tagging yourls:fpm

$ test/run.sh yourls:1.7.2-fpm
testing yourls:1.7.2-fpm
	'utc' [1/4]...passed
	'cve-2014--shellshock' [2/4]...passed
	'no-hard-coded-passwords' [3/4]...passed
	'override-cmd' [4/4]...passed


$ bashbrew build yourls:1.7.2-fpm-alpine
Building bashbrew/cache:d086b3c00cd7c80cf708985df886d2478da0178a963b1e14c4d186655fece7fe (yourls:1.7.2-fpm-alpine)
Tagging yourls:1.7.2-fpm-alpine
Tagging yourls:1.7-fpm-alpine
Tagging yourls:1-fpm-alpine
Tagging yourls:fpm-alpine

$ test/run.sh yourls:1.7.2-fpm-alpine
testing yourls:1.7.2-fpm-alpine
	'utc' [1/4]...passed
	'cve-2014--shellshock' [2/4]...passed
	'no-hard-coded-passwords' [3/4]...passed
	'override-cmd' [4/4]...passed

@yosifkit yosifkit merged commit 49a4bc2 into docker-library:master Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants