Skip to content

Commit

Permalink
Use Redis for file locking
Browse files Browse the repository at this point in the history
  • Loading branch information
whitehara committed Aug 17, 2023
1 parent 1f413b8 commit 140235c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 43 deletions.
56 changes: 34 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# ADD CRON and SMBCLIENT
# see https://github.com/nextcloud/docker/tree/master/.examples/dockerfiles
FROM local-nextcloud:26-apache-zts
FROM local-nextcloud:27-apache-zts

# For getting the newest redis-server
RUN apt-get update && apt-get install -y lsb-release gpg && \
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" > /etc/apt/sources.list.d/redis.list && \
curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps;

RUN apt-get update && apt-get install -y \
supervisor procps smbclient redis-server imagemagick \
Expand Down Expand Up @@ -46,21 +52,22 @@ stderr_logfile_maxbytes=0\n\
command=/cron.sh" > /supervisord.conf

# disable unused Apache2 module & enable used modules
RUN a2dismod access_compat reqtimeout status mpm_prefork
RUN a2dismod -f deflate
RUN a2enmod mpm_event proxy_fcgi proxy http2 rewrite headers setenvif env mime dir alias remoteip filter brotli

# enable FastCGI
RUN sed -i -e "s!SetHandler .*!SetHandler 'proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost'!g" /etc/apache2/conf-enabled/docker-php.conf
RUN echo "SetEnv proxy-sendcl 1" >> /etc/apache2/conf-enabled/docker-php.conf
RUN echo "AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json image/svg+xml" >> /etc/apache2/conf-enabled/docker-php.conf
RUN a2dismod access_compat reqtimeout status mpm_prefork ;\
a2dismod -f deflate ;\
a2enmod mpm_event proxy_fcgi proxy http2 rewrite headers setenvif env mime dir alias remoteip filter brotli

RUN cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
RUN sed -i -e "s/include=NONE\//include=/g" /usr/local/etc/php-fpm.conf
# Tune HTTP/2
RUN sed -i -e "s!</IfModule>! H2WindowSize 1048576\n H2StreamMaxMemSize 5120000000\n</IfModule>!g" /etc/apache2/mods-enabled/http2.conf

RUN mkdir -p /var/run/php-fpm
RUN cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
RUN sed -i -e "s!^\(listen =\).*!\1 /var/run/php-fpm/php-fpm.sock!g" \
# enable FastCGI
RUN sed -i -e "s!SetHandler .*!SetHandler 'proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost'!g" /etc/apache2/conf-enabled/docker-php.conf ;\
echo "SetEnv proxy-sendcl 1" >> /etc/apache2/conf-enabled/docker-php.conf ;\
echo "AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json image/svg+xml" >> /etc/apache2/conf-enabled/docker-php.conf ;\
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf ;\
sed -i -e "s/include=NONE\//include=/g" /usr/local/etc/php-fpm.conf ;\
mkdir -p /var/run/php-fpm ;\
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf ;\
sed -i -e "s!^\(listen =\).*!\1 /var/run/php-fpm/php-fpm.sock!g" \
-e "s/^;\(listen.\(owner\|group\) = www-data\)/\1/g" \
-e "s/^\(pm =\).*/\1 ondemand/g" \
-e "s/^\(pm.max_children =\).*/\1 \${PHP_FPM_MAX_CHILDREN}/g" \
Expand All @@ -76,25 +83,30 @@ ENV PHP_FPM_PROCESS_IDLE_TIMEOUT=10s
ENV PHP_FPM_MAX_REQUESTS=400

# Tune APCu
RUN echo "apc.shm_size = ${PHP_APC_SHM_SIZE}" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

ENV PHP_APC_SHM_SIZE=128M
RUN echo "apc.shm_size=\${PHP_APC_SHM_SIZE}" >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

# Make local cache dir
# You can use it in config.php > config_path
RUN mkdir -p /var/www/nxc_cache && chown www-data /var/www/nxc_cache

