Skip to content

Commit 1881c60

Browse files
authored
Fixing and improving build scripts and docs (#72)
* Fixing and improving build scripts and docs * Updating composer packages * Removing composer hash check
1 parent a00e054 commit 1881c60

File tree

14 files changed

+251
-93
lines changed

14 files changed

+251
-93
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
run: |
1818
sudo apt-get update && sudo apt-get install php-cli
1919
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
20-
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
2120
php composer-setup.php
2221
php -r "unlink('composer-setup.php');"
2322
sudo mv composer.phar /usr/local/bin/composer

Dockerfile

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ FROM ubuntu:lunar
22

33
EXPOSE 80
44

5-
ENV NR_PHP_AGENT_URL 'https://download.newrelic.com/php_agent/archive/10.6.0.318/newrelic-php5-10.6.0.318-linux.tar.gz'
5+
ENV NR_PHP_AGENT_URL 'https://download.newrelic.com/php_agent/archive/10.16.0.5/newrelic-php5-10.16.0.5-linux.tar.gz'
6+
ENV GHOSTSCRIPT_URL 'https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10021/ghostscript-10.02.1.tar.gz'
67

7-
ENV INSTALL_GHOSTSCRIPT true
8+
# ENV INSTALL_GHOSTSCRIPT true
89

910
ENV WP_INSTALL_IF_NOT_FOUND true
10-
# ENV FORCE_WP_CONFIG true
11-
ENV WP_DEBUG true
12-
ENV WP_SCRIPT_DEBUG true
1311
ENV WP_MEMORY_LIMIT = '448M'
1412

1513
ENV PHP_UPLOAD_MAX_FILESIZE '256M'
@@ -18,9 +16,10 @@ ENV PHP_MEMORY_LIMIT '512M'
1816
ENV PHP_MAX_EXECUTION_TIME '240'
1917

2018
ENV PHP_ERROR_REPORTING 'E_ALL \& ~E_STRICT'
19+
ENV WP_DEBUG true
2120

2221
# ENV WP_UPLOADS_URL 'https://cdn.aldavigdis.dev'
23-
ENV WP_CONTENT_URL 'https://cdn.aldavigdis.dev'
22+
# ENV WP_CONTENT_URL 'https://cdn.aldavigdis.dev'
2423

2524
# Remove Akismet and hello.php during deployment
2625
ENV REMOVE_CRAP_PLUGINS true
@@ -31,11 +30,11 @@ ENV PREVENT_UPDATES true
3130
# Wether we should fix file permissions on deployment or not
3231
# ENV NUKE_PERMISSIONS true
3332

34-
# The "Hardening WordPress" article at https://wordpress.org/documentation/article/hardening-wordpress/
35-
# recommends 755 and 644.
36-
ENV FILE_OWNER 'root:root'
37-
ENV FILE_MODE 444
38-
ENV DIRECTORY_MODE 555
33+
ENV FILE_OWNER 'wp-services'
34+
ENV FILE_GROUP 'www-data'
35+
ENV FILE_MODE 0644
36+
ENV DIRECTORY_MODE 0644
37+
RUN useradd wp-services -r -m --shell=/bin/false --uid=699
3938

4039
ENV DEBIAN_FRONTEND=noninteractive
4140

Dockerfile.production

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM ubuntu:lunar
2+
3+
EXPOSE 80
4+
5+
ENV NR_PHP_AGENT_URL 'https://download.newrelic.com/php_agent/archive/10.9.0.324/newrelic-php5-10.9.0.324-linux.tar.gz'
6+
7+
ENV INSTALL_GHOSTSCRIPT true
8+
9+
ENV PHP_UPLOAD_MAX_FILESIZE '256M'
10+
ENV PHP_POST_MAX_SIZE '384M'
11+
ENV PHP_MEMORY_LIMIT '512M'
12+
ENV PHP_MAX_EXECUTION_TIME '240'
13+
14+
# The "Hardening WordPress" article at https://wordpress.org/documentation/article/hardening-wordpress/
15+
# recommends 755 and 644.
16+
ENV FILE_OWNER 'wp-services'
17+
ENV FILE_GROUP 'www-data'
18+
ENV FILE_MODE 0644
19+
ENV DIRECTORY_MODE 0644
20+
RUN useradd wp-services -r -m --shell=/bin/false --uid=699
21+
22+
ENV DEBIAN_FRONTEND=noninteractive
23+
24+
# Install PHP and related packages, plus locales
25+
COPY ./bin/install_packages.sh /root/install_packages.sh
26+
RUN bash /root/install_packages.sh
27+
ENV LANG en_US.utf8
28+
29+
# Install Ghostscript
30+
COPY ./bin/install_ghostscript.sh /root/install_ghostscript.sh
31+
RUN if [ $INSTALL_GHOSTSCRIPT ]; then bash /root/install_ghostscript.sh; fi
32+
33+
# Copy over our nginx site config
34+
COPY ./nginx_config/default_site /etc/nginx/sites-enabled/default
35+
36+
# Run further nginx configurations
37+
COPY bin/configure_nginx.sh /root/configure_nginx.sh
38+
RUN /root/configure_nginx.sh
39+
40+
WORKDIR /var/www/html
41+
42+
COPY mu-plugins/ /root/mu-plugins/
43+
44+
COPY bin/* /root/
45+
46+
ENTRYPOINT /root/entrypoint.sh

bin/configure_nginx.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3-
sed -i -e "s/access_log \/var\/log\/nginx\/access.log;/access_log \/dev\/stdout;/" /etc/nginx/nginx.conf
4-
sed -i -e "s/error_log \/var\/log\/nginx\/error.log;/error_log \/dev\/stderr;/" /etc/nginx/nginx.conf
3+
# sed -i -e "s/access_log \/var\/log\/nginx\/access.log;/access_log \/dev\/stdout;/" /etc/nginx/nginx.conf
4+
# sed -i -e "s/error_log \/var\/log\/nginx\/error.log;/error_log \/dev\/stderr;/" /etc/nginx/nginx.conf
55

66
if [ $PHP_MAX_EXECUTION_TIME ]
77
then
88
sed -i -e "s/fastcgi_read_timeout 30;/fastcgi_read_timeout ${PHP_MAX_EXECUTION_TIME};/" /etc/nginx/sites-enabled/default
99
sed -i -e "s/fastcgi_send_timeout 30;/fastcgi_send_timeout ${PHP_MAX_EXECUTION_TIME};/" /etc/nginx/sites-enabled/default
10-
fi
10+
fi

bin/configure_wordpress.sh

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ then
4949
wp config set DISALLOW_FILE_EDIT true --raw --allow-root
5050
wp config set WP_AUTO_UPDATE_CORE false --raw --allow-root
5151

52-
if [ $WP_DEBUG ]
52+
if [ "$WP_DEBUG" ]
5353
then
5454
wp config set WP_DEBUG true --raw --allow-root
5555
wp config set WP_DEBUG_DISPLAY false --raw --allow-root
5656
fi
5757

58-
if [ $WP_SCRIPT_DEBUG ]
58+
if [ "$WP_SCRIPT_DEBUG" ]
5959
then
6060
wp config set SCRIPT_DEBUG false --raw --allow-root
6161
fi
6262

63-
if [ -v $WP_MEMORY_LIMIT ]
63+
if [ "$WP_MEMORY_LIMIT" ]
6464
then
6565
wp config set WP_MEMORY_LIMIT "$WP_MEMORY_LIMIT" --allow-root
6666
wp config set WP_MAX_MEMORY_LIMIT "$WP_MEMORY_LIMIT" --allow-root
@@ -69,54 +69,62 @@ then
6969
wp config set WP_MAX_MEMORY_LIMIT "ini_get( 'memory_limit' )" --raw --allow-root
7070
fi
7171

72-
if [ $DISABLE_WP_CRON ]
72+
if [ "$DISABLE_WP_CRON" ]
7373
then
7474
wp config set DISABLE_WP_CRON true --allow-root
7575
fi
7676

77-
if [ $WP_UPLOADS_URL ]
77+
if [ "$WP_UPLOADS_URL" ]
7878
then
7979
wp config set UPLOADS_URL "$WP_UPLOADS_URL" --allow-root
8080
fi
8181

8282
# Enable Memcached object storage
83-
export MEMCACHED_HOST=$(jq -r '.memcached_servers[0]' /secrets/credentials.json)
84-
if [ $MEMCACHED_HOST ]
83+
memcached_host=$(jq -r '.memcached_servers[0]' /secrets/credentials.json)
84+
if [ "$memcached_host" ]
8585
then
8686
sed -i "/Add any custom values between this line/a \$memcached_servers = array( 'default' => \$credentials->memcached_servers );" wp-config.php
8787
curl -s https://plugins.trac.wordpress.org/export/HEAD/memcached/trunk/object-cache.php > ./wp-content/object-cache.php
88-
chmod $FILE_MODE ./wp-content/object-cache.php
89-
chown $FILE_OWNER ./wp-content/object-cache.php
88+
if [ "$FILE_MODE" ]
89+
then
90+
chmod "$FILE_MODE" ./wp-content/object-cache.php
91+
fi
92+
if [ "$FILE_OWNER" ]
93+
then
94+
chown "$FILE_OWNER" ./wp-content/object-cache.php
95+
fi
9096
fi
9197

92-
if [ $WP_CONTENT_URL ]
98+
if [ "$WP_CONTENT_URL" ]
9399
then
94100
wp config set WP_CONTENT_URL "$WP_CONTENT_URL" --allow-root
95101
fi
102+
fi
96103

97-
if [ $WP_THEME_INSTALL ]
98-
then
99-
wp theme install "$WP_THEME_INSTALL" --allow-root
100-
fi
104+
wp core install --url="localhost" --title="DockPress Site" --admin_user="admin" --admin_password="password" --admin_email="[email protected]" --skip-email --allow-root
101105

102-
if [ $WP_THEME_ACTIVATE ]
103-
then
104-
wp theme activate "$WP_THEME_ACTIVATE" --allow-root
105-
fi
106+
if [ "$WP_THEME_INSTALL" ]
107+
then
108+
wp theme install "$WP_THEME_INSTALL" --allow-root
109+
fi
106110

107-
if [ $WP_PLUGIN_INSTALL ]
108-
then
109-
wp plugin install "$WP_PLUGIN_INSTALL" --allow-root
110-
fi
111+
if [ "$WP_THEME_ACTIVATE" ]
112+
then
113+
wp theme activate "$WP_THEME_ACTIVATE" --allow-root
114+
fi
111115

112-
if [ $WP_PLUGIN_ACTIVATE ]
113-
then
114-
wp plugin activate "$WP_PLUGIN_ACTIVATE" --allow-root
115-
fi
116+
if [ "$WP_PLUGIN_INSTALL" ]
117+
then
118+
wp plugin install "$WP_PLUGIN_INSTALL" --allow-root
119+
fi
120+
121+
if [ "$WP_PLUGIN_ACTIVATE" ]
122+
then
123+
wp plugin activate "$WP_PLUGIN_ACTIVATE" --allow-root
116124
fi
117125

118126
# Remove crapware plugins from the WordPress installation
119-
if [ $REMOVE_CRAP_PLUGINS ]
127+
if [ "$REMOVE_CRAP_PLUGINS" ]
120128
then
121129
rm -rf wp-content/plugins/akismet/
122130
rm -rf wp-content/plugins/hello.php
@@ -126,5 +134,4 @@ if [ ! -d wp-content/uploads ]
126134
then
127135
echo "📁 Creating uploads directory"
128136
mkdir wp-content/uploads
129-
chmod a+rw wp-content/uploads
130137
fi

bin/install_new_relic.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3-
export NR_KEY=$(jq -r '.new_relic_key' /secrets/credentials.json)
4-
export NR_APP_NAME=$(jq -r '.new_relic_app_name' /secrets/credentials.json)
3+
nr_key=$(jq -r '.new_relic_key' /secrets/credentials.json)
4+
nr_app_name=$(jq -r '.new_relic_app_name' /secrets/credentials.json)
55

66
# The installation will not happen unless the credentials and ENV variables are set
7-
if [ $NR_KEY ] && [ "${NR_APP_NAME}" ] && [ $NR_PHP_AGENT_URL ]
7+
if [ "$nr_key" ] && [ "${NR_APP_NAME}" ] && [ "$NR_PHP_AGENT_URL" ]
88
then
99
curl -s -L ${NR_PHP_AGENT_URL} | tar -C /tmp -zx
1010

@@ -15,9 +15,9 @@ then
1515

1616
rm -rf /tmp/newrelic-php5-* /tmp/nrinstall*
1717

18-
sed -i -e "s/\"REPLACE_WITH_REAL_KEY\"/\"${NR_KEY}\"/" \
18+
sed -i -e "s/\"REPLACE_WITH_REAL_KEY\"/\"${nr_key}\"/" \
1919
-e "s/;newrelic.framework = \"\"/newrelic.framework = \"wordpress\"/" \
20-
-e "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"${NR_APP_NAME}\"/" \
20+
-e "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"${nr_app_name}\"/" \
2121
-e 's/;newrelic.daemon.app_connect_timeout =.*/newrelic.daemon.app_connect_timeout=15s/' \
2222
-e 's/;newrelic.daemon.start_timeout =.*/newrelic.daemon.start_timeout=5s/' \
2323
/etc/php/8.1/fpm/conf.d/newrelic.ini

bin/install_packages.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ apt-get install nginx php8.1-fpm php8.1 \
66
php8.1-mysql php8.1-curl php8.1-memcached php8.1-memcache \
77
php8.1-zip php8.1-xml php8.1-mbstring php8.1-imagick \
88
php8.1-redis php8.1-bc php8.1-intl php8.1-ssh2 \
9-
mariadb-client curl locales jq less python3-pip -y
9+
mariadb-client curl locales jq less vim -y
1010

1111
rm -rf /var/lib/apt/lists/*
1212
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
1313

1414
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp
15-
16-
# Update Python packages with known security vulnerabilities
17-
python3 -m pip install cryptography --break-system-packages --upgrade

bin/nuke_permissions.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#!/bin/bash
22

3-
chown -R $FILE_OWNER .
4-
find . -type f -not -path "./.git/*" -not -path "./wp-content/uploads/*" -exec chmod $DIRECTORY_MODE {} \;
5-
find . -type f -not -path "./.git/*" -not -path "./wp-content/uploads/*" -exec chmod $FILE_MODE {} \;
3+
if [ "$FILE_OWNER" ]
4+
then
5+
if [ ! "$FILE_GROUP" ]
6+
then
7+
FILE_GROUP=$FILE_OWNER
8+
fi
9+
chown -R "$FILE_OWNER:$FILE_GROUP" .
10+
fi
11+
12+
if [ "$DIRECTORY_MODE" ]
13+
then
14+
find . -type d -not -path "./.git/*" -not -path "./wp-content/uploads/*" -exec chmod "$DIRECTORY_MODE" {} \;
15+
fi
16+
17+
if [ "$FILE_MODE" ]
18+
then
19+
find . -type f -not -path "./.git/*" -not -path "./wp-content/uploads/*" -exec chmod "$FILE_MODE" {} \;
20+
fi

compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
dockpress:
3+
image: dockpress
4+
volumes:
5+
- ./secrets:/secrets
6+
ports:
7+
- 80:80
8+
mariadb:
9+
image: mariadb
10+
restart: always
11+
ports:
12+
- 3306:3306
13+
environment:
14+
- MARIADB_DATABASE=wordpress
15+
- MARIADB_USER=wordpress
16+
- MARIADB_PASSWORD=password
17+
- MARIADB_ROOT_PASSWORD=password
18+
memcached:
19+
image: memcached
20+
ports:
21+
- 11211:11211

0 commit comments

Comments
 (0)