Skip to content

Commit fcf2fcd

Browse files
authored
Build docker on release (#836)
* test docker build action * fix typo * add simple Dockerfile * check location to find out why it can't find the dockerfile * add checkout step * typo * add the correct Dockerfile * add files for building container and action it on a release tag * fix path * pass version into the Docker build * don't cache * typo * build the docker image * don't fire on every push * verify the files are there * check path * diagnose * fetch the release from s3 for building * add bucket as a param * clean up a little * add build workflow for dev * show command * limit scope * increase verbosity * install s3cmd with pip * use vars for bucket * show key used (will rotate) * split build args into multiple lines * format build-args correctly * remove debug output * rename dockerfile to .release * trigger dev on testing tags * build without fetching from S3 * update paths * update * use phplist3 path * fix path * keep it relative * and again * once more * try artifacts * typo * other typo * use env * use file context * use Path Context * copy files in place * fake version and avoid firing all * update * set config and enable site * typo * add note about initialise * update phplint * typo * set Docker user to be www-data * remove SF upload and add Docker build * update test version * debug * copy file for Docker build * remove user restriction (for now) * add upload to SF * install rsync if necessary * make each test build different * upload as artifact * add verbosity * typo * mark unstable as RC to put it in the development folder * tidy up * tweak security and redirect logs to docker output * add vars for repo and image
1 parent 2a50fc6 commit fcf2fcd

File tree

10 files changed

+210
-9
lines changed

10 files changed

+210
-9
lines changed

.github/workflows/build-release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ jobs:
198198
sha256sum phplist-${RELEASE_VERSION}.* > phplist-${RELEASE_VERSION}.sha256
199199
sha1sum phplist-${RELEASE_VERSION}.* > phplist-${RELEASE_VERSION}.sha1
200200
ls -l
201+
## move the files for use in Docker build
201202
mv phplist-$RELEASE_VERSION phplist3
202203
cd $GITHUB_WORKSPACE
204+
cp ../phplist-${RELEASE_VERSION}.tgz .
203205
204206
- name: Set up S3cmd cli tool
205207
uses: s3-actions/[email protected]
@@ -215,6 +217,14 @@ jobs:
215217
s3cmd put phplist-${RELEASE_VERSION}.* s3://${{ secrets.AWS_S3_VERSIONS_BUCKET }}/
216218
s3cmd put phplist3/public_html/lists/admin/images/power-phplist.png s3://${{ secrets.AWS_S3_POWERED_BUCKET }}/images/${RELEASE_VERSION}/
217219
220+
- name: Upload the package as artifact
221+
if: always()
222+
uses: actions/upload-artifact@v2
223+
with:
224+
path: "phplist-*.tgz"
225+
name: "phpList Release File"
226+
retention-days: 3
227+
218228
- name: Upload the files to SF
219229
run: |
220230
export SSHPASS=${{ secrets.SF_PASS }}
@@ -236,3 +246,23 @@ jobs:
236246
bye
237247
EOF
238248
249+
- name: Set up Docker Buildx
250+
uses: docker/setup-buildx-action@v1
251+
252+
- name: Login to DockerHub
253+
uses: docker/login-action@v1
254+
with:
255+
username: ${{ secrets.DOCKERHUB_USERNAME }}
256+
password: ${{ secrets.DOCKERHUB_TOKEN }}
257+
258+
- name: Build and push
259+
id: docker_build
260+
uses: docker/build-push-action@v2
261+
with:
262+
context: .
263+
push: true
264+
no-cache: true
265+
file: Dockerfile.release
266+
tags: ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMAGE }}:${{ env.RELEASE_VERSION }}
267+
build-args: |
268+
VERSION=${{ env.RELEASE_VERSION }}

Dockerfile.release

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ LABEL maintainer="[email protected]"
66
RUN apt-get update && apt-get upgrade -y
77

88
RUN apt-get install -y apt-utils \
9-
vim apache2 net-tools php-mysql \
9+
apache2 php-mysql \
1010
libapache2-mod-php php-curl php-gd \
11-
git cron php-imap php-xml php-zip php-mbstring
11+
cron php-imap php-xml php-zip php-mbstring
1212

1313
RUN useradd -d /var/www/phpList3 phplist
1414

@@ -19,18 +19,23 @@ RUN rm -rf /var/www/phpList3 && mkdir -p /var/www/phpList3
1919
RUN rm -rf /etc/phplist && mkdir /etc/phplist
2020