# Install redis using with unixsocket
RUN mkdir -p /var/run/redis && chown redis:redis /var/run/redis
RUN sed -i -e "s/^\(port\) .*/\1 0/g" \
# Setup redis using with unixsocket
RUN mkdir -p /var/run/redis && chown redis:redis /var/run/redis ;\
sed -i -e "s/^\(port\) .*/\1 0/g" \
-e "s/^\(daemonize\) .*/\1 no/g" \
-e "s!^\(logfile\) .*!\1 ''!g" \
-e "s/^\(always-show-logo\) .*/\1 no/g" \
-e "s/^# \(unixsocket \)/\1/g" \
-e "s!^# \(unixsocket \).*!\1/var/run/redis/redis-server.sock!g" \
-e "s/^# \(unixsocketperm\) .*/\1 770/g" \
-e "s/^\(save .*\)/# \1/g" \
/etc/redis/redis.conf
RUN usermod -a -G redis www-data
/etc/redis/redis.conf ;\
usermod -a -G redis www-data ;\
( echo 'session.save_handler=redis' ;\
echo 'session.save_path="unix:///var/run/redis/redis-server.sock"' ;\
echo 'redis.session.locking_enabled=1' ;\
echo 'redis.session.lock_retries=1' ;\
echo 'redis.session.lock_wait_time=10000' ;\
) >> /usr/local/etc/php/conf.d/docker-php-ext-redis.ini

