Skip to content

Commit 9aa62b5

Browse files
authored
Merge pull request #120 from simplerisk/simplerisk-minimal-updates
Preparing for release + bug fix
2 parents b30df60 + ec4157c commit 9aa62b5

6 files changed

Lines changed: 129 additions & 55 deletions

File tree

simplerisk-minimal/Dockerfile

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Dockerfile generated by script
2-
ARG php_version=8.3
2+
ARG php_version=8.4
33

44
FROM alpine/curl:8.12.1 AS downloader
55

@@ -18,26 +18,27 @@ WORKDIR /var/www
1818

1919
SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
2020

21-
# Creating keyring env and installing apt dependencies
22-
RUN mkdir -p /etc/apt/keyrings && \
23-
apt-get update && \
24-
apt-get install -y --no-install-recommends gnupg2 wget lsb-release && \
25-
wget -qO - https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 | gpg --dearmor -o /etc/apt/keyrings/mysql.gpg && \
26-
# FIXME: use $(lsb_release -cs) when trixie becomes available on MySQL repos
27-
echo "deb [signed-by=/etc/apt/keyrings/mysql.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-8.0" | tee /etc/apt/sources.list.d/mysql.list && \
28-
apt-get update && \
29-
apt-get -y install --no-install-recommends libldap2-dev \
30-
libicu-dev \
31-
libcap2-bin \
32-
libcurl4-gnutls-dev \
33-
libpng-dev \
34-
libzip-dev \
35-
supervisor \
36-
cron \
37-
ca-certificates \
38-
mysql-community-client && \
39-
apt-get -y remove gnupg2 wget lsb-release && \
21+
# Install required packages, including MySQL client from Debian repos
22+
RUN apt-get update && \
23+
apt-get install -y --no-install-recommends \
24+
libldap2-dev \
25+
libicu-dev \
26+
libcap2-bin \
27+
libcurl4-gnutls-dev \
28+
libpng-dev \
29+
libzip-dev \
30+
supervisor \
31+
cron \
32+
ca-certificates \
33+
rsyslog \
34+
logrotate \
35+
curl \
36+
# This will install mariadb-client
37+
default-mysql-client && \
38+
apt-get -y autoremove && \
39+
apt-get -y purge && \
4040
rm -rf /var/lib/apt/lists/*
41+
4142
# Configure all PHP extensions
4243
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && \
4344
docker-php-ext-install ldap \
@@ -47,13 +48,17 @@ RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && \
4748
zip \
4849
gd \
4950
intl
51+
5052
# Setting up setcap for port mapping without root and removing packages
5153
RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/apache2 && \
5254
chmod gu+s /usr/sbin/cron && \
5355
apt-get -y remove libcap2-bin && \
5456
apt-get -y autoremove && \
5557
apt-get -y purge
5658

59+
RUN echo "0 0 * * * root /usr/sbin/logrotate /etc/logrotate.d/simplerisk.conf > /dev/null 2>&1" >> /etc/cron.d/logrotate-cron && \
60+
chmod 0644 /etc/cron.d/logrotate-cron
61+
5762
# Copying all files
5863
COPY common/ /
5964
COPY --from=downloader /var/www/simplerisk /var/www/simplerisk
@@ -88,12 +93,15 @@ RUN echo 'upload_max_filesize = 5M' >> /usr/local/etc/php/conf.d/docker-php-uplo
8893
# Cleanup /var/www/, creating Simplerisk user on www-data group and setting up ownerships
8994
RUN rm -rf /var/www/html && \
9095
useradd -G www-data simplerisk && \
91-
chown -R simplerisk:www-data /var/www/simplerisk /etc/apache2 /var/run/ /var/log/apache2 && \
92-
chmod -R 770 /var/www/simplerisk /etc/apache2 /var/run/ /var/log/apache2 && \
93-
chmod 755 /entrypoint.sh /etc/apache2/foreground.sh
96+
mkdir -p /var/log/simplerisk && \
97+
mkdir -p /var/log/supervisor && \
98+
mkdir -p /var/run/supervisor && \
99+
chmod -R 700 /etc/apache2 /var/log/simplerisk /var/run/ /var/www/simplerisk && \
100+
chmod 755 /entrypoint.sh /etc/apache2/foreground.sh && \
101+
chown -R simplerisk:www-data /etc/apache2 /var/log/apache2 /var/log/simplerisk /var/log/supervisor /var/run/ /var/www/simplerisk
94102

95103
# Data to save
96-
VOLUME [ "/var/log/apache2", "/etc/apache2/ssl", "/var/www/simplerisk" ]
104+
VOLUME [ "/var/log", "/etc/apache2/ssl", "/var/www/simplerisk" ]
97105

98106
# Using simplerisk user from here
99107
USER simplerisk
@@ -109,4 +117,4 @@ HEALTHCHECK --interval=1m \
109117
CMD curl --fail http://localhost || exit 1
110118

111119
# Start Apache
112-
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
120+
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]

simplerisk-minimal/common/entrypoint.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ delete_db(){
108108
print_log "db_deletion: prepare" "Performing database deletion"
109109

110110
# Needed to separate the GRANT statement from the rest because it was providing a syntax error
111-
exec_cmd "mysql -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
111+
exec_cmd "mysql --skip-ssl -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
112112
SET sql_mode = 'ANSI_QUOTES';
113113
DROP DATABASE \"${SIMPLERISK_DB_DATABASE}\";
114114
USE mysql;
@@ -138,15 +138,15 @@ db_setup(){
138138

139139
print_log "initial_setup:info" "Applying changes to MySQL database... (MySQL error will be printed to console as guidance)"
140140
# Using sql_mode = ANSI_QUOTES to avoid using backticks
141-
exec_cmd "mysql -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
141+
exec_cmd "mysql --skip-ssl -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
142142
SET sql_mode = 'ANSI_QUOTES';
143143
CREATE DATABASE \"${SIMPLERISK_DB_DATABASE}\";
144144
USE \"${SIMPLERISK_DB_DATABASE}\";
145145
\. ${SCHEMA_FILE}
146146
CREATE USER \"${SIMPLERISK_DB_USERNAME}\"@\"%\" IDENTIFIED BY \"${SIMPLERISK_DB_PASSWORD}\";
147147
EOSQL" "Was not able to apply settings on database. Check error above. Exiting."
148148
# Needed to separate the GRANT statement from the rest because it was providing a syntax error
149-
exec_cmd "mysql -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
149+
exec_cmd "mysql --skip-ssl -u $DB_SETUP_USER -p$DB_SETUP_PASS -h$SIMPLERISK_DB_HOSTNAME -P$SIMPLERISK_DB_PORT <<EOSQL
150150
SET sql_mode = 'ANSI_QUOTES';
151151
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER ON \"${SIMPLERISK_DB_DATABASE}\".* TO \"${SIMPLERISK_DB_USERNAME}\"@\"%\";
152152
EOSQL" "Was not able to apply settings on database. Check error above. Exiting."
@@ -194,7 +194,6 @@ _main() {
194194
# shellcheck disable=SC2015
195195
[[ "${DB_SETUP:-}" = automatic* ]] && db_setup || true
196196
unset_variables
197-
service cron start
198197
exec "$@"
199198
}
200199

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/var/log/simplerisk/simplerisk.log {
2+
daily
3+
rotate 30
4+
compress
5+
missingok
6+
notifempty
7+
create 0640 www-data www-data
8+
dateext
9+
dateformat -%Y%m%d
10+
sharedscripts
11+
postrotate
12+
# Optional: reload service if needed
13+
# For example, if SimpleRisk had a daemon that needed to reopen the log:
14+
# systemctl reload simplerisk.service >/dev/null 2>&1 || true
15+
endscript
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# /etc/rsyslog.d/60-simplerisk.conf
2+
# Dedicated log for SimpleRisk (LOCAL0)
3+
local0.* /var/log/simplerisk/simplerisk.log
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[unix_http_server]
2+
file=/tmp/supervisor.sock ; (the path to the socket file)
3+
chmod=0700
4+
5+
[supervisord]
6+
childlogdir=/var/log/supervisor
7+
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
8+
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
9+
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
10+
loglevel=info ; (log level;default info; others: debug,warn,trace)
11+
pidfile=/var/run/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
12+
nodaemon=true ; (start in foreground if true;default false)
13+
minfds=1024 ; (min. avail startup file descriptors;default 1024)
14+
minprocs=200 ; (min. avail process descriptors;default 200)
15+
16+
[rpcinterface:supervisor]
17+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
18+
19+
[supervisorctl]
20+
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
21+
22+
[program:apache2]
23+
command=/usr/sbin/apache2ctl -D FOREGROUND
24+
stdout_logfile=/dev/stdout
25+
stderr_logfile=/dev/stderr
26+
autorestart=true
27+
28+
[program:rsyslog]
29+
command=/usr/sbin/rsyslogd -n
30+
autorestart=true
31+
priority=10
32+
33+
[program:cron]
34+
command=/usr/sbin/cron -f
35+
autostart=true
36+
autorestart=true
37+
priority=30
38+
stdout_logfile=/dev/stdout
39+
stdout_logfile_maxbytes=0
40+
stderr_logfile=/dev/stderr
41+
stderr_logfile_maxbytes=0

simplerisk-minimal/generate_dockerfile.sh

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
set -euo pipefail
44

5-
readonly MYSQL_KEY_URL='https://repo.mysql.com/RPM-GPG-KEY-mysql-2023'
65
SCRIPT_LOCATION="$(dirname "$(readlink -f "$0")")"
76
readonly SCRIPT_LOCATION
87

@@ -14,7 +13,7 @@ fi
1413

1514
cat << EOF > "${SCRIPT_LOCATION}/Dockerfile"
1615
# Dockerfile generated by script
17-
ARG php_version=8.3
16+
ARG php_version=8.4
1817
1918
EOF
2019

@@ -41,26 +40,27 @@ WORKDIR /var/www
4140
4241
SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
4342
44-
# Creating keyring env and installing apt dependencies
45-
RUN mkdir -p /etc/apt/keyrings && \\
46-
apt-get update && \\
47-
apt-get install -y --no-install-recommends gnupg2 wget lsb-release && \\
48-
wget -qO - $MYSQL_KEY_URL | gpg --dearmor -o /etc/apt/keyrings/mysql.gpg && \\
49-
# FIXME: use \$(lsb_release -cs) when trixie becomes available on MySQL repos
50-
echo "deb [signed-by=/etc/apt/keyrings/mysql.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-8.0" | tee /etc/apt/sources.list.d/mysql.list && \\
51-
apt-get update && \\
52-
apt-get -y install --no-install-recommends libldap2-dev \\
53-
libicu-dev \\
54-
libcap2-bin \\
55-
libcurl4-gnutls-dev \\
56-
libpng-dev \\
57-
libzip-dev \\
58-
supervisor \\
59-
cron \\
60-
ca-certificates \\
61-
mysql-community-client && \\
62-
apt-get -y remove gnupg2 wget lsb-release && \\
43+
# Install required packages, including MySQL client from Debian repos
44+
RUN apt-get update && \\
45+
apt-get install -y --no-install-recommends \\
46+
libldap2-dev \\
47+
libicu-dev \\
48+
libcap2-bin \\
49+
libcurl4-gnutls-dev \\
50+
libpng-dev \\
51+
libzip-dev \\
52+
supervisor \\
53+
cron \\
54+
ca-certificates \\
55+
rsyslog \\
56+
logrotate \\
57+
curl \\
58+
# This will install mariadb-client
59+
default-mysql-client && \\
60+
apt-get -y autoremove && \\
61+
apt-get -y purge && \\
6362
rm -rf /var/lib/apt/lists/*
63+
6464
# Configure all PHP extensions
6565
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && \\
6666
docker-php-ext-install ldap \\
@@ -70,13 +70,17 @@ RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu && \\
7070
zip \\
7171
gd \\
7272
intl
73+
7374
# Setting up setcap for port mapping without root and removing packages
7475
RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/apache2 && \\
7576
chmod gu+s /usr/sbin/cron && \\
7677
apt-get -y remove libcap2-bin && \\
7778
apt-get -y autoremove && \\
7879
apt-get -y purge
7980
81+
RUN echo "0 0 * * * root /usr/sbin/logrotate /etc/logrotate.d/simplerisk.conf > /dev/null 2>&1" >> /etc/cron.d/logrotate-cron && \\
82+
chmod 0644 /etc/cron.d/logrotate-cron
83+
8084
# Copying all files
8185
COPY common/ /
8286
EOF
@@ -121,12 +125,15 @@ RUN echo 'upload_max_filesize = 5M' >> /usr/local/etc/php/conf.d/docker-php-uplo
121125
# Cleanup /var/www/, creating Simplerisk user on www-data group and setting up ownerships
122126
RUN rm -rf /var/www/html && \\
123127
useradd -G www-data simplerisk && \\
124-
chown -R simplerisk:www-data /var/www/simplerisk /etc/apache2 /var/run/ /var/log/apache2 && \\
125-
chmod -R 770 /var/www/simplerisk /etc/apache2 /var/run/ /var/log/apache2 && \\
126-
chmod 755 /entrypoint.sh /etc/apache2/foreground.sh
128+
mkdir -p /var/log/simplerisk && \\
129+
mkdir -p /var/log/supervisor && \\
130+
mkdir -p /var/run/supervisor && \\
131+
chmod -R 700 /etc/apache2 /var/log/simplerisk /var/run/ /var/www/simplerisk && \\
132+
chmod 755 /entrypoint.sh /etc/apache2/foreground.sh && \\
133+
chown -R simplerisk:www-data /etc/apache2 /var/log/apache2 /var/log/simplerisk /var/log/supervisor /var/run/ /var/www/simplerisk
127134
128135
# Data to save
129-
VOLUME [ "/var/log/apache2", "/etc/apache2/ssl", "/var/www/simplerisk" ]
136+
VOLUME [ "/var/log", "/etc/apache2/ssl", "/var/www/simplerisk" ]
130137
131138
# Using simplerisk user from here
132139
USER simplerisk
@@ -142,5 +149,5 @@ HEALTHCHECK --interval=1m \\
142149
CMD curl --fail http://localhost || exit 1
143150
144151
# Start Apache
145-
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
152+
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]
146153
EOF

0 commit comments

Comments
 (0)