2121
COPY docker/docker-apache-phplist.conf /etc/apache2/sites-available
22+
COPY docker/security.conf /etc/apache2/conf-available
2223
COPY docker/docker-entrypoint.sh /usr/local/bin/
2324
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
2425
RUN a2ensite docker-apache-phplist
2526
RUN a2enmod rewrite
27+
RUN a2enmod headers
28+
RUN a2disconf other-vhosts-access-log
29+
RUN sed -i s/LogLevel.*/LogLevel\ warn/ /etc/apache2/apache2.conf
2630

2731
COPY docker/phplist-crontab /etc/cron.d/
2832
COPY docker/docker-phplist-config-live.php /etc/phplist/config.php
2933

3034
COPY phplist-${VERSION}.tgz ./
3135

32-
RUN tar zvxf phplist-$VERSION.tgz
36+
RUN tar zxf phplist-$VERSION.tgz
3337
RUN mv phplist-$VERSION/* /var/www/phpList3/
38+
RUN rm -rf /phplist-$VERSION*
3439

3540
RUN rm -f /etc/apache2/sites-enabled/000-default.conf && \
3641
cd /var/www/ && find . -type d -name .git -print0 | xargs -0 rm -rf && \
@@ -41,5 +46,4 @@ RUN chown -R www-data: /var/www/phpList3
4146

4247
EXPOSE 80
4348

44-
VOLUME ["/var/www", "/var/log/apache2"]
4549
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

docker/docker-apache-phplist.conf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ ServerName phplist.docker
66
DirectoryIndex index.php
77
php_value upload_max_filesize 50M
88
php_value post_max_size 100M
9-
LogLevel core:info
10-
11-
ErrorLog ${APACHE_LOG_DIR}/phplist_error.log
12-
CustomLog ${APACHE_LOG_DIR}/phplist_access.log vhost_combined
139

1410
<Directory /var/www/phpList3>
1511
AllowOverride All
12+
Options -Indexes
1613
</Directory>
14+
15+
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
16+
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
17+
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
18+
CustomLog /proc/self/fd/1 combined env=!forwarded
19+
CustomLog /proc/self/fd/1 proxy env=forwarded
20+
ErrorLog /proc/self/fd/1
1721
</VirtualHost>

docker/docker-entrypoint.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
## entry point file, needed to be able to pass ENV vars from docker-compose.yml to the containers.
4+
5+
echo Initialising phpList, Please wait
6+
7+
exec 6>&1
8+
exec > /usr/bin/phplist
9+
10+
echo '#!/bin/bash'
11+
echo -n
12+
echo 'exec 6>&1'
13+
echo 'exec > /dev/null 2>&1'
14+
printenv | sed 's/^\(.*\)$/export \1/g'
15+
echo -n
16+
echo 'exec 1>&6 6>&-'
17+
echo /usr/bin/php /var/www/phpList3/public_html/lists/admin/index.php -c /etc/phplist/config.php \$\*
18+
19+
exec 1>&6 6>&-
20+
chmod 755 /usr/bin/phplist
21+
22+
## wait for the DB container, but not forever
23+
UNCONNECTED=$(phplist | grep "Cannot connect")
24+
COUNT=1
25+
while [[ "$UNCONNECTED" ]] && [[ $COUNT -lt 11 ]] ; do
26+
echo Waiting for the Database to be available - $COUNT/10
27+
sleep 10;
28+
UNCONNECTED=$(phplist | grep "Cannot connect")
29+
COUNT=$(( $COUNT + 1 ))
30+
done
31+
32+
if [[ "$UNCONNECTED" ]]; then
33+
echo Failed to find a Database to connect to
34+
exit;
35+
fi
36+
37+
/usr/bin/phplist -pinitialise ## https://github.com/phpList/phplist3/issues/718 - @TODO make this work
38+
/usr/bin/phplist -pinitlanguages
39+
40+
service cron start
41+
echo $(phplist --version) READY
42+
/usr/sbin/apache2ctl -D FOREGROUND
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
$database_host = getenv('DB_HOST');
4+
$database_name = getenv('DB_NAME');
5+
$database_user = getenv('DB_USER');
6+
$database_password = getenv('DB_PASSWORD');
7+
$mailhost = getenv('MAILHOST');
8+
define('PHPMAILERHOST', $mailhost);
9+
define('PHPMAILERPORT', 1025);
10+
define('TEST', 0);
11+
define('HASH_ALGO', 'sha256');
12+
define('UPLOADIMAGES_DIR','images');
13+
define ("MANUALLY_PROCESS_BOUNCES",0);
14+
define ("MANUALLY_PROCESS_QUEUE",0);
15+
define('CHECK_REFERRER',false);
16+
#define('VERBOSE', 1);
17+
#define('PHPMAILER_SMTP_DEBUG', 1);
18+
define('PHPMAILER_SECURE',0);
19+
define('DEVVERSION',true);
20+
21+
$developer_email = '[email protected]';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$database_host = getenv('DB_HOST');
4+
$database_name = getenv('DB_NAME');
5+
$database_user = getenv('DB_USER');
6+
$database_password = getenv('DB_PASSWORD');
7+
$mailhost = getenv('MAILHOST');
8+
define('PHPMAILERHOST', $mailhost);
9+
define('TEST', 0);
10+
define('HASH_ALGO', 'sha256');
11+
define('UPLOADIMAGES_DIR','images');
12+
define ('MANUALLY_PROCESS_BOUNCES',1);
13+
define ('MANUALLY_PROCESS_QUEUE',0);
14+
define('PHPMAILER_SECURE',0);
15+
define('CHECK_REFERRER',false);

docker/phplist-crontab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*/1 * * * * phplist -pprocessqueue >> /var/log/phplist.log 2>&1
2+
0 3 * * * phplist -pprocessbounces >> /var/log/phplist-bounces.log 2>&1

