Compare commits

...

9 Commits

Author SHA1 Message Date
Ethan Paul df55484e5a
!LOCAL Add makefile for automating build and upload 2024-04-12 17:07:38 -04:00
Ethan Paul 1eafbc0a66
!LOCAL adapt compose file for local dev 2024-04-12 17:07:38 -04:00
Ethan Paul 2d92c672e2
Remove duplicate JS mimetype inclusions 2024-04-12 17:07:38 -04:00
Ethan Paul abea6087e5
Add service container for executing cron tasks 2024-04-12 17:07:38 -04:00
Ethan Paul fb6290d01f
Document new custom nginx image 2024-04-12 17:07:38 -04:00
Ethan Paul d98b8fc065
Update compose to use new custom nginx infrastructure 2024-04-12 17:07:38 -04:00
Ethan Paul 2ae4390f93
Add dockerfile for building custom nginx container
Add entrypoint that calls envsubst ahead of starting nginx
2024-04-12 17:07:38 -04:00
Ethan Paul c39cd210f8
Move nginx config to template file
Replace hardcoded config values with environment variables
2024-04-12 17:07:37 -04:00
Ethan Paul a990337983
Add pgsql php extension to support postgres backends 2024-04-12 17:05:06 -04:00
7 changed files with 103 additions and 37 deletions

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
REPOSITORY_PROXY = vcs.enp.one/skylab/nxcloud-proxy
REPOSITORY_SERVER = vcs.enp.one/skylab/nxcloud-server
.PHONY: help docs
# source: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## List Makefile targets
$(info Makefile documentation)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'
image: ## Build image
podman build ./php-fpm --tag $(REPOSITORY_SERVER):latest
podman build ./nginx --tag $(REPOSITORY_PROXY):latest
push: image ## Build and publish image
podman login $(shell echo $(REPOSITORY_SERVER) | cut -d '/' -f 1)
podman push $(REPOSITORY_SERVER):latest
podman login $(shell echo $(REPOSITORY_PROXY) | cut -d '/' -f 1)
podman push $(REPOSITORY_PROXY):latest

View File

