build: refactor docker builds

Signed-off-by: nachoparker <nacho@ownyourbits.com>
This commit is contained in:
nachoparker 2019-05-11 12:13:19 -06:00
parent d9384817c2
commit 3b36dd3752
20 changed files with 138 additions and 253 deletions

View File

@ -1,48 +0,0 @@
# Batch-build docker container layers for NextCloudPi
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
nextcloudpi-armhf: nextcloud-armhf
docker build . -f docker-armhf/nextcloudpi/Dockerfile -t ownyourbits/nextcloudpi-armhf:latest
nextcloud-armhf: lamp-armhf
docker build . -f docker-armhf/nextcloud/Dockerfile -t ownyourbits/nextcloud-armhf:latest
lamp-armhf: debian-ncp-armhf
docker build . -f docker-armhf/lamp/Dockerfile -t ownyourbits/lamp-armhf:latest
debian-ncp-armhf:
docker build --pull . -f docker-armhf/debian-ncp/Dockerfile -t ownyourbits/debian-ncp-armhf:latest
nextcloudpi-x86: nextcloud-x86
docker build . -f docker/nextcloudpi/Dockerfile -t ownyourbits/nextcloudpi-x86:latest
nextcloud-x86: lamp-x86
docker build . -f docker/nextcloud/Dockerfile -t ownyourbits/nextcloud-x86:latest
lamp-x86: debian-ncp-x86
docker build . -f docker/lamp/Dockerfile -t ownyourbits/lamp-x86:latest
debian-ncp-x86:
docker build --pull . -f docker/debian-ncp/Dockerfile -t ownyourbits/debian-ncp-x86:latest
# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA

View File