docker/security.conf

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Disable access to the entire file system except for the directories that
3+
# are explicitly allowed later.
4+
#
5+
# This currently breaks the configurations that come with some web application
6+
# Debian packages.
7+
#
8+
#<Directory />
9+
# AllowOverride None
10+
# Require all denied
11+
#</Directory>
12+
13+
14+
# Changing the following options will not really affect the security of the
15+
# server, but might make attacks slightly more difficult in some cases.
16+
17+
#
18+
# ServerTokens
19+
# This directive configures what you return as the Server HTTP response
20+
# Header. The default is 'Full' which sends information about the OS-Type
21+
# and compiled in modules.
22+
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
23+
# where Full conveys the most information, and Prod the least.
24+
ServerTokens Minimal
25+
#ServerTokens OS
26+
#ServerTokens Full
27+
28+
#
29+
# Optionally add a line containing the server version and virtual host
30+
# name to server-generated pages (internal error documents, FTP directory
31+
# listings, mod_status and mod_info output etc., but not CGI generated
32+
# documents or custom error documents).
33+
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
34+
# Set to one of: On | Off | EMail
35+
ServerSignature Off
36+
#ServerSignature On
37+
38+
#
39+
# Allow TRACE method
40+
#
41+
# Set to "extended" to also reflect the request body (only for testing and
42+
# diagnostic purposes).
43+
#
44+
# Set to one of: On | Off | extended
45+
TraceEnable Off
46+
#TraceEnable On
47+
48+
#
49+
# Forbid access to version control directories
50+
#
51+
# If you use version control systems in your document root, you should
52+
# probably deny access to their directories. For example, for subversion:
53+
#
54+
#<DirectoryMatch "/\.svn">
55+
# Require all denied
56+
#</DirectoryMatch>
57+
58+
#
59+
# Setting this header will prevent MSIE from interpreting files as something
60+
# else than declared by the content type in the HTTP headers.
61+
# Requires mod_headers to be enabled.
62+
#
63+
Header set X-Content-Type-Options: "nosniff"
64+
65+
#
66+
# Setting this header will prevent other sites from embedding pages from this
67+
# site as frames. This defends against clickjacking attacks.
68+
# Requires mod_headers to be enabled.
69+
#
70+
Header set X-Frame-Options: "sameorigin"
71+
Header set X-XSS-Protection "1; mode=block"
72+
73+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

scripts/install-plugins.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ to=$2
77

88
echo $from $to
99

10+
[[ -x $(which rsync) ]] || {
11+
apt install -y rsync
12+
}
13+
1014
for plugin in $(find $from -type d -name phplist-plugin-*); do
11-
[[ ! -z "$(ls -A $plugin/plugins/)" ]] && rsync -a $plugin/plugins/* $to
15+
[[ ! -z "$(ls -A $plugin/plugins/)" ]] && {
16+
echo installing plugin $plugin
17+
rsync -a $plugin/plugins/* $to
18+
}
1219
done

scripts/install-themes.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ to=$2
77

88
echo $from $to
99

10+
[[ -x $(which rsync) ]] || {
11+
apt install -y rsync
12+
}
1013
for theme in $(ls -d $from/*/phplist-ui-*); do
1114
[[ ! -z "$(ls -A $theme)" ]] && {
1215
echo installing $theme

0 commit comments

Comments
 (0)