Skip to content

Commit f0e9f27

Browse files
authored
Merge pull request #259 from J0WI/alpine
Add Alpine variant
2 parents 0e76d15 + 923f8c4 commit f0e9f27

29 files changed

Lines changed: 1116 additions & 75 deletions

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,27 @@ jobs:
4242

4343
- <<: *test-scripts
4444
env: SCRIPT=generate-stackbrew-library.sh
45-
script:
45+
install:
46+
- wget -O "$HOME/bin/bashbrew" https://doi-janky.infosiftr.net/job/bashbrew/lastSuccessfulBuild/artifact/bin/bashbrew-amd64
47+
- chmod +x "$HOME/bin/bashbrew"
48+
script:
4649
- ./generate-stackbrew-library.sh
4750

4851
- stage: test images
49-
env: VERSION=11.0 VARIANT=fpm ARCH=amd64
52+
env: VERSION=11.0 VARIANT=fpm-alpine ARCH=amd64
53+
- env: VERSION=11.0 VARIANT=fpm-alpine ARCH=i386
54+
- env: VERSION=11.0 VARIANT=fpm ARCH=amd64
5055
- env: VERSION=11.0 VARIANT=fpm ARCH=i386
5156
- env: VERSION=11.0 VARIANT=apache ARCH=amd64
5257
- env: VERSION=11.0 VARIANT=apache ARCH=i386
58+
- env: VERSION=12.0 VARIANT=fpm-alpine ARCH=amd64
59+
- env: VERSION=12.0 VARIANT=fpm-alpine ARCH=i386
5360
- env: VERSION=12.0 VARIANT=fpm ARCH=amd64
5461
- env: VERSION=12.0 VARIANT=fpm ARCH=i386
5562
- env: VERSION=12.0 VARIANT=apache ARCH=amd64
5663
- env: VERSION=12.0 VARIANT=apache ARCH=i386
64+
- env: VERSION=13.0 VARIANT=fpm-alpine ARCH=amd64
65+
- env: VERSION=13.0 VARIANT=fpm-alpine ARCH=i386
5766
- env: VERSION=13.0 VARIANT=fpm ARCH=amd64
5867
- env: VERSION=13.0 VARIANT=fpm ARCH=i386
5968
- env: VERSION=13.0 VARIANT=apache ARCH=amd64

11.0/apache/Dockerfile

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
FROM php:7.1-apache
22