@ -102,8 +102,9 @@ In order to generate the Docker images
```
git clone https://github.com/nextcloud/nextcloudpi.git
cd nextcloudpi
make # armhf version
make nextcloudpi-x86 # x86 version
./build-docker.sh x86
./build-docker.sh armhf
./build-docker.sh arm64
```
NextCloudPi can be installed in any architecture running the latest Debian
@ -126,6 +127,8 @@ https://hub.docker.com/r/ownyourbits/nextcloudpi-x86
https://hub.docker.com/r/ownyourbits/nextcloudpi-armhf
https://hub.docker.com/r/ownyourbits/nextcloudpi-arm64
## Contact
You can find us in the [forums](https://help.nextcloud.com/c/support/appliances-docker-snappy-vm) and a [Telegram group](https://t.me/NextCloudPi)

View File

@ -1,5 +1,4 @@
#!/bin/bash
# Batch creation of NextCloudPi images and containers
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
@ -10,6 +9,9 @@
set -e
version=$(git describe --tags --always)
version=${version%-*-*}
## BUILDING
source buildlib.sh # initializes $IMGNAME
@ -33,28 +35,61 @@ IMG="$( ls -1t tmp/*.img | head -1 )"
# VM
./build-VM.sh
# Docker x86
make nextcloudpi-x86
# Docker
./build-docker.sh x86
./build-docker.sh armhf
./build-docker.sh arm64
[[ "$FTPPASS" == "" ]] && exit
export DOCKER_CLI_EXPERIMENTAL=enabled
# TODO test first
#&& {
docker push ownyourbits/nextcloudpi-x86
docker push ownyourbits/nextcloudpi-x86:${version}
docker push ownyourbits/nextcloud-x86
docker push ownyourbits/nextcloud-x86 :${version}
docker push ownyourbits/lamp-x86
docker push ownyourbits/lamp-x86:${version}
docker push ownyourbits/debian-ncp-x86
docker push ownyourbits/debian-ncp-x86:${version}
#}
# Docker armhf
cp -n /usr/bin/qemu-arm-static docker-armhf && \
make nextcloudpi-armhf
# TODO test first && {
docker push ownyourbits/nextcloudpi-armhf
docker push ownyourbits/nextcloudpi-armhf:${version}
docker push ownyourbits/nextcloud-armhf
docker push ownyourbits/nextcloud-armhf:${version}
docker push ownyourbits/lamp-armhf
docker push ownyourbits/lamp-armhf:${version}
docker push ownyourbits/debian-ncp-armhf
docker push ownyourbits/debian-ncp-armhf:${version}
#}
rm -f docker-armhf/qemu-arm-static
# TODO test first && {
docker push ownyourbits/nextcloudpi-arm64
docker push ownyourbits/nextcloudpi-arm64:${version}
docker push ownyourbits/nextcloud-arm64
docker push ownyourbits/nextcloud-arm64:${version}
docker push ownyourbits/lamp-arm64
docker push ownyourbits/lamp-arm64:${version}
docker push ownyourbits/debian-ncp-arm64
docker push ownyourbits/debian-ncp-arm64:${version}
#}
# Docker multi-arch
docker manifest create --amend ownyourbits/nextcloudpi \
ownyourbits/nextcloudpi-x86 \
ownyourbits/nextcloudpi-armhf \
ownyourbits/nextcloudpi-arm64
docker manifest annotate ownyourbits/nextcloudpi ownyourbits/nextcloudpi-x86 --os linux --arch amd64
docker manifest annotate ownyourbits/nextcloudpi ownyourbits/nextcloudpi-armhf --os linux --arch arm
docker manifest annotate ownyourbits/nextcloudpi ownyourbits/nextcloudpi-arm64 --os linux --arch arm64v8
docker manifest push -p ownyourbits/nextcloudpi
# License
#

View File

@ -13,7 +13,7 @@ BASEDIR=/var/www
install()
{
apt-get update
apt-get install --no-install-recommends -y rsync
apt-get install --no-install-recommends -y rsync openssh-client
}
configure()

48
build-docker.sh Executable file
View File

@ -0,0 +1,48 @@
# Batch-build docker container layers for NextCloudPi
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
set -e
version=$(git describe --tags --always)
version=${version%-*-*}
function docker_build() { DOCKER_BUILDKIT=1 docker build --progress=plain . "$@"; }
function build_arch()
{
local arch="${1}"
local arch_qemu="${2}"
local ncp_tag="${3:-arch}"
docker_build -f docker/debian-ncp/Dockerfile -t ownyourbits/debian-ncp-${arch}:latest --pull --build-arg arch=${arch} --build-arg arch_qemu=${arch_qemu}
docker_build -f docker/lamp/Dockerfile -t ownyourbits/lamp-${arch}:latest --build-arg arch=${arch}
docker_build -f docker/nextcloud/Dockerfile -t ownyourbits/nextcloud-${arch}:latest --build-arg arch=${arch}
docker_build -f docker/nextcloudpi/Dockerfile -t ownyourbits/nextcloudpi-${arch}:latest --build-arg arch=${arch}
docker tag ownyourbits/nextcloudpi-${arch}:latest ownyourbits/nextcloudpi-${ncp_tag}:"${version}"
}
[[ "$@" =~ "x86" ]] && build_arch amd64 x86_64 x86
[[ "$@" =~ "armhf" ]] && build_arch armhf arm
[[ "$@" =~ "arm64" ]] && build_arch arm64v8 aarch64 arm64
# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA

View File

@ -1,11 +0,0 @@
FROM arm32v7/debian:stretch-slim
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
CMD /bin/bash
COPY docker-armhf/qemu-arm-static /usr/bin
RUN mkdir -p /etc/services-available.d /etc/services-enabled.d
COPY docker-common/debian-ncp/run-parts.sh /

View File

@ -1,43 +0,0 @@
FROM ownyourbits/debian-ncp-armhf
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
SHELL ["/bin/bash", "-c"]
ENV DOCKERBUILD 1
COPY etc/library.sh lamp.sh /usr/local/etc/
RUN \
# installation
source /usr/local/etc/library.sh; \
set +x; \
install_app /usr/local/etc/lamp.sh; \
# stop mysqld
mysqladmin -u root shutdown; \
# mariaDB fixups (move database to /data-ro, which will be in a persistent volume)
mkdir -p /data-ro /data; \
mv /var/lib/mysql /data-ro/database; \
sed -i "s|^datadir.*|datadir = /data-ro/database|" /etc/mysql/mariadb.conf.d/90-ncp.cnf; \
# package cleanup
apt-get autoremove -y; \
apt-get clean; \
find /var/lib/apt/lists -type f | xargs rm; \
rm -rf /usr/share/man/*; \
rm -rf /usr/share/doc/*; \
rm /var/cache/debconf/*-old; \
rm -f /var/log/alternatives.log /var/log/apt/*; \
# specific cleanup
rm /data-ro/database/ib_logfile*; \
rm /usr/local/etc/lamp.sh
COPY docker-common/lamp/010lamp /etc/services-enabled.d/
ENTRYPOINT ["/run-parts.sh"]
EXPOSE 80 443

View File

@ -1,52 +0,0 @@
FROM ownyourbits/lamp-armhf
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
SHELL ["/bin/bash", "-c"]
ENV DOCKERBUILD 1
COPY etc/library.sh /usr/local/etc/
COPY bin/ncp/CONFIG/nc-nextcloud.sh /
COPY etc/ncp-config.d/nc-nextcloud.cfg /usr/local/etc/ncp-config.d/
RUN \
# mark as image build
touch /.ncp-image; \
# installation ( /var/www/nextcloud -> /data/app which will be in a volume )
apt-get update; \
apt-get install --no-install-recommends -y wget ca-certificates sudo jq; \
source /usr/local/etc/library.sh; \
set +x; \
install_app /nc-nextcloud.sh; \
run_app_unsafe /nc-nextcloud.sh; \
mv /var/www/nextcloud /data-ro/nextcloud; \
ln -s /data-ro/nextcloud /var/www/nextcloud; \
# stop mysqld
mysqladmin -u root shutdown; \
# package cleanup
apt-get autoremove -y; \
apt-get clean; \
find /var/lib/apt/lists -type f | xargs rm; \
rm -rf /usr/share/man/*; \
rm -rf /usr/share/doc/*; \
rm /var/cache/debconf/*-old; \
rm -f /var/log/alternatives.log /var/log/apt/*; \
# specific cleanup
apt-get purge -y wget ca-certificates; \
rm /nc-nextcloud.sh /usr/local/etc/ncp-config.d/nc-nextcloud.cfg; \
rm /.ncp-image;
COPY docker-common/nextcloud/020nextcloud /etc/services-enabled.d/
COPY bin/ncp-provisioning.sh /usr/local/bin/
# display message until first run initialization is complete
COPY docker-common/nextcloud/ncp-wait-msg.html /data-ro/nextcloud
RUN \
mv /data-ro/nextcloud/index.php /; \
mv /data-ro/nextcloud/ncp-wait-msg.html /data-ro/nextcloud/index.php;

View File

@ -1,69 +0,0 @@
FROM ownyourbits/nextcloud-armhf
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
SHELL ["/bin/bash", "-c"]
ENV DOCKERBUILD 1
RUN mkdir -p /tmp/ncp-build
COPY bin/ /tmp/ncp-build/bin/
COPY etc /tmp/ncp-build/etc/
COPY ncp.sh update.sh /tmp/ncp-build/
COPY ncp-web /tmp/ncp-build/ncp-web/
COPY ncp-app /tmp/ncp-build/ncp-app/
COPY docker-common /tmp/ncp-build/docker-common/
RUN \
# make sure we don't accidentally disable first run wizard
rm -f ncp-web/{wizard.cfg,ncp-web.cfg}; \
# mark as image build
touch /.ncp-image; \
# mark as docker image
touch /.docker-image; \
apt-get update; \
apt-get install --no-install-recommends -y wget ca-certificates; \
# install nextcloudpi
source /usr/local/etc/library.sh; \
set +x; \
cd /tmp/ncp-build/; \
install_app ncp.sh; \
# fix default paths
sed -i 's|/media/USBdrive|/data/backups|' /usr/local/etc/ncp-config.d/nc-backup.cfg; \
sed -i 's|/media/USBdrive|/data/backups|' /usr/local/etc/ncp-config.d/nc-backup-auto.cfg; \
# specific cleanup
cd /; rm -r /tmp/ncp-build; \
rm /.ncp-image; \
# cleanup all NCP extras
source /usr/local/etc/library.sh; \
find /usr/local/bin/ncp -name '*.sh' | while read l; do cleanup_script $l; done; \
# should be cleaned up in no-ip.sh, but breaks udiskie.
# safe to do it here since no automount in docker
apt-get purge -y make gcc libc-dev; \
# package clean up
apt-get autoremove -y; \
apt-get clean; \
find /var/lib/apt/lists -type f | xargs rm; \
find /var/log -type f -exec rm {} \; ; \
rm -rf /usr/share/man/*; \
rm -rf /usr/share/doc/*; \
rm -f /var/log/alternatives.log /var/log/apt/*; \
rm /var/cache/debconf/*-old;
COPY docker-common/nextcloudpi/000ncp /etc/services-enabled.d/
COPY bin/ncp/CONFIG/nc-init.sh /
COPY etc/ncp-config.d/nc-init.cfg /usr/local/etc/ncp-config.d/
# 4443 - ncp-web
EXPOSE 80 443 4443

View File

@ -1,9 +1,19 @@
FROM debian:stretch-slim
ARG arch=armhf
ARG arch_qemu=arm
FROM debian:stretch-slim AS qemu
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends qemu-user-static
FROM ${arch}/debian:stretch-slim
ARG arch_qemu
LABEL maintainer="Ignacio Núñez Hernanz <nacho@ownyourbits.com>"
CMD /bin/bash
COPY --from=qemu /usr/bin/qemu-${arch_qemu}-static /usr/bin/
RUN mkdir -p /etc/services-available.d /etc/services-enabled.d
COPY docker-common/debian-ncp/run-parts.sh /
COPY docker/debian-ncp/run-parts.sh /

View File

@ -1,6 +1,10 @@
FROM ownyourbits/debian-ncp-x86
# syntax=docker/dockerfile:experimental
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
ARG arch=armhf
FROM ownyourbits/debian-ncp-${arch}
LABEL maintainer="Ignacio Núñez Hernanz <nacho@ownyourbits.com>"
SHELL ["/bin/bash", "-c"]
@ -8,7 +12,7 @@ ENV DOCKERBUILD 1
COPY etc/library.sh lamp.sh /usr/local/etc/
RUN \
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
# installation
source /usr/local/etc/library.sh; \
@ -36,7 +40,7 @@ rm -f /var/log/alternatives.log /var/log/apt/*; \
rm /data-ro/database/ib_logfile*; \
rm /usr/local/etc/lamp.sh
COPY docker-common/lamp/010lamp /etc/services-enabled.d/
COPY docker/lamp/010lamp /etc/services-enabled.d/
ENTRYPOINT ["/run-parts.sh"]

View File

@ -1,6 +1,10 @@
FROM ownyourbits/lamp-x86
# syntax=docker/dockerfile:experimental
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
ARG arch=armhf
FROM ownyourbits/lamp-${arch}
LABEL maintainer="Ignacio Núñez Hernanz <nacho@ownyourbits.com>"
SHELL ["/bin/bash", "-c"]
@ -10,7 +14,7 @@ COPY etc/library.sh /usr/local/etc/
COPY bin/ncp/CONFIG/nc-nextcloud.sh /
COPY etc/ncp-config.d/nc-nextcloud.cfg /usr/local/etc/ncp-config.d/
RUN \
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
# mark as image build
touch /.ncp-image; \
@ -42,11 +46,11 @@ apt-get purge -y wget ca-certificates; \
rm /nc-nextcloud.sh /usr/local/etc/ncp-config.d/nc-nextcloud.cfg; \
rm /.ncp-image;
COPY docker-common/nextcloud/020nextcloud /etc/services-enabled.d/
COPY docker/nextcloud/020nextcloud /etc/services-enabled.d/
COPY bin/ncp-provisioning.sh /usr/local/bin/
# display message until first run initialization is complete
COPY docker-common/nextcloud/ncp-wait-msg.html /data-ro/nextcloud
COPY docker/nextcloud/ncp-wait-msg.html /data-ro/nextcloud
RUN \
mv /data-ro/nextcloud/index.php /; \
mv /data-ro/nextcloud/ncp-wait-msg.html /data-ro/nextcloud/index.php;

View File

@ -1,6 +1,10 @@
FROM ownyourbits/nextcloud-x86
# syntax=docker/dockerfile:experimental
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>
ARG arch=armhf
FROM ownyourbits/nextcloud-${arch}
LABEL maintainer="Ignacio Núñez Hernanz <nacho@ownyourbits.com>"
SHELL ["/bin/bash", "-c"]
@ -12,9 +16,9 @@ COPY etc /tmp/ncp-build/etc/
COPY ncp.sh update.sh /tmp/ncp-build/
COPY ncp-web /tmp/ncp-build/ncp-web/
COPY ncp-app /tmp/ncp-build/ncp-app/
COPY docker-common /tmp/ncp-build/docker-common/
COPY docker /tmp/ncp-build/docker/
RUN \
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
# make sure we don't accidentally disable first run wizard
rm -f ncp-web/{wizard.cfg,ncp-web.cfg}; \
@ -60,10 +64,9 @@ rm -rf /usr/share/doc/*; \
rm -f /var/log/alternatives.log /var/log/apt/*; \
rm /var/cache/debconf/*-old;
COPY docker-common/nextcloudpi/000ncp /etc/services-enabled.d/
COPY docker/nextcloudpi/000ncp /etc/services-enabled.d/
COPY bin/ncp/CONFIG/nc-init.sh /
COPY etc/ncp-config.d/nc-init.cfg /usr/local/etc/ncp-config.d/
# 4443 - ncp-web
EXPOSE 80 443 4443

View File

@ -33,6 +33,7 @@ install()
$APTINSTALL apt-transport-https gnupg2 wget ca-certificates
echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
# INSTALL
##########################################

View File

@ -119,7 +119,7 @@ cp -r ncp-app /var/www/
done
# update services
cp docker-common/{lamp/010lamp,nextcloud/020nextcloud,nextcloudpi/000ncp} /etc/services-enabled.d
cp docker/{lamp/010lamp,nextcloud/020nextcloud,nextcloudpi/000ncp} /etc/services-enabled.d
}