add: wordpress stack
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Maximum number of attempts (can be overridden via MAX_TRIES env var)
|
||||
MAX_TRIES="${MAX_TRIES:-10}"
|
||||
# Interval in seconds between attempts (can be overridden via INTERVAL env var)
|
||||
INTERVAL="${INTERVAL:-5}"
|
||||
|
||||
try=0
|
||||
|
||||
echo "debug: $0";
|
||||
|
||||
while [ "$try" -lt "$MAX_TRIES" ]; do
|
||||
try=$((try + 1))
|
||||
echo "trying to reach mysql server (${WORDPRESS_DB_HOST:-${DB_HOST}}:${WORDPRESS_DB_PORT:-${DB_PORT:-3306}}) ${try}/${MAX_TRIES}...";
|
||||
|
||||
# Test MySQL server readiness using PHP (no mysql client or WP install required)
|
||||
if php -r '
|
||||
error_reporting(0);
|
||||
$host = getenv("WORDPRESS_DB_HOST") ?: getenv("DB_HOST") ?: "mysql";
|
||||
$user = getenv("WORDPRESS_DB_USER") ?: getenv("DB_USER") ?: "root";
|
||||
$pass = getenv("WORDPRESS_DB_PASSWORD") ?: getenv("DB_PASSWORD") ?: "";
|
||||
$port = getenv("WORDPRESS_DB_PORT") ?: getenv("DB_PORT") ?: 3306;
|
||||
|
||||
$mysqli = @new mysqli($host, $user, $pass, "", (int) $port);
|
||||
|
||||
if ($mysqli && !$mysqli->connect_errno) {
|
||||
exit(0); // connection OK
|
||||
}
|
||||
exit(1); // connection failed
|
||||
'; then
|
||||
#echo "MySQL is ready, continuing..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sleep "$INTERVAL"
|
||||
done
|
||||
|
||||
DURATION=$((MAX_TRIES * INTERVAL))
|
||||
echo "MySQL was not ready after ${DURATION}s" >&2
|
||||
exit 1
|
||||
@@ -0,0 +1,65 @@
|
||||
# Instals msmtp if a SMTP_HOST var was configured
|
||||
if test -n "${SMTP_HOST}"; then
|
||||
|
||||
apk add --no-cache msmtp;
|
||||
|
||||
if test -z "${SMTP_PORT:-}"; then
|
||||
if test "${SMTP_TLS:-on}" = "off"; then
|
||||
SMTP_PORT=25;
|
||||
elif test "${SMTP_TLS:-on}" = "starttls"; then
|
||||
SMTP_PORT=587;
|
||||
else
|
||||
SMTP_PORT=465;
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "**** SMTP_AUTH=${SMTP_AUTH:-<empty>}";
|
||||
|
||||
if test "${SMTP_AUTH:-on}" = "off"; then
|
||||
SMTP_TLS="off";
|
||||
fi
|
||||
|
||||
cat > /etc/msmtprc <<HEREDOC
|
||||
# Configuração de produção
|
||||
defaults
|
||||
auth ${SMTP_AUTH:-on}
|
||||
tls ${SMTP_TLS:-on}
|
||||
syslog on
|
||||
|
||||
account default
|
||||
host ${SMTP_HOST}
|
||||
port ${SMTP_PORT}
|
||||
from ${SMTP_FROM:-${WORDPRESS_ADMIN_EMAIL}}
|
||||
HEREDOC
|
||||
|
||||
if test -n "${SMTP_AUTH}"; then
|
||||
echo "user ${SMTP_AUTH}" >> /etc/msmtprc;
|
||||
fi
|
||||
|
||||
if test -n "${SMTP_USER}"; then
|
||||
echo "user ${SMTP_USER}" >> /etc/msmtprc;
|
||||
fi
|
||||
|
||||
if test -n "${SMTP_PASSWORD}"; then
|
||||
echo password ${SMTP_PASSWORD} >> /etc/msmtprc;
|
||||
fi
|
||||
|
||||
cat > /usr/local/etc/php/conf.d/99-mail.ini <<HEREDOC
|
||||
sendmail_path = "/usr/bin/msmtp -t"
|
||||
mail.add_x_header = On
|
||||
HEREDOC
|
||||
echo "smtp is set to ${SMTP_HOST}.";
|
||||
|
||||
echo "=== DEBUG ===";
|
||||
echo;
|
||||
echo /etc/msmtprc
|
||||
cat /etc/msmtprc;
|
||||
echo;
|
||||
echo /usr/local/etc/php/conf.d/99-mail.ini;
|
||||
cat /usr/local/etc/php/conf.d/99-mail.ini;
|
||||
echo;
|
||||
echo "=== DEBUG ==="
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo "using default php mail solution";
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REQUIRED_VARS="WORDPRESS_SITEURL WORDPRESS_BLOGNAME WORDPRESS_ADMIN_USER WORDPRESS_ADMIN_EMAIL";
|
||||
DEFAULT_THEME="twentytwentyfive"
|
||||
|
||||
|
||||
for varname in ${REQUIRED_VARS}; do
|
||||
value="$(export -p | grep $varname | cut -d '=' -f 2 | xargs)"
|
||||
if test -z "${value}"; then
|
||||
>&2 echo "FAILED: \$${varname} variable must be defined to proceed" && exit 2;
|
||||
fi
|
||||
done;
|
||||
|
||||
pwd
|
||||
|
||||
if which wp && ! wp core is-installed; then
|
||||
echo "Installing WordPress via WP-CLI..."
|
||||
wp core install --url="$WORDPRESS_SITEURL" \
|
||||
--title="$WORDPRESS_BLOGNAME" \
|
||||
--admin_user="$WORDPRESS_ADMIN_USER" \
|
||||
--admin_email="$WORDPRESS_ADMIN_EMAIL" \
|
||||
--skip-email || exit 1
|
||||
echo "WordPress installed successfully"
|
||||
fi
|
||||
|
||||
if test "$(wp theme list --format=count)" = "0"; then
|
||||
wp theme install twentytwentyfive --force --activate;
|
||||
fi
|
||||
Reference in New Issue
Block a user