3+
# entrypoint.sh and cron.sh dependencies
34
RUN set -ex; \
5+
\
46
apt-get update; \
5-
# install the packages we need
67
apt-get install -y --no-install-recommends \
78
rsync \
89
bzip2 \
910
busybox-static \
1011
; \
12+
rm -rf /var/lib/apt/lists/*; \
13+
\
1114
mkdir -p /var/spool/cron/crontabs; \
12-
echo '*/15 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data; \
15+
echo '*/15 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
16+
1317
# install the PHP extensions we need
1418
# see https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html
19+
RUN set -ex; \
1520
\
1621
savedAptMark="$(apt-mark showmanual)"; \
1722
\
23+
apt-get update; \
1824
apt-get install -y --no-install-recommends \
1925
libcurl4-openssl-dev \
2026
libfreetype6-dev \
@@ -31,11 +37,31 @@ RUN set -ex; \
3137
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
3238
docker-php-ext-configure gd --with-freetype-dir=/usr --with-png-dir=/usr --with-jpeg-dir=/usr; \
3339
docker-php-ext-configure ldap --with-libdir="lib/$debMultiarch"; \
34-
docker-php-ext-install gd exif intl mbstring mcrypt ldap mysqli opcache pdo_mysql pdo_pgsql pgsql zip pcntl; \
35-
pecl install APCu-5.1.10; \
36-
pecl install memcached-3.0.4; \
37-
pecl install redis-3.1.6; \
38-
docker-php-ext-enable apcu redis memcached; \
40+
docker-php-ext-install \
41+
exif \
42+
gd \
43+
intl \
44+
ldap \
45+
mbstring \
46+
mcrypt \
47+
mysqli \
48+
opcache \
49+
pcntl \
50+
pdo_mysql \
51+
pdo_pgsql \
52+
pgsql \
53+
zip \
54+
; \
55+
pecl install \
56+
APCu-5.1.10 \
57+
memcached-3.0.4 \
58+
redis-3.1.6 \
59+
; \
60+
docker-php-ext-enable \
61+
apcu \
62+
memcached \
63+
redis \
64+
; \
3965
\
4066
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
4167
apt-mark auto '.*' > /dev/null; \
@@ -49,11 +75,11 @@ RUN set -ex; \
4975
| xargs -rt apt-mark manual; \
5076
\
5177
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
52-
rm -rf /var/lib/apt/lists/*; \
53-
\
78+
rm -rf /var/lib/apt/lists/*
79+
5480
# set recommended PHP.ini settings
5581
# see https://docs.nextcloud.com/server/12/admin_manual/configuration_server/server_tuning.html#enable-php-opcache
56-
{ \
82+
RUN { \
5783
echo 'opcache.enable=1'; \
5884
echo 'opcache.enable_cli=1'; \
5985
echo 'opcache.interned_strings_buffer=8'; \

11.0/fpm-alpine/Dockerfile

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
FROM php:7.1-fpm-alpine
2+
3+
# entrypoint.sh and cron.sh dependencies
4+
RUN set -ex; \
5+
\
6+
apk add --no-cache \
7+
bash \
8+
coreutils \
9+
rsync \
10+
; \
11+
\
12+
rm /var/spool/cron/crontabs/root; \
13+
echo '*/15 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data
14+
15+
# install the PHP extensions we need
16+
# see https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html
17+
RUN set -ex; \
18+
\
19+
apk add --no-cache --virtual .build-deps \
20+
alpine-sdk \
21+
autoconf \
22+
freetype-dev \
23+
icu-dev \
24+
libjpeg-turbo-dev \
25+
libmcrypt-dev \
26+
libpng-dev \
27+
libmemcached-dev \
28+
libxml2-dev \
29+
openldap-dev \
30+
pcre-dev \
31+
postgresql-dev \
32+
; \
33+
\
34+
docker-php-ext-configure gd --with-freetype-dir=/usr --with-png-dir=/usr --with-jpeg-dir=/usr; \
35+
docker-php-ext-configure ldap; \
36+
docker-php-ext-install \
37+
exif \
38+
gd \
39+
intl \
40+
ldap \
41+
mbstring \
42+
mcrypt \
43+
mysqli \
44+
opcache \
45+
pcntl \
46+
pdo_mysql \
47+
pdo_pgsql \
48+
pgsql \
49+
zip \
50+
; \
51+
pecl install \
52+
APCu-5.1.10 \
53+
memcached-3.0.4 \
54+
redis-3.1.6 \
55+
; \
56+
docker-php-ext-enable \
57+
apcu \
58+
memcached \
59+
redis \
60+
; \
61+
\
62+
runDeps="$( \
63+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
64+
| tr ',' '\n' \
65+
| sort -u \
66+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
67+
)"; \
68+
apk add --virtual .nextcloud-phpext-rundeps $runDeps; \
69+
apk del .build-deps
70+
71+
# set recommended PHP.ini settings
72+
# see https://docs.nextcloud.com/server/12/admin_manual/configuration_server/server_tuning.html#enable-php-opcache
73+
RUN { \
74+
echo 'opcache.enable=1'; \
75+
echo 'opcache.enable_cli=1'; \
76+
echo 'opcache.interned_strings_buffer=8'; \
77+
echo 'opcache.max_accelerated_files=10000'; \
78+
echo 'opcache.memory_consumption=128'; \
79+
echo 'opcache.save_comments=1'; \
80+
echo 'opcache.revalidate_freq=1'; \
81+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini; \
82+
\
83+
chown -R www-data:root /var/www/html; \
84+
chmod -R g=u /var/www/html
85+
86+
VOLUME /var/www/html
87+
88+
89+
ENV NEXTCLOUD_VERSION 11.0.7
90+
91+
RUN set -ex; \
92+
apk add --no-cache --virtual .fetch-deps \
93+
bzip2 \
94+
gnupg \
95+
; \
96+
\
97+
curl -fsSL -o nextcloud.tar.bz2 \
98+
"https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2"; \
99+
curl -fsSL -o nextcloud.tar.bz2.asc \
100+
"https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2.asc"; \
101+
export GNUPGHOME="$(mktemp -d)"; \
102+
# gpg key from https://nextcloud.com/nextcloud.asc
103+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \
104+
gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2; \
105+
rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc; \
106+
tar -xjf nextcloud.tar.bz2 -C /usr/src/; \
107+
rm nextcloud.tar.bz2; \
108+
rm -rf /usr/src/nextcloud/updater; \
109+
mkdir -p /usr/src/nextcloud/data; \
110+
mkdir -p /usr/src/nextcloud/custom_apps; \
111+
chmod +x /usr/src/nextcloud/occ; \
112+
apk del .fetch-deps
113+
114+
COPY *.sh /
115+
COPY config/* /usr/src/nextcloud/config/
116+
117+
ENTRYPOINT ["/entrypoint.sh"]
118+
CMD ["php-fpm"]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$CONFIG = array (
3+
'memcache.local' => '\OC\Memcache\APCu',
4+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
$CONFIG = array (
3+
"apps_paths" => array (
4+
0 => array (
5+
"path" => OC::$SERVERROOT."/apps",
6+
"url" => "/apps",
7+
"writable" => false,
8+
),
9+
1 => array (
10+
"path" => OC::$SERVERROOT."/custom_apps",
11+
"url" => "/custom_apps",
12+
"writable" => true,
13+
),
14+
),
15+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
$autoconfig_enabled = false;
4+
5+
if (getenv('SQLITE_DATABASE')) {
6+
$AUTOCONFIG["dbtype"] = "sqlite";
7+
$AUTOCONFIG["dbname"] = getenv('SQLITE_DATABASE');
8+
$autoconfig_enabled = true;
9+
} elseif (getenv('MYSQL_DATABASE') && getenv('MYSQL_USER') && getenv('MYSQL_PASSWORD') && getenv('MYSQL_HOST')) {
10+
$AUTOCONFIG["dbtype"] = "mysql";
11+
$AUTOCONFIG["dbname"] = getenv('MYSQL_DATABASE');
12+
$AUTOCONFIG["dbuser"] = getenv('MYSQL_USER');
13+
$AUTOCONFIG["dbpass"] = getenv('MYSQL_PASSWORD');
14+
$AUTOCONFIG["dbhost"] = getenv('MYSQL_HOST');
15+
$autoconfig_enabled = true;
16+
} elseif (getenv('POSTGRES_DB') && getenv('POSTGRES_USER') && getenv('POSTGRES_PASSWORD') && getenv('POSTGRES_HOST')) {
17+
$AUTOCONFIG["dbtype"] = "pgsql";
18+
$AUTOCONFIG["dbname"] = getenv('POSTGRES_DB');
19+
$AUTOCONFIG["dbuser"] = getenv('POSTGRES_USER');
20+
$AUTOCONFIG["dbpass"] = getenv('POSTGRES_PASSWORD');
21+
$AUTOCONFIG["dbhost"] = getenv('POSTGRES_HOST');
22+
$autoconfig_enabled = true;
23+
}
24+
25+
if ($autoconfig_enabled) {
26+
$AUTOCONFIG["dbtableprefix"] = getenv('NEXTCLOUD_TABLE_PREFIX') ?: "";
27+
28+
$AUTOCONFIG["directory"] = getenv('NEXTCLOUD_DATA_DIR') ?: "/var/www/html/data";
29+
30+
if (getenv('NEXTCLOUD_ADMIN_USER') && getenv('NEXTCLOUD_ADMIN_PASSWORD')) {
31+
$AUTOCONFIG["adminlogin"] = getenv('NEXTCLOUD_ADMIN_USER');
32+
$AUTOCONFIG["adminpass"] = getenv('NEXTCLOUD_ADMIN_PASSWORD');
33+
}
34+
}

11.0/fpm-alpine/cron.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
exec busybox crond -f -l 0 -L /dev/stdout

11.0/fpm-alpine/entrypoint.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# version_greater A B returns whether A > B
5+
function version_greater() {
6+
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]];
7+
}
8+
9+
# return true if specified directory is empty
10+
function directory_empty() {
11+
[ -n "$(find "$1"/ -prune -empty)" ]
12+
}
13+
14+
function run_as() {
15+
if [[ $EUID -eq 0 ]]; then
16+
su - www-data -s /bin/bash -c "$1"
17+
else
18+
bash -c "$1"
19+
fi
20+
}
21+
22+
installed_version="0.0.0~unknown"
23+
if [ -f /var/www/html/version.php ]; then
24+
installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";')
25+
fi
26+
image_version=$(php -r 'require "/usr/src/nextcloud/version.php"; echo "$OC_VersionString";')
27+
28+
if version_greater "$installed_version" "$image_version"; then
29+
echo "Can't start Nextcloud because the version of the data ($installed_version) is higher than the docker image version ($image_version) and downgrading is not supported. Are you sure you have pulled the newest image version?"
30+
exit 1
31+
fi
32+
33+
if version_greater "$image_version" "$installed_version"; then
34+
if [ "$installed_version" != "0.0.0~unknown" ]; then
35+
run_as 'php /var/www/html/occ app:list' > /tmp/list_before
36+
fi
37+
if [[ $EUID -eq 0 ]]; then
38+
rsync_options="-rlDog --chown www-data:root"
39+
else
40+
rsync_options="-rlD"
41+
fi
42+
rsync $rsync_options --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/
43+
44+
for dir in config data custom_apps themes; do
45+
if [ ! -d /var/www/html/"$dir" ] || directory_empty /var/www/html/"$dir"; then
46+
rsync $rsync_options --include /"$dir"/ --exclude '/*' /usr/src/nextcloud/ /var/www/html/
47+
fi
48+
done
49+
50+
if [ "$installed_version" != "0.0.0~unknown" ]; then
51+
run_as 'php /var/www/html/occ upgrade --no-app-disable'
52+
53+
run_as 'php /var/www/html/occ app:list' > /tmp/list_after
54+
echo "The following apps have beed disabled:"
55+
diff <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_before) <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_after) | grep '<' | cut -d- -f2 | cut -d: -f1
56+
rm -f /tmp/list_before /tmp/list_after
57+
fi
58+
fi
59+
60+
exec "$@"

0 commit comments

Comments
 (0)