Skip to content

Commit 804d2d4

Browse files
authored
Make sure the wp-secrets.php file is generated once and persisted (#50)
1 parent 17f4b0c commit 804d2d4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ RUN curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh
7575
COPY wp-config.php /usr/src/wordpress
7676
RUN chown nobody.nobody /usr/src/wordpress/wp-config.php && chmod 640 /usr/src/wordpress/wp-config.php
7777

78-
# Append WP secrets
79-
COPY wp-secrets.php /usr/src/wordpress
80-
RUN chown nobody.nobody /usr/src/wordpress/wp-secrets.php && chmod 640 /usr/src/wordpress/wp-secrets.php
78+
# Link wp-secrets to location on wp-content
79+
RUN ln -s /var/www/wp-content/wp-secrets.php /usr/src/wordpress/wp-secrets.php
8180

8281
# Entrypoint to copy wp-content
8382
COPY entrypoint.sh /entrypoint.sh

entrypoint.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@ if [ ! "$(ls -A "/var/www/wp-content" 2>/dev/null)" ]; then
99
# Copy wp-content from Wordpress src to volume
1010
cp -r /usr/src/wordpress/wp-content /var/www/
1111
chown -R nobody.nobody /var/www
12-
13-
# Generate secrets
14-
curl -f https://api.wordpress.org/secret-key/1.1/salt/ >> /usr/src/wordpress/wp-secrets.php
12+
fi
13+
# Check if wp-secrets.php exists
14+
if ! [ -f "/var/www/wp-content/wp-secrets.php" ]; then
15+
# Check that secrets environment variables are not set
16+
if [ ! $AUTH_KEY ] \
17+
&& [ ! $SECURE_AUTH_KEY ] \
18+
&& [ ! $LOGGED_IN_KEY ] \
19+
&& [ ! $NONCE_KEY ] \
20+
&& [ ! $AUTH_SALT ] \
21+
&& [ ! $SECURE_AUTH_SALT ] \
22+
&& [ ! $LOGGED_IN_SALT ] \
23+
&& [ ! $NONCE_SALT ]; then
24+
echo "Generating wp-secrets.php"
25+
# Generate secrets
26+
echo '<?php' > /var/www/wp-content/wp-secrets.php
27+
curl -f https://api.wordpress.org/secret-key/1.1/salt/ >> /var/www/wp-content/wp-secrets.php
28+
fi
1529
fi
1630
exec "$@"

wp-secrets.php

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)