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

Update YOURLS #16248

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Conversation

LeoColomb
Copy link
Contributor

@LeoColomb LeoColomb commented Feb 14, 2024

Automated changes from YOURLS/images via GitHub Actions run #4336679159.

This comment has been minimized.

@yosifkit
Copy link
Member

FROM php:8.3.2-apache

We recommend that this stays as php:8.3-apache in order to get timely OS package and PHP patch-version updates. When any image in official-images is changed, all dependent official images are rebuilt. This is why we require that any image update be FROM a current/active official image. We do not support old patch releases of php images, so this would quickly cause the yourls images to stop getting rebuild updates (when PHP 8.3.3 is released).

A few bits of feedback on the customPostInitScripts:

  • not sure if it is desired, but the current find will also get all files in subdirectories as well, so you might want it limited in some way (-mindepth 1 -maxdepth 1?). For images we maintain, we only use scripts from the top level and let users have helper scripts or data in deeper directories.
    for init_script in /docker-entrypoint-init.d/* do
    ...
  • the helm chart mentions just three file types so I think the loop should only process .sh, .sql, and .php scripts and each should likely be handled differently and then ignore anything else
    case "$init_script" in
      *.sh)
        if ...
        ;;
      *.php)
        php -f "$init_script"
        ...
      *) echo >&2 "ignoring $init_script" ;;
    esac
  • it should do something different with non-executable .sh files. (perhaps source them like postgres, or maybe ignore them like nginx)
    if [ -x "$init_script" ] then "$init_script"; else ??; fi
  • (for images we maintain, we don't typically add this type of functionality unless there's a temporary server involved such as MySQL or PostgreSQL, because it is trivial for users to inject their own entrypoint script or change the container command such that it does some arbitrary extra work before running the image's software, but it is ultimately up to you if you want to include/maintain this functionality)

@LeoColomb
Copy link
Contributor Author

We recommend that this stays as php:8.3-apache

Understood, I'll figure out how to revert to this. 👍

A few bits of feedback on the customPostInitScripts

Indeed, after a second glance, I see it raises few concerns.
@ggarson, as you submitted this addition on YOURLS/containers#263, what do you think about this?

@ggarson
Copy link

ggarson commented Mar 5, 2024

@LeoColomb @yosifkit.
I'm not aware of all your rules and habtis, so I'm ok with the first 3 points.

For the last one, don't think only with a pure docker perspective, most docker users run their docks on a Kubernetes cluster and use Helm to do it. Normally, your dockerfile should be really tighten with capabilities proposed in the helm chart and inversely. You forked helm chart structure from Bitnami who is the biggest maintainer of helm charts and docker containers and they worked like that. When I tried to deploy for the first time yourls with your helm chart, I spent some time to find why my init custom script doesn't work. If you don't want to add some features to your dockerfile, don't put them in the helm chart because it will confuse users (like me) and discourage the less patient.

I think your objective, as an opensource software maintainer, is to facilitate usage and adoption of yourls.

@LeoColomb LeoColomb force-pushed the create-pull-request/patch branch from 96759c0 to b406ebe Compare April 18, 2024 21:47
@LeoColomb LeoColomb requested a review from a team as a code owner April 18, 2024 21:47
Copy link

Diff for b406ebe:
diff --git a/_bashbrew-cat b/_bashbrew-cat
index fa8037b..9979749 100644
--- a/_bashbrew-cat
+++ b/_bashbrew-cat
@@ -1,18 +1,18 @@
 Maintainers: YOURLS <yourls@yourls.org> (@YOURLS), Léo Colombaro <git@colombaro.fr> (@LeoColomb)
-GitRepo: https://github.com/YOURLS/docker.git
+GitRepo: https://github.com/YOURLS/images.git
 GitFetch: refs/heads/dist
 
 Tags: 1.9.2-apache, 1.9-apache, 1-apache, apache, 1.9.2, 1.9, 1, latest
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 2ef3b5fe2539efd8dd876727376ddee2c22079b5
+GitCommit: 082820033f591498dbc30d4ffc0cc927197ebf26
 Directory: apache
 
 Tags: 1.9.2-fpm, 1.9-fpm, 1-fpm, fpm
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 2ef3b5fe2539efd8dd876727376ddee2c22079b5
+GitCommit: 082820033f591498dbc30d4ffc0cc927197ebf26
 Directory: fpm
 
 Tags: 1.9.2-fpm-alpine, 1.9-fpm-alpine, 1-fpm-alpine, fpm-alpine
 Architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
-GitCommit: 2ef3b5fe2539efd8dd876727376ddee2c22079b5
+GitCommit: 082820033f591498dbc30d4ffc0cc927197ebf26
 Directory: fpm-alpine
diff --git a/yourls_fpm-alpine/Dockerfile b/yourls_fpm-alpine/Dockerfile
index dc0e788..954f733 100644
--- a/yourls_fpm-alpine/Dockerfile
+++ b/yourls_fpm-alpine/Dockerfile
@@ -1,13 +1,4 @@
-FROM php:8.2-fpm-alpine
-
-LABEL org.opencontainers.image.title="YOURLS"
-LABEL org.opencontainers.image.description="Your Own URL Shortener"
-LABEL org.opencontainers.image.url="https://yourls.org/"
-LABEL org.opencontainers.image.documentation="https://yourls.org/"
-LABEL org.opencontainers.image.vendor="YOURLS Org"
-LABEL org.opencontainers.image.authors="YOURLS"
-LABEL org.opencontainers.image.licenses="MIT"
-LABEL io.artifacthub.package.readme-url="https://raw.githubusercontent.com/YOURLS/YOURLS/master/README.md"
+FROM php:8.3-fpm-alpine
 
 # install the PHP extensions we need
 RUN set -eux; \
@@ -29,8 +20,6 @@ RUN apk add --no-cache bash
 ARG YOURLS_VERSION="1.9.2"
 ARG YOURLS_SHA256="62a95ba766d62f3305d75944cbfe12d5a90c08c88fbf2f6e67150d36412b916f"
 
-LABEL org.opencontainers.image.version="$YOURLS_VERSION"
-
 ENV YOURLS_VERSION=$YOURLS_VERSION
 ENV YOURLS_SHA256=$YOURLS_SHA256
 
@@ -44,8 +33,8 @@ RUN set -eux; \
     rm yourls.tar.gz; \
     chown -R www-data:www-data /usr/src/yourls
 
-COPY --chown=www-data:www-data config-docker.php /usr/src/yourls/user/
-COPY docker-entrypoint.sh /usr/local/bin/
+COPY --chown=www-data:www-data config-container.php /usr/src/yourls/user/
+COPY container-entrypoint.sh /usr/local/bin/
 
-ENTRYPOINT ["docker-entrypoint.sh"]
+ENTRYPOINT ["container-entrypoint.sh"]
 CMD ["php-fpm"]
diff --git a/yourls_latest/config-docker.php b/yourls_fpm-alpine/config-container.php
similarity index 85%
rename from yourls_latest/config-docker.php
rename to yourls_fpm-alpine/config-container.php
index cf56824..43d4302 100644
--- a/yourls_latest/config-docker.php
+++ b/yourls_fpm-alpine/config-container.php
@@ -4,8 +4,8 @@
  */
 
 // a helper function to lookup "env_FILE", "env", then fallback