@ -61,6 +61,12 @@ Simply run this command from the root of the cloned repo:
this will take a while.
### Building nginx
This will embed an optimized configuration for serving Nextcloud files and PHP-FPM resources. Run this
command from the root of the cloned repo:
`docker compose build nginx`
### Installing Nextcloud
Run `docker compose up -d`. If something doesn't work try debugging it yourself of open an issue with the php-fpm and nginx logs attached.
@ -82,9 +88,6 @@ Edit `/your/nextcloud/root/nextcloud/config/config.php` and add the following op
),
```
### Editing nginx.conf
You may also have to replace `example.com` with your own domain or multiple domains in the nginx.conf file.
### Enabling system cron (optional)
Nextcloud must perform background tasks. The best way to do that is to use cron. However, on docker this is not easily doable. Here the host will perform the cronjobs required.
@ -165,4 +168,4 @@ Add this to your `/your/nextcloud/root/nextcloud/config/config.php`:
### Migrating from existing Nextcloud
To migrate you follow the steps described in the official [docs](https://docs.nextcloud.com/server/28/admin_manual/maintenance/migrating.html). The only difference here is importing the database backup into MariaDB running in the Docker Container. The way I did it is I exposed a port to MariaDB in the docker compose file and I ran something like `mysql -h [localhost:PORT HERE] -u nextcloud -pPASSWORD HERE nextcloud < database.bak` to import the backed up database.
To migrate you follow the steps described in the official [docs](https://docs.nextcloud.com/server/28/admin_manual/maintenance/migrating.html). The only difference here is importing the database backup into MariaDB running in the Docker Container. The way I did it is I exposed a port to MariaDB in the docker compose file and I ran something like `mysql -h [localhost:PORT HERE] -u nextcloud -pPASSWORD HERE nextcloud < database.bak` to import the backed up database.

View File

@ -2,55 +2,71 @@
services:
nginx:
container_name: nginx-nextcloud
image: nginx:latest
build: ./nginx
ports:
- 80:80
- 8080:80
- 443:443
volumes:
- ${NEXTCLOUD_DIR}:/var/www/html
- ${DATA_DIR}:/data
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./appdata/application:/var/www/html
- ./appdata/data:/data
environment:
- NEXTCLOUD_PHP_FPM_HOST=nxcloud-server-1:9000
- NEXTCLOUD_DOMAIN=localhost
- NEXTCLOUD_MAX_UPLOAD_SIZE=4G
networks:
- nextcloud
depends_on:
- php-fpm-nextcloud
- redis-nextcloud
- mariadb-nextcloud
- server
- redis
- mariadb
php-fpm-nextcloud:
container_name: php-fpm-nextcloud
build: ./php-fpm
server:
build:
context: ./php-fpm
tags:
- vcs.enp.one/skylab/nextcloud-server:latest
volumes:
- ${NEXTCLOUD_DIR}:/var/www/html
- ${DATA_DIR}:/data
- ./appdata/application:/var/www/html
- ./appdata/data:/data
networks:
- nextcloud
mariadb-nextcloud:
container_name: mariadb-nextcloud
mariadb:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- ./mariadb:/var/lib/mysql
- ./appdata/database:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASS}
- MYSQL_PASSWORD=${MARIADB_PASS}
- MARIADB_RANDOM_ROOT_PASSWORD=true
- MYSQL_PASSWORD=nextcloud
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
networks:
- nextcloud
redis-nextcloud:
container_name: redis-nextcloud
# image: redis:latest
# keydb is a fork and drop-in replacement for Redis
redis:
image: eqalpha/keydb
restart: unless-stopped
networks:
- nextcloud
cron:
image: vcs.enp.one/skylab/nextcloud-server:latest
command:
- -c
- "'while true; do php --define apc.enable_cli=1 /var/www/html/cron.php; sleep 300; done'"
networks:
- nextcloud
user: www-data
entrypoint:
- /bin/bash
volumes:
- ./appdata/application:/var/www/html
- ./appdata/data:/data
depends_on:
- server
- redis
- mariadb
networks:
nextcloud:
driver: bridge

10
nginx/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM docker.io/library/nginx:latest
ENV NEXTCLOUD_DOMAIN=example.com
ENV NEXTCLOUD_PHP_FPM_HOST=server:9000
ENV NEXTCLOUD_MAX_UPLOAD_SIZE=512M
ADD nginx.conf.template /nginx.conf.template
ADD docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["sh", "-c", "/docker-entrypoint.sh"]

16
nginx/docker-entrypoint.sh Executable file
View File

@ -0,0 +1,16 @@
#/usr/bin/env bash
# This implementation is adapted from the solution proposed here:
# https://stackoverflow.com/questions/21866477/nginx-use-environment-variables
# envsubst will take the input and replace all references to environment
# variables with their corresponding value. Because nginx uses the same
# '$' prefix for its internal variables, we should explicitly define the
# variables we want to replace rather than replacing all env vars.
envsubst '
$NEXTCLOUD_PHP_FPM_HOST
$NEXTCLOUD_DOMAIN
$NEXTCLOUD_MAX_UPLOAD_SIZE
' < /nginx.conf.template > /etc/nginx/nginx.conf
exec nginx -g 'daemon off;'

View File

@ -2,7 +2,7 @@ events { worker_connections 1024; }
http {
upstream php-handler {
server php-fpm-nextcloud:9000;
server ${NEXTCLOUD_PHP_FPM_HOST};
#server unix:/run/php/php8.2-fpm.sock;
}
@ -16,7 +16,7 @@ http {
listen 80;
listen [::]:80;
# INFO: Set this to your domain
server_name example.com;
server_name ${NEXTCLOUD_DOMAIN};
# Prevent nginx HTTP Server Detection
server_tokens off;
@ -34,7 +34,7 @@ http {
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
# set max upload size and increase upload timeout:
client_max_body_size 512M;
client_max_body_size ${NEXTCLOUD_MAX_UPLOAD_SIZE};
client_body_timeout 300s;
fastcgi_buffers 64 4K;
@ -71,10 +71,10 @@ http {
# and include that list explicitly or add the file extension
# only for Nextcloud like below:
include mime.types;
types {
text/javascript js mjs;
application/wasm wasm;
}
#types {
# text/javascript js mjs;
# application/wasm wasm;
#}
# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour

View File

@ -55,7 +55,8 @@ RUN install-php-extensions \
redis \
imagick \
sysvsem \
opcache
opcache \
pgsql
# Copy optimized php.ini-development and production