diff --git a/bin/build b/bin/build new file mode 100755 index 0000000..d2fee7c --- /dev/null +++ b/bin/build @@ -0,0 +1,62 @@ +#!/bin/bash + +# potential flags: custom tag, no squash, delete/redo, custom dir + +# Parameters +if [[ $# -eq 0 ]]; then + echo "Usage: $0 imagedir [containername]" + exit 0 +fi + +if [[ ! -d $1 ]]; then + echo "Error: directory \"$1\" not found." + exit 1 +else + proj=$1 +fi + +if [[ -n $2 ]]; then + cont=$2 +else + cont=$proj +fi + +fail() { + podman image rm $proj:$today + podman rm -f $cont + echo "Encountered unexpected error. Exiting." + exit 2 +} + +today=$(date "+%Y-%m-%d-T%H%M") +tag=latest + +# Main +set -e +cd $proj + +# execute install script if it exists +# install script should be idempotent +if [[ -f Install ]]; then + ./Install +fi + +# build image +echo "Building container ..." +podman build -f Containerfile -t $proj:$today -t $proj:$tag || fail +#--squash +# start container +echo "Creating container ..." +podman create --name $cont $proj:$today || fail +podman start $cont || fail +# Systemdfile is for commands that need systemd to execute +echo "Running build steps that require systemd ..." +podman exec $cont bash -c "if [ -f /root/Systemdfile ]; then /root/Systemdfile; fi" || fail +echo "Finished!" +# get container IP +printf "Container IP is: " +podman inspect -f '{{ .NetworkSettings.IPAddress }}' $cont +#echo "Use this address to configure your reverse proxy" + +# todo: configure autostart service +# todo: handle volumes diff --git a/bin/launch b/bin/launch new file mode 100755 index 0000000..344c985 --- /dev/null +++ b/bin/launch @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ -z $1 ]]; then + echo "Usage: $0 image [name]" + exit 1 +fi + +if [[ -z $2 ]]; then + 2=$1 +fi + +podman create --name $2 $1 +podman start $2 diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..e69de29 diff --git a/nextcloud/build.sh b/nextcloud/build.sh deleted file mode 100755 index 58c7d2d..0000000 --- a/nextcloud/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Variables -today=$(date "+%Y-%m-%d-T%H%M") -proj=nextcloud - -podman build -f Containerfile -t $proj:$today -t $proj:latest #--squash diff --git a/debian/Containerfile b/src/debian/Containerfile similarity index 100% rename from debian/Containerfile rename to src/debian/Containerfile diff --git a/debian/build.sh b/src/debian/build.sh similarity index 100% rename from debian/build.sh rename to src/debian/build.sh diff --git a/nextcloud/Containerfile b/src/nextcloud/Containerfile similarity index 52% rename from nextcloud/Containerfile rename to src/nextcloud/Containerfile index 0af7786..8155204 100644 --- a/nextcloud/Containerfile +++ b/src/nextcloud/Containerfile @@ -1,7 +1,6 @@ ### Meta ### FROM localhost/debian -# Versions of various packages that we may need to refer to ARG phpv=7.3 ARG psqlv=11 @@ -10,27 +9,27 @@ EXPOSE 80/tcp ### Basics ### RUN apt update -y && apt install -y systemd sudo wget apache2 php-fpm \ php-gd php-zip php-pgsql php-curl php-mbstring php-intl php-imagick \ - php-xml php-json redis-server php-redis postgresql postgresql-doc unzip + php-xml php-json redis-server php-redis postgresql postgresql-doc \ + unzip php-ldap -RUN mkdir -p /srv/nextcloud/database /srv/nextcloud/files && chown -R www-data:www-data \ - /srv/nextcloud +RUN mkdir -p /srv/nextcloud/database /srv/nextcloud/files && chown -R www-data:www-data /srv/nextcloud COPY resources/bin/ /usr/local/bin/ ### Apache ### RUN a2enmod rewrite headers env dir mime proxy_fcgi && a2enconf php${phpv}-fpm -COPY resources/site.conf /etc/apache2/sites-available/ +COPY resources/apache/nextcloud.conf /etc/apache2/sites-available/ WORKDIR /etc/apache2/sites-enabled -RUN rm 000-default.conf && ln -s ../sites-available/site.conf +RUN rm 000-default.conf && ln -s ../sites-available/nextcloud.conf ### PHP ### RUN systemctl enable php${phpv}-fpm -COPY resources/php.ini /etc/php/${phpv}/fpm/ -COPY config/php/www.conf /etc/php/${phpv}/fpm/pool.d/ +COPY resources/php/php.ini /etc/php/${phpv}/fpm/ +COPY resources/php/www.conf /etc/php/${phpv}/fpm/pool.d/ ### Redis ### COPY --chown=redis:redis resources/redis.conf /etc/redis/ @@ -38,11 +37,9 @@ COPY --chown=redis:redis resources/redis.conf /etc/redis/ RUN usermod -a -G redis www-data ### PostgreSQL ### -COPY --chown=postgres:postgres resources/pg_hba.conf /etc/postgresql/${psqlv}/main/pg_hba.conf +COPY --chown=postgres:postgres resources/postgresql/pg_hba.conf /etc/postgresql/${psqlv}/main/pg_hba.conf -COPY --chown=postgres:postgres resources/redo.sql /usr/local/lib/psql/ - -#RUN db-redo +COPY --chown=postgres:postgres resources/postgresql/redo.sql /usr/local/lib/psql/ ### Nextcloud ### WORKDIR /var/www/html @@ -52,11 +49,7 @@ RUN wget https://download.nextcloud.com/server/releases/latest.zip && \ chown -R www-data:www-data nextcloud && \ rm latest.zip -COPY --chown=www-data:www-data config/nextcloud/my.config.php nextcloud/config/ - -#RUN nc-occ maintenance:install --data-dir "/srv/nextcloud/files/" --database "pgsql" --database-host "/var/run/postgresql" --database-name "nextcloud" --database-user "ncadmin" --database-pass "" --admin-user "admin" --admin-pass "admin" - -#RUN nc-occ maintenance:update:htaccess && nc-occ db:add-missing-indices && nc-occ db:convert-filecache-bigint +COPY --chown=www-data:www-data resources/my.config.php nextcloud/config/ # TODO: install apps via occ @@ -65,3 +58,6 @@ WORKDIR /root COPY resources/crontab . RUN crontab -u www-data crontab && rm crontab +### Systemdfile ### +COPY Systemdfile /root/ +RUN chmod +x /root/Systemdfile diff --git a/src/nextcloud/Systemdfile b/src/nextcloud/Systemdfile new file mode 100644 index 0000000..86889e0 --- /dev/null +++ b/src/nextcloud/Systemdfile @@ -0,0 +1,17 @@ +#!/bin/bash + +# fail if any command returns error +set -e +# wait 5 seconds to make sure all services have finished starting up +sleep 5 + +# make database for nextcloud +db-redo + +# install nextcloud +nc-occ maintenance:install --data-dir "/srv/nextcloud/files/" --database "pgsql" --database-host "/var/run/postgresql" --database-name "nextcloud" --database-user "ncadmin" --database-pass "" --admin-user "admin" --admin-pass "admin" + +# configure nextcloud options +nc-occ maintenance:update:htaccess +nc-occ db:add-missing-indices +nc-occ db:convert-filecache-bigint diff --git a/nextcloud/resources/site.conf b/src/nextcloud/resources/apache/nextcloud.conf similarity index 100% rename from nextcloud/resources/site.conf rename to src/nextcloud/resources/apache/nextcloud.conf diff --git a/nextcloud/resources/bin/db-dump b/src/nextcloud/resources/bin/db-dump similarity index 100% rename from nextcloud/resources/bin/db-dump rename to src/nextcloud/resources/bin/db-dump diff --git a/nextcloud/resources/bin/db-redo b/src/nextcloud/resources/bin/db-redo similarity index 100% rename from nextcloud/resources/bin/db-redo rename to src/nextcloud/resources/bin/db-redo diff --git a/nextcloud/resources/bin/nc-occ b/src/nextcloud/resources/bin/nc-occ similarity index 100% rename from nextcloud/resources/bin/nc-occ rename to src/nextcloud/resources/bin/nc-occ diff --git a/nextcloud/resources/crontab b/src/nextcloud/resources/crontab similarity index 83% rename from nextcloud/resources/crontab rename to src/nextcloud/resources/crontab index cec2414..9cd6438 100644 --- a/nextcloud/resources/crontab +++ b/src/nextcloud/resources/crontab @@ -2,6 +2,6 @@ # Run Nextcloud cron tasks every 5 minutes */5 * * * * php -f /var/www/html/nextcloud/cron.php # Dump database every hour -10 * * * * /usr/local/bin/dbdump 01 +10 * * * * /usr/local/bin/db-dump 01 # Scan for new files every 15 minutes */15 * * * * nc-occ files:scan --all diff --git a/nextcloud/config/nextcloud/my.config.php b/src/nextcloud/resources/my.config.php similarity index 99% rename from nextcloud/config/nextcloud/my.config.php rename to src/nextcloud/resources/my.config.php index ac9cf29..249c85c 100644 --- a/nextcloud/config/nextcloud/my.config.php +++ b/src/nextcloud/resources/my.config.php @@ -24,6 +24,7 @@ $CONFIG = array( 'overwrite.cli.url' => 'http://medusa.casa.alemor.org/nextcloud/', /** Memory Caching **/ +/** 'memcache.local' => '\\OC\\Memcache\\Redis', 'memcache.distributed' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', @@ -34,5 +35,6 @@ $CONFIG = array( 'port' => 0, 'timeout' => 0.0, ), +**/ ); diff --git a/nextcloud/resources/php.ini b/src/nextcloud/resources/php/php.ini similarity index 100% rename from nextcloud/resources/php.ini rename to src/nextcloud/resources/php/php.ini diff --git a/nextcloud/config/php/www.conf b/src/nextcloud/resources/php/www.conf similarity index 100% rename from nextcloud/config/php/www.conf rename to src/nextcloud/resources/php/www.conf diff --git a/nextcloud/resources/pg_hba.conf b/src/nextcloud/resources/postgresql/pg_hba.conf similarity index 100% rename from nextcloud/resources/pg_hba.conf rename to src/nextcloud/resources/postgresql/pg_hba.conf diff --git a/nextcloud/resources/redo.sql b/src/nextcloud/resources/postgresql/redo.sql similarity index 100% rename from nextcloud/resources/redo.sql rename to src/nextcloud/resources/postgresql/redo.sql diff --git a/nextcloud/resources/redis.conf b/src/nextcloud/resources/redis.conf similarity index 100% rename from nextcloud/resources/redis.conf rename to src/nextcloud/resources/redis.conf