# Enable PDF preview
# You can use it with modifying config.php
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ The last part is customized nextcloud. It is based on the 2nd image. The additio
```
'cache_path' => '/var/www/nxc_cache',
```
- Install Redis Server
- Setup Redis Server
- You can use it to write the following settings in the config/config.php
```
'memcache.distributed' => '\OC\Memcache\Redis',
'filelocking.enabled' => true,
'memcache.locking' => '\\OC\Memcache\Redis',
'memcache.distributed' => '\\OC\Memcache\Redis',
'redis' => [
'host' => '/var/run/redis/redis-server.sock',
'port' => 0,
Expand Down
51 changes: 34 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
#!/bin/sh

### 1st stage: php ###
PHP_VER=8.1
PHP_VER=8.2
PHP_TAG=local-php:$PHP_VER-apache-zts-bullseye
PHP_DIR=./php/$PHP_VER/bullseye/apache/

# Update the repository
(cd php; git reset --hard; git pull)
# Modify Dockerfile
sed -i -e "s/\(--with-apxs2\)/\1 --enable-zts --disable-zend-signals --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data /g" $PHP_DIR/Dockerfile
# Build
docker build -t $PHP_TAG --pull --no-cache $PHP_DIR
function build_php () {
# Update the repository
(cd php; git reset --hard; git pull https://github.com/docker-library/php/ master)
# Modify Dockerfile
sed -i -e "s/\(--with-apxs2\)/\1 --enable-zts --disable-zend-signals --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data /g" \
-e "s/\(gnupg\)/\1 aria2/g" \
-e "s/curl -fsSL/aria2c -x8/g" \
$PHP_DIR/Dockerfile
# Build
docker build -t $PHP_TAG --pull --no-cache $PHP_DIR
}

### 2nd stage: nextcloud ###
NEXTCLOUD_VER=`awk -F'.' '{print $1}' nextcloud/latest.txt`
NEXTCLOUD_TAG=local-nextcloud:$NEXTCLOUD_VER-apache-zts
NEXTCLOUD_DIR=./nextcloud/$NEXTCLOUD_VER/apache/

# Update the repository
(cd nextcloud; git reset --hard; git pull)
# Modify Dockerfile
sed -i -e "s!FROM .*!FROM $PHP_TAG!g" $NEXTCLOUD_DIR/Dockerfile
# Build
docker build -t $NEXTCLOUD_TAG $NEXTCLOUD_DIR
function build_nextcloud () {
# Update the repository
(cd nextcloud; git reset --hard; git pull https://github.com/nextcloud/docker/ master)
# Modify Dockerfile for faster download
sed -i -e "s!FROM .*!FROM $PHP_TAG!g" \
-e "s/\(gnupg\)/\1 aria2/g" \
-e "s/curl -fsSL/aria2c -x8/g" \
$NEXTCLOUD_DIR/Dockerfile
# Build
docker build -t $NEXTCLOUD_TAG $NEXTCLOUD_DIR
}

### 3rd stage: nextcloud-custom ###
CUSTOM_TAG=nextcloud-custom
function build_custom () {

# Modify Dockerfile
sed -i -e "s!FROM .*!FROM $NEXTCLOUD_TAG!g" ./Dockerfile
# Build
docker build -t $CUSTOM_TAG .
# Modify Dockerfile
sed -i -e "s!FROM .*!FROM $NEXTCLOUD_TAG!g" ./Dockerfile
# Build
docker build -t $CUSTOM_TAG .
}

### MAIN ###
build_php
build_nextcloud
build_custom
2 changes: 1 addition & 1 deletion nextcloud
Submodule nextcloud updated 62 files
+2 −2 .examples/dockerfiles/full/apache/Dockerfile
+2 −2 .examples/dockerfiles/full/fpm/Dockerfile
+2 −2 .examples/dockerfiles/imap/apache/Dockerfile
+2 −2 .examples/dockerfiles/imap/fpm/Dockerfile
+6 −6 .github/workflows/command-rebase.yml
+10 −7 25/apache/Dockerfile
+47 −0 25/apache/entrypoint.sh
+11 −8 25/fpm-alpine/Dockerfile
+47 −0 25/fpm-alpine/entrypoint.sh
+10 −7 25/fpm/Dockerfile
+47 −0 25/fpm/entrypoint.sh
+11 −8 26/apache/Dockerfile
+47 −0 26/apache/entrypoint.sh
+12 −9 26/fpm-alpine/Dockerfile
+47 −0 26/fpm-alpine/entrypoint.sh
+11 −8 26/fpm/Dockerfile
+47 −0 26/fpm/entrypoint.sh
+12 −8 27/apache/Dockerfile
+0 −0 27/apache/config/apache-pretty-urls.config.php
+0 −0 27/apache/config/apcu.config.php
+0 −0 27/apache/config/apps.config.php
+0 −0 27/apache/config/autoconfig.php
+0 −0 27/apache/config/redis.config.php
+0 −0 27/apache/config/reverse-proxy.config.php
+0 −0 27/apache/config/s3.config.php
+0 −0 27/apache/config/smtp.config.php
+0 −0 27/apache/config/swift.config.php
+0 −0 27/apache/cron.sh
+47 −0 27/apache/entrypoint.sh
+0 −0 27/apache/upgrade.exclude
+13 −9 27/fpm-alpine/Dockerfile
+0 −0 27/fpm-alpine/config/apcu.config.php
+0 −0 27/fpm-alpine/config/apps.config.php
+0 −0 27/fpm-alpine/config/autoconfig.php
+0 −0 27/fpm-alpine/config/redis.config.php
+0 −0 27/fpm-alpine/config/reverse-proxy.config.php
+0 −0 27/fpm-alpine/config/s3.config.php
+0 −0 27/fpm-alpine/config/smtp.config.php
+0 −0 27/fpm-alpine/config/swift.config.php
+0 −0 27/fpm-alpine/cron.sh
+47 −0 27/fpm-alpine/entrypoint.sh
+0 −0 27/fpm-alpine/upgrade.exclude
+12 −8 27/fpm/Dockerfile
+0 −0 27/fpm/config/apcu.config.php
+0 −0 27/fpm/config/apps.config.php
+0 −0 27/fpm/config/autoconfig.php
+0 −0 27/fpm/config/redis.config.php
+0 −0 27/fpm/config/reverse-proxy.config.php
+0 −0 27/fpm/config/s3.config.php
+0 −0 27/fpm/config/smtp.config.php
+0 −0 27/fpm/config/swift.config.php
+0 −0 27/fpm/cron.sh
+47 −0 27/fpm/entrypoint.sh
+0 −0 27/fpm/upgrade.exclude
+10 −7 Dockerfile-alpine.template
+10 −7 Dockerfile-debian.template
+34 −2 README.md
+47 −0 docker-entrypoint.sh
+1 −1 generate-stackbrew-library.sh
+1 −1 latest.txt
+37 −18 update.sh
+80 −0 versions.json
2 changes: 1 addition & 1 deletion php
Submodule php updated 203 files

0 comments on commit 140235c

Please sign in to comment.