diff --git a/.docker/Dockerfile.php81 b/.docker/Dockerfile.php81 index a6d72f8..486d711 100644 --- a/.docker/Dockerfile.php81 +++ b/.docker/Dockerfile.php81 @@ -77,5 +77,5 @@ VOLUME /var/www/html WORKDIR /var/www/html -ENTRYPOINT [ "bash", "/var/www/scripts/entrypoint.sh" ] +ENTRYPOINT [ "bash", "/var/www/scripts/nextcloud-entrypoint.sh" ] CMD ["php-fpm"] diff --git a/.docker/Dockerfile.php82 b/.docker/Dockerfile.php82 index caa064f..d375b01 100644 --- a/.docker/Dockerfile.php82 +++ b/.docker/Dockerfile.php82 @@ -77,5 +77,5 @@ VOLUME /var/www/html WORKDIR /var/www/html -ENTRYPOINT [ "bash", "/var/www/scripts/entrypoint.sh" ] +ENTRYPOINT [ "bash", "/var/www/scripts/nextcloud-entrypoint.sh" ] CMD ["php-fpm"] diff --git a/.docker/Dockerfile.php83 b/.docker/Dockerfile.php83 index c6aa670..bdb75c4 100644 --- a/.docker/Dockerfile.php83 +++ b/.docker/Dockerfile.php83 @@ -77,5 +77,5 @@ VOLUME /var/www/html WORKDIR /var/www/html -ENTRYPOINT [ "bash", "/var/www/scripts/entrypoint.sh" ] +ENTRYPOINT [ "bash", "/var/www/scripts/nextcloud-entrypoint.sh" ] CMD ["php-fpm"] diff --git a/.docker/config/php/xdebug.ini b/.docker/config/php/xdebug.ini index 3a6d1d3..5e31f73 100644 --- a/.docker/config/php/xdebug.ini +++ b/.docker/config/php/xdebug.ini @@ -1,5 +1,4 @@ xdebug.client_host=host.docker.internal xdebug.discover_client_host=true xdebug.log_level=0 -xdebug.mode=debug xdebug.start_with_request=yes diff --git a/.docker/database-services.yml b/.docker/database-services.yml new file mode 100644 index 0000000..9170132 --- /dev/null +++ b/.docker/database-services.yml @@ -0,0 +1,32 @@ +services: + mysql: + # Pin to 8.4: mysql:latest currently resolves to 9.x, and Nextcloud autoinstall + # runs with the application user, which cannot read mysql.component there. + image: mysql:8.4 + volumes: + - ../volumes/mysql/init:/docker-entrypoint-initdb.d + - ../volumes/mysql/data:/var/lib/mysql + ports: + - target: 3306 + published: "3306-3325" + host_ip: ${IP_BIND:-127.0.0.1} + command: ["mysqld"] + environment: + - TZ=${TZ:-CET} + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root} + - MYSQL_DATABASE=${MYSQL_DATABASE:-nextcloud} + - MYSQL_USER=${MYSQL_USER:-nextcloud} + - MYSQL_PASSWORD=${MYSQL_PASSWORD:-nextcloud} + pgsql: + image: postgres:13-alpine + volumes: + - ../volumes/postgres/data:/var/lib/postgresql/data + ports: + - target: 5432 + published: "5432-5451" + host_ip: ${IP_BIND:-127.0.0.1} + command: ["postgres", "-c", "log_statement=all"] + environment: + - POSTGRES_DB=${POSTGRES_DB:-nextcloud} + - POSTGRES_USER=${POSTGRES_USER:-nextcloud} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-nextcloud} \ No newline at end of file diff --git a/.docker/scripts/entrypoint.sh b/.docker/scripts/nextcloud-entrypoint.sh similarity index 97% rename from .docker/scripts/entrypoint.sh rename to .docker/scripts/nextcloud-entrypoint.sh index b8732e1..e117b19 100644 --- a/.docker/scripts/entrypoint.sh +++ b/.docker/scripts/nextcloud-entrypoint.sh @@ -140,9 +140,5 @@ exec busybox crond -f -l 0 -L /dev/stdout > /dev/null 2>&1 & runuser -u www-data -- php -f /var/www/html/cron.php # Start PHP-FPM -if [[ "$HTTP_PORT" != 80 ]]; then - echo "💙 Nextclud is up! Access http://localhost:$HTTP_PORT" -else - echo "💙 Nextclud is up! Access http://localhost" -fi +echo "💙 Nextcloud is up!" exec "$@" diff --git a/README.md b/README.md index 0a766c0..7ff5290 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,24 @@ # Nextcloud development environment -An development apps environment for Nextcloud. +A Docker Compose-based development environment for Nextcloud. -## Development environment +> [!WARNING] +> This environment is intended for development only. It uses default credentials and insecure development settings and must not be used in production. -Run the command: +## Quick start + +Start the basic environment with MySQL: ```bash -docker compose up nextcloud mysql nginx mailpit redis +docker compose up ``` -* [Advanced setup](docs/advanced-setup.md) - * [Environments](docs/advanced-setup.md#environments) - * [PHP custom settings](docs/advanced-setup.md#php-custom-settings) -* [App development](docs/apps-development.md) - * [Sample](docs/apps-development.md#samble) -* [FAQ](docs/faq.md) - * [Reset setup](docs/faq.md#reset-setup) - * [Upgrade to newest commits of server repository](docs/faq.md#upgrade-to-newest-commits-of-server-repository) - * [Using IDE](docs/faq.md#using-ide) - * [Fix permissions](docs/faq.md#fix-permissions) - * [Simplify commands with alias](docs/bash_aliases.md) \ No newline at end of file +For PostgreSQL, optional services, dynamic host ports, multiple environments, +and other advanced configuration, see the +[advanced setup guide](docs/advanced-setup.md). + +## More documentation + +- [Advanced setup](docs/advanced-setup.md) +- [App development](docs/apps-development.md) +- [FAQ](docs/faq.md) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1e8503b..e6af1f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,12 @@ services: - pgsql: - image: postgres:13-alpine - restart: unless-stopped - volumes: - - ./volumes/postgres/data:/var/lib/postgresql/data - environment: - - POSTGRES_DB=${POSTGRES_DB:-nextcloud} - - POSTGRES_USER=${POSTGRES_USER:-nextcloud} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-nextcloud} - ports: - - 127.0.0.1:5432:5432 - command: postgres -c log_statement=all - mysql: - # Pin to 8.4: mysql:latest currently resolves to 9.x, and Nextcloud autoinstall - # runs with the application user, which cannot read mysql.component there. - image: mysql:8.4 - volumes: - - ./volumes/mysql/init:/docker-entrypoint-initdb.d - - ./volumes/mysql/data:/var/lib/mysql - ports: - - 127.0.0.1:3306:3306 - restart: unless-stopped - environment: - - TZ=${TZ:-CET} - - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root} - - MYSQL_DATABASE=${MYSQL_DATABASE:-nextcloud} - - MYSQL_USER=${MYSQL_USER:-nextcloud} - - MYSQL_PASSWORD=${MYSQL_PASSWORD:-nextcloud} + database: + extends: + file: .docker/database-services.yml + service: ${DB_HOST:-mysql} + networks: + default: + aliases: + - ${DB_HOST:-mysql} nextcloud: image: ghcr.io/librecodecoop/nextcloud-dev-php${PHP_VERSION:-83}:latest # build: @@ -34,10 +14,13 @@ services: # dockerfile: Dockerfile.php${PHP_VERSION:-83} volumes: - ./.docker/scripts/wait-for-db.php:/var/www/scripts/wait-for-db.php + - ./volumes/php:/var/www/php-config - ~/.composer:/var/www/.composer/ - ~/.npm:/var/www/.npm/ - ./volumes/nextcloud:/var/www/html restart: unless-stopped + depends_on: + - database environment: - HOST_UID=${HOST_UID:-1000} - HOST_GID=${HOST_GID:-1000} @@ -56,10 +39,11 @@ services: - MAIL_DOMAIN=${MAIL_DOMAIN:-nextcloud.test} - MAIL_SMTPPORT=${MAIL_SMTPPORT:-1025} - MAIL_SMTPHOST=${MAIL_SMTPHOST:-mailpit} - - VERSION_NEXTCLOUD=${VERSION_NEXTCLOUD:-stable33} + - VERSION_NEXTCLOUD=${VERSION_NEXTCLOUD:-master} - AUTOINSTALL=${AUTOINSTALL:-1} - XDEBUG_CONFIG - - HTTP_PORT=${HTTP_PORT:-80} + - XDEBUG_MODE + - PHP_INI_SCAN_DIR=/usr/local/etc/php/conf.d:/var/www/php-config extra_hosts: - host.docker.internal:host-gateway nginx: @@ -75,23 +59,33 @@ services: - ./volumes/nginx/includes:/etc/nginx/conf.d/includes/ - ./volumes/nginx/certs:/certs ports: - - ${HTTP_PORT:-80}:80 - - 443:443 + - target: 80 + published: "${HTTP_PORT:-80-99}" + host_ip: ${IP_BIND:-127.0.0.1} + - target: 443 + published: "${HTTPS_PORT:-443-462}" + host_ip: ${IP_BIND:-127.0.0.1} mailpit: image: axllent/mailpit ports: - - 127.0.0.1:${MAILHOG_PORT:-8025}:8025 + - target: 8025 + published: "${MAILHOG_PORT:-8025-8044}" + host_ip: ${IP_BIND:-127.0.0.1} redis: image: redis eurooffice: image: ghcr.io/euro-office/documentserver:latest + profiles: + - eurooffice restart: always volumes: - ./volumes/eurooffice:/home/eurooffice/.eurooffice - ./volumes/eurooffice/local.json:/etc/onlyoffice/documentserver/local.json - ./volumes/nextcloud/apps-extra/eurooffice-plugin:/var/www/onlyoffice/documentserver/sdkjs-plugins/libresign:ro ports: - - 8080:80 + - target: 80 + published: "8080-8099" + host_ip: ${IP_BIND:-127.0.0.1} environment: - EXAMPLE_ENABLED=true - JWT_SECRET=${JWT_SECRET:-my_jwt_secret} @@ -101,13 +95,16 @@ services: - host.docker.internal:host-gateway playwright: image: mcr.microsoft.com/playwright:v1.59.1-noble - container_name: nextcloud-playwright + profiles: + - playwright user: pwuser volumes: - ./volumes/nextcloud:/var/www/html working_dir: /var/www/html ports: - - 127.0.0.1:9323:9323 + - target: 9323 + published: "9323-9342" + host_ip: ${IP_BIND:-127.0.0.1} environment: - PLAYWRIGHT_BASE_URL=${PLAYWRIGHT_BASE_URL:-https://nginx} - NODE_ENV=test @@ -120,15 +117,21 @@ services: - default signal-gateway: image: bbernhard/signal-cli-rest-api:latest + profiles: + - signal restart: unless-stopped ports: - - 127.0.0.1:5001:8080 + - target: 8080 + published: "5001-5020" + host_ip: ${IP_BIND:-127.0.0.1} volumes: - ./volumes/signal:/home/.local/share/signal-cli environment: - LOG_LEVEL=info whatsapp.web: image: aldinokemal2104/go-whatsapp-web-multidevice + profiles: + - whatsapp restart: unless-stopped environment: - APP_PORT=3000 diff --git a/docs/advanced-setup.md b/docs/advanced-setup.md index f7262d4..797e690 100644 --- a/docs/advanced-setup.md +++ b/docs/advanced-setup.md @@ -1,15 +1,143 @@ # Advanced setup -## Environments +## Environment variables -You can customize the environment before first run changing some environments entries. +The development environment can be customized through environment variables. -Create an `.env` file and add values on your needs. +An `.env` file is optional. Variables can also be provided inline: -`VERSION_NEXTCLOUD` For this environment, the recommended branch is `stable33`. If you need to work with another Nextcloud server version, use the matching branch from the [Nextcloud server repository](https://github.com/nextcloud/server). +```bash +VERSION_NEXTCLOUD=stable33 docker compose up +``` + +By default, `VERSION_NEXTCLOUD` uses `master`. To use another Nextcloud version, set it to the corresponding branch from the [Nextcloud server repository](https://github.com/nextcloud/server). + +Xdebug can be configured with its native `XDEBUG_MODE` variable: + +```bash +XDEBUG_MODE=debug docker compose up +XDEBUG_MODE=develop,debug docker compose up +XDEBUG_MODE=coverage docker compose up +``` + +## Database + +MySQL is used by default: + +```bash +docker compose up +``` + +The supported `DB_HOST` values are: + +- `mysql` +- `pgsql` + +To use PostgreSQL: + +```bash +DB_HOST=pgsql docker compose up +``` + +## Optional services + +Optional services are enabled with Docker Compose profiles: + +```bash +docker compose --profile eurooffice up +docker compose --profile playwright up +docker compose --profile signal up +docker compose --profile whatsapp up +``` + +Multiple profiles can be enabled together: + +```bash +docker compose \ + --profile eurooffice \ + --profile playwright \ + up +``` + +## Multiple environments + +Multiple checkouts can run at the same time. + +Docker uses the standard host ports when they are available. If a port is already in use, another available port is selected automatically. + +Start each environment from its own directory: + +```bash +cd /path/to/first-checkout +docker compose up +``` + +```bash +cd /path/to/second-checkout +docker compose up +``` + +To see the ports assigned to an environment: + +```bash +docker compose ps +``` + +To check a specific port, use: + +```bash +docker compose port nginx 80 +``` + +For example, if it returns: + +```text +127.0.0.1:81 +``` + +access Nextcloud at: + +```text +http://localhost:81 +``` + +When port `80` is available, Nextcloud remains accessible normally at: + +```text +http://localhost +``` + +A specific host port can still be requested explicitly: + +```bash +HTTP_PORT=9000 HTTPS_PORT=9443 docker compose up +``` + +By default, published services bind to `127.0.0.1` and are accessible only from the local host. To expose them on other network interfaces, set: + +```bash +IP_BIND=0.0.0.0 docker compose up +``` + +This can make the development services accessible to other hosts on the network, subject to the host firewall and network configuration. + +HTTP and HTTPS use automatic ranges beginning at ports `80` and `443` when no override is provided. The example above forces `host:9000 -> container:80` and `host:9443 -> container:443`. ## PHP custom settings -Custom PHP settings have to be applied on [`.docker/app/config/php.ini`](/.docker/app/config/php.ini) file. +Custom PHP settings can be added as `.ini` files in `volumes/php/`. This directory is ignored by Git and is mounted into the PHP container without replacing the default configuration bundled in the image. + +For example, create `volumes/php/99-local.ini`: + +```ini +memory_limit=1024M +upload_max_filesize=512M +``` + +Restart the PHP service after changing these files: + +```bash +docker compose restart nextcloud +``` ⬅️ [Back to index](../README.md)