-if (!function_exists('getenv_docker')) {
-    function getenv_docker(string $name, ?string $default = null): ?string
+if (!function_exists('getenv_container')) {
+    function getenv_container(string $name, ?string $default = null): ?string
     {
         if ($fileEnv = getenv($name . '_FILE')) {
             return trim(file_get_contents($fileEnv));
@@ -23,20 +23,20 @@ if (!function_exists('getenv_docker')) {
  */
 
 /** MySQL database username */
-define( 'YOURLS_DB_USER', getenv_docker('YOURLS_DB_USER', 'root') );
+define( 'YOURLS_DB_USER', getenv_container('YOURLS_DB_USER', 'root') );
 
 /** MySQL database password */
-define( 'YOURLS_DB_PASS', getenv_docker('YOURLS_DB_PASS') );
+define( 'YOURLS_DB_PASS', getenv_container('YOURLS_DB_PASS') );
 
 /** The name of the database for YOURLS */
-define( 'YOURLS_DB_NAME', getenv_docker('YOURLS_DB_NAME', 'yourls') );
+define( 'YOURLS_DB_NAME', getenv_container('YOURLS_DB_NAME', 'yourls') );
 
 /** 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_docker('YOURLS_DB_HOST', 'mysql') );
+define( 'YOURLS_DB_HOST', getenv_container('YOURLS_DB_HOST', 'mysql') );
 
 /** MySQL tables prefix */
-define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
+define( 'YOURLS_DB_PREFIX', getenv_container('YOURLS_DB_PREFIX', 'yourls_') );
 
 /*
  ** Site options
@@ -44,7 +44,7 @@ define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
 
 /** 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_docker('YOURLS_SITE', 'http://your-own-domain-here.com') );
+define( 'YOURLS_SITE', getenv_container('YOURLS_SITE', 'http://your-own-domain-here.com') );
 
 /** Server timezone GMT offset */
 define( 'YOURLS_HOURS_OFFSET', filter_var(getenv('YOURLS_HOURS_OFFSET'), FILTER_VALIDATE_INT) ?: 0 );
@@ -72,7 +72,7 @@ define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with
  ** YOURLS will auto encrypt plain text passwords in this file
  ** Read http://yourls.org/userpassword for more information */
 $yourls_user_passwords = [
-    getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),
+    getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),
 ];
 
 /** Debug mode to output some internal information
diff --git a/yourls_latest/docker-entrypoint.sh b/yourls_fpm-alpine/container-entrypoint.sh
similarity index 82%
rename from yourls_latest/docker-entrypoint.sh
rename to yourls_fpm-alpine/container-entrypoint.sh
index 8b65b17..b137360 100755
--- a/yourls_latest/docker-entrypoint.sh
+++ b/yourls_fpm-alpine/container-entrypoint.sh
@@ -72,12 +72,12 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 	# We want to copy the initial config if the actual config file doesn't already
 	# exist OR if it is an empty file (e.g. it has been created for the volume mount).
 	if [ ! -s user/config.php ]; then
-		cp /usr/src/yourls/user/config-docker.php user/config.php
+		cp /usr/src/yourls/user/config-container.php user/config.php
 
 		: "${YOURLS_USER:=}"
 		: "${YOURLS_PASS:=}"
 		if [ -n "${YOURLS_USER}" ] && [ -n "${YOURLS_PASS}" ]; then
-			result=$(sed "s/  getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
+			result=$(sed "s/  getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
 			echo "$result" > user/config.php
 		fi
 
@@ -86,6 +86,26 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 			# could be on a filesystem that doesn't allow chown (like some NFS setups)
 			chown "$user:$group" user/config.php || true
 		fi
+
+		# ability to use custom script
+		for file in /docker-entrypoint-init.d/*; do
+			echo >&2 "Running custom script $file"
+			case "$file" in
+			*.sh)
+				if [ -x "$file" ]; then
+					"$file" || exit 1
+				else
+					echo >&2 "... ignoring non-executable $file"
+				fi
+				;;
+			*.php)
+				php -f "$file"
+				;;
+			*)
+				echo >&2 "... ignoring $file"
+				;;
+			esac
+		done
 	fi
 fi
 
diff --git a/yourls_fpm/Dockerfile b/yourls_fpm/Dockerfile
index f12d542..7176d4e 100644
--- a/yourls_fpm/Dockerfile
+++ b/yourls_fpm/Dockerfile
@@ -1,13 +1,4 @@
-FROM php:8.2-fpm
-
-LABEL org.opencontainers.image.title="YOURLS"
-LABEL org.opencontainers.image.description="Your Own URL Shortener"
-LABEL org.opencontainers.image.url="https://yourls.org/"
-LABEL org.opencontainers.image.documentation="https://yourls.org/"
-LABEL org.opencontainers.image.vendor="YOURLS Org"
-LABEL org.opencontainers.image.authors="YOURLS"
-LABEL org.opencontainers.image.licenses="MIT"
-LABEL io.artifacthub.package.readme-url="https://raw.githubusercontent.com/YOURLS/YOURLS/master/README.md"
+FROM php:8.3-fpm
 
 # install the PHP extensions we need
 RUN set -eux; \
@@ -29,8 +20,6 @@ RUN { \
 ARG YOURLS_VERSION="1.9.2"
 ARG YOURLS_SHA256="62a95ba766d62f3305d75944cbfe12d5a90c08c88fbf2f6e67150d36412b916f"
 
-LABEL org.opencontainers.image.version="$YOURLS_VERSION"
-
 ENV YOURLS_VERSION=$YOURLS_VERSION
 ENV YOURLS_SHA256=$YOURLS_SHA256
 
@@ -44,8 +33,8 @@ RUN set -eux; \
     rm yourls.tar.gz; \
     chown -R www-data:www-data /usr/src/yourls
 
-COPY --chown=www-data:www-data config-docker.php /usr/src/yourls/user/
-COPY docker-entrypoint.sh /usr/local/bin/
+COPY --chown=www-data:www-data config-container.php /usr/src/yourls/user/
+COPY container-entrypoint.sh /usr/local/bin/
 
-ENTRYPOINT ["docker-entrypoint.sh"]
+ENTRYPOINT ["container-entrypoint.sh"]
 CMD ["php-fpm"]
diff --git a/yourls_fpm-alpine/config-docker.php b/yourls_fpm/config-container.php
similarity index 85%
rename from yourls_fpm-alpine/config-docker.php
rename to yourls_fpm/config-container.php
index cf56824..43d4302 100644
--- a/yourls_fpm-alpine/config-docker.php
+++ b/yourls_fpm/config-container.php
@@ -4,8 +4,8 @@
  */
 
 // a helper function to lookup "env_FILE", "env", then fallback
-if (!function_exists('getenv_docker')) {
-    function getenv_docker(string $name, ?string $default = null): ?string
+if (!function_exists('getenv_container')) {
+    function getenv_container(string $name, ?string $default = null): ?string
     {
         if ($fileEnv = getenv($name . '_FILE')) {
             return trim(file_get_contents($fileEnv));
@@ -23,20 +23,20 @@ if (!function_exists('getenv_docker')) {
  */
 
 /** MySQL database username */
-define( 'YOURLS_DB_USER', getenv_docker('YOURLS_DB_USER', 'root') );
+define( 'YOURLS_DB_USER', getenv_container('YOURLS_DB_USER', 'root') );
 
 /** MySQL database password */
-define( 'YOURLS_DB_PASS', getenv_docker('YOURLS_DB_PASS') );
+define( 'YOURLS_DB_PASS', getenv_container('YOURLS_DB_PASS') );
 
 /** The name of the database for YOURLS */
-define( 'YOURLS_DB_NAME', getenv_docker('YOURLS_DB_NAME', 'yourls') );
+define( 'YOURLS_DB_NAME', getenv_container('YOURLS_DB_NAME', 'yourls') );
 
 /** 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_docker('YOURLS_DB_HOST', 'mysql') );
+define( 'YOURLS_DB_HOST', getenv_container('YOURLS_DB_HOST', 'mysql') );
 
 /** MySQL tables prefix */
-define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
+define( 'YOURLS_DB_PREFIX', getenv_container('YOURLS_DB_PREFIX', 'yourls_') );
 
 /*
  ** Site options
@@ -44,7 +44,7 @@ define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
 
 /** 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_docker('YOURLS_SITE', 'http://your-own-domain-here.com') );
+define( 'YOURLS_SITE', getenv_container('YOURLS_SITE', 'http://your-own-domain-here.com') );
 
 /** Server timezone GMT offset */
 define( 'YOURLS_HOURS_OFFSET', filter_var(getenv('YOURLS_HOURS_OFFSET'), FILTER_VALIDATE_INT) ?: 0 );
@@ -72,7 +72,7 @@ define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with
  ** YOURLS will auto encrypt plain text passwords in this file
  ** Read http://yourls.org/userpassword for more information */
 $yourls_user_passwords = [
-    getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),
+    getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),
 ];
 
 /** Debug mode to output some internal information
diff --git a/yourls_fpm/docker-entrypoint.sh b/yourls_fpm/container-entrypoint.sh
similarity index 82%
rename from yourls_fpm/docker-entrypoint.sh
rename to yourls_fpm/container-entrypoint.sh
index 8b65b17..b137360 100755
--- a/yourls_fpm/docker-entrypoint.sh
+++ b/yourls_fpm/container-entrypoint.sh
@@ -72,12 +72,12 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 	# We want to copy the initial config if the actual config file doesn't already
 	# exist OR if it is an empty file (e.g. it has been created for the volume mount).
 	if [ ! -s user/config.php ]; then
-		cp /usr/src/yourls/user/config-docker.php user/config.php
+		cp /usr/src/yourls/user/config-container.php user/config.php
 
 		: "${YOURLS_USER:=}"
 		: "${YOURLS_PASS:=}"
 		if [ -n "${YOURLS_USER}" ] && [ -n "${YOURLS_PASS}" ]; then
-			result=$(sed "s/  getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
+			result=$(sed "s/  getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
 			echo "$result" > user/config.php
 		fi
 
@@ -86,6 +86,26 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 			# could be on a filesystem that doesn't allow chown (like some NFS setups)
 			chown "$user:$group" user/config.php || true
 		fi
+
+		# ability to use custom script
+		for file in /docker-entrypoint-init.d/*; do
+			echo >&2 "Running custom script $file"
+			case "$file" in
+			*.sh)
+				if [ -x "$file" ]; then
+					"$file" || exit 1
+				else
+					echo >&2 "... ignoring non-executable $file"
+				fi
+				;;
+			*.php)
+				php -f "$file"
+				;;
+			*)
+				echo >&2 "... ignoring $file"
+				;;
+			esac
+		done
 	fi
 fi
 
diff --git a/yourls_latest/Dockerfile b/yourls_latest/Dockerfile
index ba4fafc..ef27f6e 100644
--- a/yourls_latest/Dockerfile
+++ b/yourls_latest/Dockerfile
@@ -1,13 +1,4 @@
-FROM php:8.2-apache
-
-LABEL org.opencontainers.image.title="YOURLS"
-LABEL org.opencontainers.image.description="Your Own URL Shortener"
-LABEL org.opencontainers.image.url="https://yourls.org/"
-LABEL org.opencontainers.image.documentation="https://yourls.org/"
-LABEL org.opencontainers.image.vendor="YOURLS Org"
-LABEL org.opencontainers.image.authors="YOURLS"
-LABEL org.opencontainers.image.licenses="MIT"
-LABEL io.artifacthub.package.readme-url="https://raw.githubusercontent.com/YOURLS/YOURLS/master/README.md"
+FROM php:8.3-apache
 
 # install the PHP extensions we need
 RUN set -eux; \
@@ -29,8 +20,6 @@ RUN a2enmod rewrite expires
 ARG YOURLS_VERSION="1.9.2"
 ARG YOURLS_SHA256="62a95ba766d62f3305d75944cbfe12d5a90c08c88fbf2f6e67150d36412b916f"
 
-LABEL org.opencontainers.image.version="$YOURLS_VERSION"
-
 ENV YOURLS_VERSION=$YOURLS_VERSION
 ENV YOURLS_SHA256=$YOURLS_SHA256
 
@@ -44,8 +33,8 @@ RUN set -eux; \
     rm yourls.tar.gz; \
     chown -R www-data:www-data /usr/src/yourls
 
-COPY --chown=www-data:www-data config-docker.php /usr/src/yourls/user/
-COPY docker-entrypoint.sh /usr/local/bin/
+COPY --chown=www-data:www-data config-container.php /usr/src/yourls/user/
+COPY container-entrypoint.sh /usr/local/bin/
 COPY .htaccess /usr/src/yourls/
-ENTRYPOINT ["docker-entrypoint.sh"]
+ENTRYPOINT ["container-entrypoint.sh"]
 CMD ["apache2-foreground"]
diff --git a/yourls_fpm/config-docker.php b/yourls_latest/config-container.php
similarity index 85%
rename from yourls_fpm/config-docker.php
rename to yourls_latest/config-container.php
index cf56824..43d4302 100644
--- a/yourls_fpm/config-docker.php
+++ b/yourls_latest/config-container.php
@@ -4,8 +4,8 @@
  */
 
 // a helper function to lookup "env_FILE", "env", then fallback
-if (!function_exists('getenv_docker')) {
-    function getenv_docker(string $name, ?string $default = null): ?string
+if (!function_exists('getenv_container')) {
+    function getenv_container(string $name, ?string $default = null): ?string
     {
         if ($fileEnv = getenv($name . '_FILE')) {
             return trim(file_get_contents($fileEnv));
@@ -23,20 +23,20 @@ if (!function_exists('getenv_docker')) {
  */
 
 /** MySQL database username */
-define( 'YOURLS_DB_USER', getenv_docker('YOURLS_DB_USER', 'root') );
+define( 'YOURLS_DB_USER', getenv_container('YOURLS_DB_USER', 'root') );
 
 /** MySQL database password */
-define( 'YOURLS_DB_PASS', getenv_docker('YOURLS_DB_PASS') );
+define( 'YOURLS_DB_PASS', getenv_container('YOURLS_DB_PASS') );
 
 /** The name of the database for YOURLS */
-define( 'YOURLS_DB_NAME', getenv_docker('YOURLS_DB_NAME', 'yourls') );
+define( 'YOURLS_DB_NAME', getenv_container('YOURLS_DB_NAME', 'yourls') );
 
 /** 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_docker('YOURLS_DB_HOST', 'mysql') );
+define( 'YOURLS_DB_HOST', getenv_container('YOURLS_DB_HOST', 'mysql') );
 
 /** MySQL tables prefix */
-define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
+define( 'YOURLS_DB_PREFIX', getenv_container('YOURLS_DB_PREFIX', 'yourls_') );
 
 /*
  ** Site options
@@ -44,7 +44,7 @@ define( 'YOURLS_DB_PREFIX', getenv_docker('YOURLS_DB_PREFIX', 'yourls_') );
 
 /** 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_docker('YOURLS_SITE', 'http://your-own-domain-here.com') );
+define( 'YOURLS_SITE', getenv_container('YOURLS_SITE', 'http://your-own-domain-here.com') );
 
 /** Server timezone GMT offset */
 define( 'YOURLS_HOURS_OFFSET', filter_var(getenv('YOURLS_HOURS_OFFSET'), FILTER_VALIDATE_INT) ?: 0 );
@@ -72,7 +72,7 @@ define( 'YOURLS_COOKIEKEY', getenv('YOURLS_COOKIEKEY') ?: 'modify this text with
  ** YOURLS will auto encrypt plain text passwords in this file
  ** Read http://yourls.org/userpassword for more information */
 $yourls_user_passwords = [
-    getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),
+    getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),
 ];
 
 /** Debug mode to output some internal information
diff --git a/yourls_fpm-alpine/docker-entrypoint.sh b/yourls_latest/container-entrypoint.sh
similarity index 82%
rename from yourls_fpm-alpine/docker-entrypoint.sh
rename to yourls_latest/container-entrypoint.sh
index 8b65b17..b137360 100755
--- a/yourls_fpm-alpine/docker-entrypoint.sh
+++ b/yourls_latest/container-entrypoint.sh
@@ -72,12 +72,12 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 	# We want to copy the initial config if the actual config file doesn't already
 	# exist OR if it is an empty file (e.g. it has been created for the volume mount).
 	if [ ! -s user/config.php ]; then
-		cp /usr/src/yourls/user/config-docker.php user/config.php
+		cp /usr/src/yourls/user/config-container.php user/config.php
 
 		: "${YOURLS_USER:=}"
 		: "${YOURLS_PASS:=}"
 		if [ -n "${YOURLS_USER}" ] && [ -n "${YOURLS_PASS}" ]; then
-			result=$(sed "s/  getenv_docker('YOURLS_USER') => getenv_docker('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
+			result=$(sed "s/  getenv_container('YOURLS_USER') => getenv_container('YOURLS_PASS'),/  \'${YOURLS_USER}\' => \'${YOURLS_PASS//&/\\&}\',/g" user/config.php)
 			echo "$result" > user/config.php
 		fi
 
@@ -86,6 +86,26 @@ if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
 			# could be on a filesystem that doesn't allow chown (like some NFS setups)
 			chown "$user:$group" user/config.php || true
 		fi
+
+		# ability to use custom script
+		for file in /docker-entrypoint-init.d/*; do
+			echo >&2 "Running custom script $file"
+			case "$file" in
+			*.sh)
+				if [ -x "$file" ]; then
+					"$file" || exit 1
+				else
+					echo >&2 "... ignoring non-executable $file"
+				fi
+				;;
+			*.php)
+				php -f "$file"
+				;;
+			*)
+				echo >&2 "... ignoring $file"
+				;;
+			esac
+		done
 	fi
 fi

Relevant Maintainers:

@LeoColomb
Copy link
Contributor Author

@yosifkit Content updated based on your review. Thanks again 😊

@tianon tianon merged commit 4c4f51a into docker-library:master Apr 19, 2024
8 checks passed
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.

4 participants