From 944187b98ba93857fb1e5737ecbecdcef2bf3086 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 10 Mar 2023 10:28:26 +0100 Subject: [PATCH 01/12] Proposed change to in-build docker-compose.yml and Dockerfile. The current implementation uses php 7.4, which is no longer compatible with the required PHP version of the server. I upped this to PHP 8.1 List of changes: - Upped PHP Version to 8.1 - Added Apache Webserver so the Container works "out of the box" after docker-compose up -d - Mounting whole project as volume to /var/www/html in docker-compose.yml (and set WORKDIR to /var/www/html) Tested in a Docker for Windows environment. Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 50 ++++++++++++++++++++------------ .devcontainer/docker-compose.yml | 1 + 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4374d03954f71..42d94e9963eda 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,31 +4,43 @@ ARG DEBIAN_FRONTEND=noninteractive # PHP RUN apt-get update -y + +RUN apt install -y apache2 vim software-properties-common + +RUN add-apt-repository ppa:ondrej/php + RUN apt-get install --no-install-recommends -y \ - php7.4 \ - php7.4-gd \ - php7.4-zip \ - php7.4-curl \ - php7.4-xml \ - php7.4-mbstring \ - php7.4-sqlite \ - php7.4-xdebug \ - php7.4-pgsql \ - php7.4-intl \ - php7.4-imagick \ - php7.4-gmp \ - php7.4-apcu \ - php7.4-bcmath \ + php8.1 \ + php8.1-common \ + php8.1-gd \ + php8.1-zip \ + php8.1-curl \ + php8.1-xml \ + php8.1-xmlrpc \ + php8.1-mbstring \ + php8.1-sqlite \ + php8.1-xdebug \ + php8.1-pgsql \ + php8.1-intl \ + php8.1-imagick \ + php8.1-gmp \ + php8.1-apcu \ + php8.1-bcmath \ + php8.1-redis \ + php8.1-soap \ + php8.1-imap \ + php8.1-opcache \ + php8.1-cli \ + php8.1-dev \ libmagickcore-6.q16-3-extra \ curl \ - vim \ lsof \ make \ nodejs \ npm -RUN echo "xdebug.remote_enable = 1" >> /etc/php/7.4/cli/conf.d/20-xdebug.ini -RUN echo "xdebug.remote_autostart = 1" >> /etc/php/7.4/cli/conf.d/20-xdebug.ini +RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini +RUN echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini # Docker RUN apt-get -y install \ @@ -44,4 +56,6 @@ RUN add-apt-repository \ stable" RUN apt-get update -y RUN apt-get install -y docker-ce docker-ce-cli containerd.io -RUN ln -s /var/run/docker-host.sock /var/run/docker.sock +RUN ln -s /var/run/docker-host.sock /var/run/docker.sock + +WORKDIR /var/www/html diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ada819429f442..ffec604fbb6d0 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -5,6 +5,7 @@ services: volumes: - .:/workspace:cached - /var/run/docker.sock:/var/run/docker-host.sock + - ..:/var/www/html command: /bin/sh -c "while sleep 1000; do :; done" ports: - 80:80 From 0046cd89b28965d871bf93f75b4548133e74faf8 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Sat, 11 Mar 2023 12:18:21 +0000 Subject: [PATCH 02/12] Minor improvements for devcontainer * Autostart apache2 * Apply occ installation on start * Autostart Xdebug on request * Add DevContainer Xdebug profile Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 8 +++++++- .devcontainer/codespace.config.php | 1 + .devcontainer/devcontainer.json | 25 ++++++++++++++----------- .devcontainer/docker-compose.yml | 2 +- .devcontainer/setup.sh | 22 ++++++++++++++++++++++ .vscode/launch.json | 14 ++++++++++++++ 6 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 42d94e9963eda..4d579223b8dd2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -5,7 +5,7 @@ ARG DEBIAN_FRONTEND=noninteractive # PHP RUN apt-get update -y -RUN apt install -y apache2 vim software-properties-common +RUN apt install -y apache2 vim software-properties-common sudo nano RUN add-apt-repository ppa:ondrej/php @@ -42,6 +42,12 @@ RUN apt-get install --no-install-recommends -y \ RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini RUN echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini +# Autostart XDebug for apache +RUN { \ + echo "xdebug.mode=debug"; \ + echo "xdebug.start_with_request=yes"; \ +} >> /etc/php/8.1/apache2/conf.d/20-xdebug.ini + # Docker RUN apt-get -y install \ apt-transport-https \ diff --git a/.devcontainer/codespace.config.php b/.devcontainer/codespace.config.php index 5d883c3c9dfdb..c191698c2565c 100644 --- a/.devcontainer/codespace.config.php +++ b/.devcontainer/codespace.config.php @@ -16,4 +16,5 @@ if(is_string($codespaceName) && !empty($codespaceName) && is_string($codespaceDomain) && !empty($codespaceDomain)) { $CONFIG['overwritehost'] = $codespaceName . '-80.' . $codespaceDomain; $CONFIG['overwriteprotocol'] = 'https'; + $CONFIG['trusted_domains'] = [ $CONFIG['overwritehost'] ]; } diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f86a8cf34302e..2f197a58fedfc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,15 +8,18 @@ 8080, 8025 ], - "runArgs": [ - "--privileged" - ], - "extensions": [ - "felixfbecker.php-debug", - "felixfbecker.php-intellisense", - "ms-azuretools.vscode-docker" - ], - "settings": { - "php.suggest.basic": false, - } + "customizations": { + "vscode": { + "extensions": [ + "felixfbecker.php-debug", + "felixfbecker.php-intellisense", + "ms-azuretools.vscode-docker", + "xdebug.php-debug" + ], + "settings": { + "php.suggest.basic": false + } + } + }, + "workspaceFolder": "/var/www/html" } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ffec604fbb6d0..cb46f3ce80005 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -6,7 +6,7 @@ services: - .:/workspace:cached - /var/run/docker.sock:/var/run/docker-host.sock - ..:/var/www/html - command: /bin/sh -c "while sleep 1000; do :; done" + command: /bin/sh -c "chown -R www-data:www-data /var/www/html && service apache2 start && while sleep 1000; do :; done" ports: - 80:80 - 8080:8080 diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 9d2e3d73f98e8..e3595123b84db 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -6,3 +6,25 @@ git submodule update --init # Codespace config cp .devcontainer/codespace.config.php config/codespace.config.php + +# Set git safe.directory +git config --global --add safe.directory /var/www/html + +# Onetime installation setup +if [ ! -f "data/.devcontainer-install-complete" ]; then + echo "Running NC installation" + sudo -u www-data php occ maintenance:install \ + --verbose \ + --database=pgsql \ + --database-name=postgres \ + --database-host=127.0.0.1 \ + --database-port=5432 \ + --database-user=postgres \ + --database-pass=postgres \ + --admin-user admin \ + --admin-pass admin && \ + touch "data/.devcontainer-install-complete" +fi + +# Clear caches and stuff ... +service apache2 restart diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000000..8103dd29461d2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9003 + } + ] +} From df0ba7d1585d041e96420877b9960d3328a46f4c Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Sat, 18 Mar 2023 16:48:56 +0100 Subject: [PATCH 03/12] Use ubuntu jammy and cleanup Dockerfile Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4d579223b8dd2..b674943a58739 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,13 +1,10 @@ -FROM ubuntu:focal +FROM ubuntu:jammy ARG DEBIAN_FRONTEND=noninteractive # PHP -RUN apt-get update -y - -RUN apt install -y apache2 vim software-properties-common sudo nano - -RUN add-apt-repository ppa:ondrej/php +RUN apt-get update -y && \ + apt install -y apache2 vim software-properties-common sudo nano RUN apt-get install --no-install-recommends -y \ php8.1 \ @@ -39,8 +36,8 @@ RUN apt-get install --no-install-recommends -y \ nodejs \ npm -RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini -RUN echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini +RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \ + echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini # Autostart XDebug for apache RUN { \ @@ -54,14 +51,14 @@ RUN apt-get -y install \ ca-certificates \ curl \ gnupg-agent \ - software-properties-common -RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - -RUN add-apt-repository \ + software-properties-common && \ + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \ + add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ - stable" -RUN apt-get update -y -RUN apt-get install -y docker-ce docker-ce-cli containerd.io -RUN ln -s /var/run/docker-host.sock /var/run/docker.sock + stable" && \ + apt-get update -y && \ + apt-get install -y docker-ce docker-ce-cli containerd.io && \ + ln -s /var/run/docker-host.sock /var/run/docker.sock WORKDIR /var/www/html From 483a775490e4a51c4e34cf5470be8927249e67e2 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Mon, 27 Mar 2023 07:05:27 +0000 Subject: [PATCH 04/12] Minor DevContainer adjustments * Add gnupg2 to be able to sign commits * Make sure /var/www/html always belongs to www-data * Add Git-History plugin * Introduce dedicated entrypoint script * Store Postgres database data in volume to be persistent * Cleaner check if NC is already installed in setup.sh * Add composer to DevContainer Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 13 ++++++++++-- .devcontainer/README.md | 35 ++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 4 +++- .devcontainer/docker-compose.yml | 8 +++++++- .devcontainer/entrypoint.sh | 6 ++++++ .devcontainer/setup.sh | 7 +++---- 6 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .devcontainer/README.md create mode 100755 .devcontainer/entrypoint.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b674943a58739..642ee36d1a11b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,7 +4,7 @@ ARG DEBIAN_FRONTEND=noninteractive # PHP RUN apt-get update -y && \ - apt install -y apache2 vim software-properties-common sudo nano + apt install -y apache2 vim software-properties-common sudo nano gnupg2 RUN apt-get install --no-install-recommends -y \ php8.1 \ @@ -36,6 +36,15 @@ RUN apt-get install --no-install-recommends -y \ nodejs \ npm +# Composer +# Download the Composer installer script to a temporary file +RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php && \ + curl -sS https://composer.github.io/installer.sig -o /tmp/composer-setup.sig && \ + php -r "if (hash_file('sha384', '/tmp/composer-setup.php') !== trim(file_get_contents('/tmp/composer-setup.sig'))) { echo 'Composer installation failed, invalid hash'; exit(1); }" && \ + php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && \ + rm /tmp/composer-setup.php /tmp/composer-setup.sig + + RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \ echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini @@ -52,7 +61,7 @@ RUN apt-get -y install \ curl \ gnupg-agent \ software-properties-common && \ - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \ + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \ add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000000000..b1c8ed6d3409d --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,35 @@ +# Nextcloud DevContainer + +## Usage + +Make sure you have the [VSCode DevContainer](https://code.visualstudio.com/docs/devcontainers/containers) extensions installed. If you open the project, VSCode will ask you if you want to open it inside of the DevContainer. If that's not the case, use F1→*Dev Containers: Open Folder in Container*. + +Alternatively open the project directly in [GitHub Codespaces](https://github.com/features/codespaces). + +That's already it. Everything else will be configured automatically by the Containers startup routine. + +## Credentials + +On first start the Container installs and configures Nextcloud with the following credentials: + +**Nextcloud Admin Login** + +Username: `admin`
+Password: `admin` + +**Postgres credentials** + +Username: `postgres`
+Password: `postgres`
+Database: `postgres` + +## Services + +The following services will be started: + +| Service | Local port | Description | +|---------|------------|-------------| +| Nextcloud (served via Apache) | `80` | The main application | +| Mailhog | `8025` | SMTP email delivery for testing | +| Adminer | `8080` | Database viewer. Use credentials from above and connect to `localhost:5432` to get access to the NC database | + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2f197a58fedfc..709744e3f0d61 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,7 @@ "dockerComposeFile": "docker-compose.yml", "service": "nextclouddev", "postCreateCommand": ".devcontainer/setup.sh", + "postStartCommand": "chown -R www-data:www-data /var/www/html", "forwardPorts": [ 80, 8080, @@ -14,7 +15,8 @@ "felixfbecker.php-debug", "felixfbecker.php-intellisense", "ms-azuretools.vscode-docker", - "xdebug.php-debug" + "xdebug.php-debug", + "donjayamanne.githistory" ], "settings": { "php.suggest.basic": false diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index cb46f3ce80005..a30bba74a6653 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -6,7 +6,7 @@ services: - .:/workspace:cached - /var/run/docker.sock:/var/run/docker-host.sock - ..:/var/www/html - command: /bin/sh -c "chown -R www-data:www-data /var/www/html && service apache2 start && while sleep 1000; do :; done" + command: /var/www/html/.devcontainer/entrypoint.sh ports: - 80:80 - 8080:8080 @@ -17,6 +17,9 @@ services: restart: always environment: POSTGRES_PASSWORD: postgres + PGDATA: /data/postgres + volumes: + - db:/data/postgres network_mode: service:nextclouddev adminer: @@ -28,3 +31,6 @@ services: image: mailhog/mailhog restart: always network_mode: service:nextclouddev + +volumes: + db: diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh new file mode 100755 index 0000000000000..a2aecb7ecb70a --- /dev/null +++ b/.devcontainer/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Set proper permissions and start webserver +chown -R www-data:www-data /var/www/html && service apache2 start + +while sleep 1000; do :; done diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index e3595123b84db..aec20f3b4dc2b 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -9,9 +9,10 @@ cp .devcontainer/codespace.config.php config/codespace.config.php # Set git safe.directory git config --global --add safe.directory /var/www/html +git config --global --add safe.directory /var/www/html/3rdparty # Onetime installation setup -if [ ! -f "data/.devcontainer-install-complete" ]; then +if [[ ! $(sudo -u www-data php occ status) =~ installed:[[:space:]]*true ]]; then echo "Running NC installation" sudo -u www-data php occ maintenance:install \ --verbose \ @@ -22,9 +23,7 @@ if [ ! -f "data/.devcontainer-install-complete" ]; then --database-user=postgres \ --database-pass=postgres \ --admin-user admin \ - --admin-pass admin && \ - touch "data/.devcontainer-install-complete" + --admin-pass admin fi -# Clear caches and stuff ... service apache2 restart From 6677e2295ca2da8915f315aa403d0ec249526f07 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Fri, 31 Mar 2023 06:40:04 +0000 Subject: [PATCH 05/12] Dedicated DevContainer user + NVM * Use dedicated DevContainer user to run Apache (ensure file permissions) * Install NVM for node Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 20 ++++++++++++--- .devcontainer/README.md | 39 +++++++++++++++++++++++++++++- .devcontainer/codespace.config.php | 6 +++-- .devcontainer/devcontainer.json | 4 +-- .devcontainer/entrypoint.sh | 3 +-- .devcontainer/setup.sh | 6 ++--- 6 files changed, 64 insertions(+), 14 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 642ee36d1a11b..99755ca22898c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -33,18 +33,15 @@ RUN apt-get install --no-install-recommends -y \ curl \ lsof \ make \ - nodejs \ - npm + unzip # Composer -# Download the Composer installer script to a temporary file RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php && \ curl -sS https://composer.github.io/installer.sig -o /tmp/composer-setup.sig && \ php -r "if (hash_file('sha384', '/tmp/composer-setup.php') !== trim(file_get_contents('/tmp/composer-setup.sig'))) { echo 'Composer installation failed, invalid hash'; exit(1); }" && \ php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && \ rm /tmp/composer-setup.php /tmp/composer-setup.sig - RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \ echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini @@ -70,4 +67,19 @@ RUN apt-get -y install \ apt-get install -y docker-ce docker-ce-cli containerd.io && \ ln -s /var/run/docker-host.sock /var/run/docker.sock +# Dedicated DevContainer user runs Apache +ENV APACHE_RUN_USER=devcontainer +ENV APACHE_RUN_GROUP=devcontainer +RUN useradd -ms /bin/bash ${APACHE_RUN_USER} && \ + adduser ${APACHE_RUN_USER} sudo && \ + echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \ + sed -ri "s/^export APACHE_RUN_USER=.*$/export APACHE_RUN_USER=${APACHE_RUN_USER}/" "/etc/apache2/envvars" && \ + sed -ri "s/^export APACHE_RUN_GROUP=.*$/export APACHE_RUN_GROUP=${APACHE_RUN_GROUP}/" "/etc/apache2/envvars" + +USER devcontainer + +# NVM +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash +RUN bash --login -i -c 'source /home/devcontainer/.bashrc && nvm install 16' + WORKDIR /var/www/html diff --git a/.devcontainer/README.md b/.devcontainer/README.md index b1c8ed6d3409d..da540711fc871 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -31,5 +31,42 @@ The following services will be started: |---------|------------|-------------| | Nextcloud (served via Apache) | `80` | The main application | | Mailhog | `8025` | SMTP email delivery for testing | -| Adminer | `8080` | Database viewer. Use credentials from above and connect to `localhost:5432` to get access to the NC database | +| Adminer | `8080` | Database viewer. Use credentials from above and connect to `localhost` to get access to the NC database | +## Permissions + +The container runs with the user `devcontainer` who is also running the Apache2 process. All mounted source files have +proper permissions so that this user can access everything which is inside the current workspace. If you need to +get root permissions for whatever reason, use `sudo su` or `sudo ` (for example `sudo service apache2 restart`). +Everything else (like building the application, adjusting files, ...) should be done as `devcontainer` user. + +## NodeJs and NVM + +The container comes with [`nvm`](https://github.com/nvm-sh/nvm) and Node 16 installed. This should be sufficient to +build Nextcloud Core sources via `make`. If you need a different Node Version (for example for +app development), you can easily switch between different versions by running: + +```bash +# Install and use Node 14 +nvm install 14 +nvm use 14 + +# Check version +node -v + +# Switch back to Node 16 +nvm use 16 + +# Check version +node -v +``` + +Note that `nvm` is only installed for the user `devcontainer` and won't work out of the box for +any other user. + +## Debugging + +The Apache webserver is already configured to automatically try to connect to a debugger process +listening on port `9003`. To start the VSCode debugger process, use the delivered debug profile `Listen for XDebug`. +After you started the VSCode debugger, just navigate to the appropriate Nextcloud URL to get your +debug hits. \ No newline at end of file diff --git a/.devcontainer/codespace.config.php b/.devcontainer/codespace.config.php index c191698c2565c..3c5257635400b 100644 --- a/.devcontainer/codespace.config.php +++ b/.devcontainer/codespace.config.php @@ -14,7 +14,9 @@ ]; if(is_string($codespaceName) && !empty($codespaceName) && is_string($codespaceDomain) && !empty($codespaceDomain)) { - $CONFIG['overwritehost'] = $codespaceName . '-80.' . $codespaceDomain; + $host = $codespaceName . '-80.' . $codespaceDomain; + $CONFIG['overwritehost'] = $host; + $CONFIG['overwrite.cli.url'] = 'https://' . $host; $CONFIG['overwriteprotocol'] = 'https'; - $CONFIG['trusted_domains'] = [ $CONFIG['overwritehost'] ]; + $CONFIG['trusted_domains'] = [ $host ]; } diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 709744e3f0d61..3fb1bf42e4406 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,6 @@ "dockerComposeFile": "docker-compose.yml", "service": "nextclouddev", "postCreateCommand": ".devcontainer/setup.sh", - "postStartCommand": "chown -R www-data:www-data /var/www/html", "forwardPorts": [ 80, 8080, @@ -23,5 +22,6 @@ } } }, - "workspaceFolder": "/var/www/html" + "workspaceFolder": "/var/www/html", + "remoteUser": "devcontainer" } diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh index a2aecb7ecb70a..952f6f8aad65a 100755 --- a/.devcontainer/entrypoint.sh +++ b/.devcontainer/entrypoint.sh @@ -1,6 +1,5 @@ #!/bin/bash -# Set proper permissions and start webserver -chown -R www-data:www-data /var/www/html && service apache2 start +sudo service apache2 start while sleep 1000; do :; done diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index aec20f3b4dc2b..2b61f3f9190b6 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -12,9 +12,9 @@ git config --global --add safe.directory /var/www/html git config --global --add safe.directory /var/www/html/3rdparty # Onetime installation setup -if [[ ! $(sudo -u www-data php occ status) =~ installed:[[:space:]]*true ]]; then +if [[ ! $(sudo -u ${APACHE_RUN_USER} php occ status) =~ installed:[[:space:]]*true ]]; then echo "Running NC installation" - sudo -u www-data php occ maintenance:install \ + sudo -u ${APACHE_RUN_USER} php occ maintenance:install \ --verbose \ --database=pgsql \ --database-name=postgres \ @@ -26,4 +26,4 @@ if [[ ! $(sudo -u www-data php occ status) =~ installed:[[:space:]]*true ]]; the --admin-pass admin fi -service apache2 restart +sudo service apache2 restart From f3046ed18c89395d81d9194fee67d2eb0ea589ad Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Fri, 31 Mar 2023 09:14:24 +0000 Subject: [PATCH 06/12] Configure line ending to let shell scripts work in Windows ENV Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 7f8fd14dd1d6e..baaf0e69fe00a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ /dist/* binary /package-lock.json merge=binary /core/css/*.css* binary +/.devcontainer/*.sh text eol=lf From ec4f3ff881bc2bd49b2834dd7f0f5f70bf21015a Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Fri, 31 Mar 2023 09:25:24 +0000 Subject: [PATCH 07/12] Move git safe.directory to earlier stage Signed-off-by: GitHub Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/setup.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 2b61f3f9190b6..aac1f82f0839c 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -2,15 +2,16 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" >/dev/null 2>&1 && pwd )" cd $DIR/ -git submodule update --init - -# Codespace config -cp .devcontainer/codespace.config.php config/codespace.config.php # Set git safe.directory git config --global --add safe.directory /var/www/html git config --global --add safe.directory /var/www/html/3rdparty +git submodule update --init + +# Codespace config +cp .devcontainer/codespace.config.php config/codespace.config.php + # Onetime installation setup if [[ ! $(sudo -u ${APACHE_RUN_USER} php occ status) =~ installed:[[:space:]]*true ]]; then echo "Running NC installation" From b4372f6c4e51ddbe820cdb8b4c3d4717b2244da9 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Mon, 3 Apr 2023 09:42:27 +0000 Subject: [PATCH 08/12] Add .vscode to expected files list Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- build/files-checker.php | 1 + 1 file changed, 1 insertion(+) diff --git a/build/files-checker.php b/build/files-checker.php index c06e5ea81dc39..9c9cc56b087f6 100644 --- a/build/files-checker.php +++ b/build/files-checker.php @@ -44,6 +44,7 @@ '.tag', '.tx', '.user.ini', + '.vscode', '3rdparty', 'AUTHORS', 'CHANGELOG.md', From b35db66ca42e32429b1a97c9789fd3f08ff81b0a Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Tue, 4 Apr 2023 16:37:39 +0000 Subject: [PATCH 09/12] Enbale apcu in devcontainer CLI Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .devcontainer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 99755ca22898c..6605e2b6499ab 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -43,7 +43,8 @@ RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php && \ rm /tmp/composer-setup.php /tmp/composer-setup.sig RUN echo "xdebug.remote_enable = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \ - echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini + echo "xdebug.remote_autostart = 1" >> /etc/php/8.1/cli/conf.d/20-xdebug.ini && \ + echo "apc.enable_cli=1" >> /etc/php/8.1/cli/conf.d/20-apcu.ini # Autostart XDebug for apache RUN { \ From 0867c6657cec46514a0b44129c5eb163dd452f12 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Thu, 6 Apr 2023 14:56:54 +0000 Subject: [PATCH 10/12] Move launch.json to .devcontainer and copy on start Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- {.vscode => .devcontainer}/launch.json | 0 .devcontainer/setup.sh | 3 +++ build/files-checker.php | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) rename {.vscode => .devcontainer}/launch.json (100%) diff --git a/.vscode/launch.json b/.devcontainer/launch.json similarity index 100% rename from .vscode/launch.json rename to .devcontainer/launch.json diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index aac1f82f0839c..3485d4f7257c6 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -12,6 +12,9 @@ git submodule update --init # Codespace config cp .devcontainer/codespace.config.php config/codespace.config.php +# VSCode debugger profile +mkdir -p .vscode && cp .devcontainer/launch.json .vscode/launch.json + # Onetime installation setup if [[ ! $(sudo -u ${APACHE_RUN_USER} php occ status) =~ installed:[[:space:]]*true ]]; then echo "Running NC installation" diff --git a/build/files-checker.php b/build/files-checker.php index 9c9cc56b087f6..c06e5ea81dc39 100644 --- a/build/files-checker.php +++ b/build/files-checker.php @@ -44,7 +44,6 @@ '.tag', '.tx', '.user.ini', - '.vscode', '3rdparty', 'AUTHORS', 'CHANGELOG.md', From d9c66ba3b1038794fba85195e6d25c28b47e573b Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Mon, 10 Apr 2023 12:00:38 +0000 Subject: [PATCH 11/12] Distinguish 'done' from 'configuring' in 2FA When there is a token in the session for which the user is still [setting up 2FA](https://raw.githubusercontent.com/nextcloud/twofactor_totp/master/screenshots/settings.png), setting `self::SESSION_UID_DONE` ("two_factor_auth_passed") is a misnomer. AFAICT, everything works fine if you set nothing into the session and just return 'false' from this if-statement, but in case there is some code (now or in the future) that needs to know if the user is configuring 2FA, to play it safe I would suggest storing `self::SESSION_UID_CONFIGURING` ("two_factor_auth_configuring") into the session. Signed-off-by: Michiel de Jong Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- .../Authentication/TwoFactorAuth/Manager.php | 3 +- .../TwoFactorAuth/ManagerTest.php | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 7e115cf9b4221..3e71d0787b313 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -52,6 +52,7 @@ class Manager { public const SESSION_UID_KEY = 'two_factor_auth_uid'; public const SESSION_UID_DONE = 'two_factor_auth_passed'; + public const SESSION_UID_CONFIGURING = 'two_factor_auth_configuring'; public const REMEMBER_LOGIN = 'two_factor_remember_login'; public const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; @@ -359,7 +360,7 @@ public function needsSecondFactor(IUser $user = null): bool { $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); if (!\in_array((string) $tokenId, $tokensNeeding2FA, true)) { - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); + $this->session->set(self::SESSION_UID_CONFIGURING, $user->getUID()); return false; } } catch (InvalidTokenException|SessionNotAvailableException $e) { diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index da11b11e53780..02780e0a874f5 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -678,6 +678,39 @@ public function testNeedsSecondFactorSessionAuthFailDBPass() { $this->assertFalse($this->manager->needsSecondFactor($user)); } + public function testNeedsSecondFactorWhileConfiguring() { + $user = $this->createMock(IUser::class); + $user->method('getUID') + ->willReturn('user'); + + $this->session->method('exists') + ->willReturn(false); + $this->session->method('getId') + ->willReturn('mysessionid'); + + $token = $this->createMock(OC\Authentication\Token\IToken::class); + $token->method('getId') + ->willReturn(40); + + $this->tokenProvider->method('getToken') + ->with('mysessionid') + ->willReturn($token); + + $this->config->method('getUserKeys') + ->with('user', 'login_token_2fa') + ->willReturn([ + '42', '43', '44' + ]); + + // the user is still configuring 2FA with token 40 + $this->session->expects($this->once()) + ->method('set') + ->with(Manager::SESSION_UID_CONFIGURING, 'user'); + + // 2FA should not be required if configuration is not complete + $this->assertFalse($this->manager->needsSecondFactor($user)); + } + public function testNeedsSecondFactorInvalidToken() { $this->prepareNoProviders(); From 9bad67ef8fea0701351cd6a2082aaa7c8c578b1a Mon Sep 17 00:00:00 2001 From: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:17:58 +0000 Subject: [PATCH 12/12] fix test failing in drone Signed-off-by: MohammadReza vahedi <34796044+mrvahedi68@users.noreply.github.com> --- tests/lib/Authentication/TwoFactorAuth/ManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 02780e0a874f5..7aa1fe9668cbc 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -673,7 +673,7 @@ public function testNeedsSecondFactorSessionAuthFailDBPass() { $this->session->expects($this->once()) ->method('set') - ->with(Manager::SESSION_UID_DONE, 'user'); + ->with(Manager::SESSION_UID_CONFIGURING, 'user'); $this->assertFalse($this->manager->needsSecondFactor($user)); }