Selaa lähdekoodia

Improve Dev Container (#5423)

* Improve Dev Container
PHPStan was failing in Dev Container

* Update Docker to Alpine Linux 3.18
* New DATA_PATH environment variable

* README
Alexandre Alapetite 2 vuotta sitten
vanhempi
commit
0292b2f1f3

+ 2 - 1
.devcontainer/Dockerfile

@@ -1,4 +1,4 @@
-FROM alpine:3.17
+FROM alpine:3.18
 
 ENV TZ UTC
 SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
@@ -26,6 +26,7 @@ RUN adduser --ingroup www-data --disabled-password developer && \
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV 'development'
 ENV LISTEN '0.0.0.0:8080'
 

+ 22 - 0
.devcontainer/README.md

@@ -0,0 +1,22 @@
+# Dev Container for FreshRSS
+
+This is a [Development Container](https://containers.dev) to provide a one-click full development environment
+with all the needed tools and configurations, to develop and test [FreshRSS](https://github.com/FreshRSS/FreshRSS/).
+
+It can be used on your local machine (see for instance the [Dev Containers extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)),
+or as [GitHub Codespaces](https://github.com/features/codespaces) simply in a Web browser:
+
+[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=edge&repo=6322699)
+
+## Test instance of FreshRSS
+
+A test instance of FreshRSS is automatically started as visible from the *Ports* tab: check the *Local Address* column, and click on the *Open in browser* 🌐 icon.
+It runs the FreshRSS code that you are currently editing.
+
+## Software tests
+
+Running the tests can be done directly from the built-in terminal, e.g.:
+
+```sh
+make test-all
+```

+ 9 - 0
.devcontainer/devcontainer.json

@@ -4,7 +4,15 @@
 	"build": {
 		"dockerfile": "Dockerfile"
 	},
+	"containerEnv": {
+		"DATA_PATH": "/home/developer/freshrss-data"
+	},
 	"customizations": {
+		"codespaces": {
+			"openFiles": [
+				".devcontainer/README.md"
+			]
+		},
 		"vscode": {
 			"extensions": [
 				"bmewburn.vscode-intelephense-client",
@@ -13,6 +21,7 @@
 				"eamodio.gitlens",
 				"EditorConfig.EditorConfig",
 				"foxundermoon.shell-format",
+				"GitHub.vscode-pull-request-github",
 				"mrmlnc.vscode-apache",
 				"ms-azuretools.vscode-docker",
 				"redhat.vscode-yaml",

+ 1 - 6
.devcontainer/postCreateCommand.sh

@@ -4,14 +4,9 @@ ln -s "$(pwd)" /var/www/FreshRSS
 
 cp ./Docker/*.Apache.conf /etc/apache2/conf.d/
 
-cat <<EOT >./constants.local.php
-<?php
-define('DATA_PATH', '/home/developer/freshrss-data');
-EOT
-
 ./Docker/entrypoint.sh
 
 chown -R developer:www-data /home/developer/freshrss-data
-chmod -R g+w /home/developer/freshrss-data
+chmod -R g+rwX /home/developer/freshrss-data
 
 httpd

+ 1 - 0
Docker/Dockerfile

@@ -52,6 +52,7 @@ RUN sed -r -i "/^\s*(CustomLog|ErrorLog|Listen) /s/^/#/" /etc/apache2/apache2.co
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV ''
 ENV LISTEN ''
 

+ 1 - 0
Docker/Dockerfile-Alpine

@@ -50,6 +50,7 @@ RUN rm -f /etc/apache2/conf.d/languages.conf /etc/apache2/conf.d/info.conf \
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV ''
 ENV LISTEN ''
 

+ 1 - 0
Docker/Dockerfile-Newest

@@ -52,6 +52,7 @@ RUN rm -f /etc/apache2/conf.d/languages.conf /etc/apache2/conf.d/info.conf \
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV ''
 ENV LISTEN ''
 

+ 1 - 0
Docker/Dockerfile-Oldest

@@ -52,6 +52,7 @@ RUN rm -f /etc/apache2/conf.d/languages.conf /etc/apache2/conf.d/info.conf \
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV ''
 ENV LISTEN ''
 

+ 1 - 0
Docker/Dockerfile-QEMU-ARM

@@ -64,6 +64,7 @@ RUN rm /usr/bin/qemu-* /var/www/FreshRSS/Docker/qemu-*
 ENV COPY_LOG_TO_SYSLOG On
 ENV COPY_SYSLOG_TO_STDERR On
 ENV CRON_MIN ''
+ENV DATA_PATH ''
 ENV FRESHRSS_ENV ''
 ENV LISTEN ''
 

+ 1 - 0
Docker/README.md

@@ -83,6 +83,7 @@ and with newer packages in general (Apache, PHP).
 
 * `TZ`: (default is `UTC`) A [server timezone](http://php.net/timezones)
 * `CRON_MIN`: (default is disabled) Define minutes for the built-in cron job to automatically refresh feeds (see below for more advanced options)
+* `DATA_PATH`: (default is empty, defined by `./constants.local.php` or `./constants.php`) Defines the path for writeable data.
 * `FRESHRSS_ENV`: (default is `production`) Enables additional development information if set to `development` (increases the level of logging and ensures that errors are displayed) (see below for more development options)
 * `COPY_LOG_TO_SYSLOG`: (default is `On`) Copy all the logs to syslog
 * `COPY_SYSLOG_TO_STDERR`: (default is `On`) Copy syslog to Standard Error so that it is visible in docker logs

+ 1 - 1
README.fr.md

@@ -30,7 +30,7 @@ Enfin, il permet l’ajout d’[extensions](#extensions) pour encore plus de per
 Les demandes de fonctionnalités, rapports de bugs, et autres contributions sont les bienvenues. Privilégiez pour cela des [demandes sur GitHub](https://github.com/FreshRSS/FreshRSS/issues).
 Nous sommes une communauté amicale.
 
-Pour faciliter les contributions, l’option suivante est disponible :
+Pour faciliter les contributions, [l’option suivante](.devcontainer/README.md) est disponible :
 
 [![Ouvrir dans GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=edge&repo=6322699)
 

+ 1 - 1
README.md

@@ -30,7 +30,7 @@ Finally, it supports [extensions](#extensions) for further tuning.
 Feature requests, bug reports, and other contributions are welcome. The best way is to [open an issue on GitHub](https://github.com/FreshRSS/FreshRSS/issues).
 We are a friendly community.
 
-To facilitate contributions, the following option is available:
+To facilitate contributions, the [following option](.devcontainer/README.md) is available:
 
 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=edge&repo=6322699)
 

+ 6 - 1
constants.php

@@ -40,7 +40,12 @@ defined('COPY_SYSLOG_TO_STDERR') or define('COPY_SYSLOG_TO_STDERR', filter_var(g
 defined('MAX_LOG_SIZE') or define('MAX_LOG_SIZE', 1048576);
 
 //This directory must be writable
-defined('DATA_PATH') or define('DATA_PATH', FRESHRSS_PATH . '/data');
+$dataPath = getenv('DATA_PATH');
+if (is_string($dataPath) && $dataPath !== '') {
+	define('DATA_PATH', $dataPath);
+} else {
+	defined('DATA_PATH') or define('DATA_PATH', FRESHRSS_PATH . '/data');
+}
 
 defined('UPDATE_FILENAME') or define('UPDATE_FILENAME', DATA_PATH . '/update.php');
 defined('USERS_PATH') or define('USERS_PATH', DATA_PATH . '/users');

+ 5 - 9
lib/lib_install.php

@@ -40,15 +40,11 @@ function checkRequirements(string $dbType = ''): array {
 	$xml = function_exists('xml_parser_create');
 	$json = function_exists('json_encode');
 	$mbstring = extension_loaded('mbstring');
-	// @phpstan-ignore-next-line
-	$data = DATA_PATH != '' && touch(DATA_PATH . '/index.html');	// is_writable() is not reliable for a folder on NFS
-	// @phpstan-ignore-next-line
-	$cache = CACHE_PATH != '' && touch(CACHE_PATH . '/index.html');
-	$tmp = TMP_PATH != '' && is_writable(TMP_PATH);
-	// @phpstan-ignore-next-line
-	$users = USERS_PATH != '' && touch(USERS_PATH . '/index.html');
-	// @phpstan-ignore-next-line
-	$favicons = DATA_PATH != '' && touch(DATA_PATH . '/favicons/index.html');
+	$data = is_dir(DATA_PATH) && touch(DATA_PATH . '/index.html');	// is_writable() is not reliable for a folder on NFS
+	$cache = is_dir(CACHE_PATH) && touch(CACHE_PATH . '/index.html');
+	$tmp = is_dir(TMP_PATH) && is_writable(TMP_PATH);
+	$users = is_dir(USERS_PATH) && touch(USERS_PATH . '/index.html');
+	$favicons = is_dir(DATA_PATH) && touch(DATA_PATH . '/favicons/index.html');
 
 	return array(
 		'php' => $php ? 'ok' : 'ko',

+ 7 - 13
lib/lib_rss.php

@@ -724,26 +724,20 @@ function check_install_php(): array {
 	);
 }
 
-
 /**
  * Check different data files and directories exist.
- *
  * @return array<string,bool> of tested values.
  */
 function check_install_files(): array {
-	return array(
-		// @phpstan-ignore-next-line
-		'data' => DATA_PATH && touch(DATA_PATH . '/index.html'),	// is_writable() is not reliable for a folder on NFS
-		// @phpstan-ignore-next-line
-		'cache' => CACHE_PATH && touch(CACHE_PATH . '/index.html'),
-		// @phpstan-ignore-next-line
-		'users' => USERS_PATH && touch(USERS_PATH . '/index.html'),
-		'favicons' => touch(DATA_PATH . '/favicons/index.html'),
-		'tokens' => touch(DATA_PATH . '/tokens/index.html'),
-	);
+	return [
+		'data' => is_dir(DATA_PATH) && touch(DATA_PATH . '/index.html'),	// is_writable() is not reliable for a folder on NFS
+		'cache' => is_dir(CACHE_PATH) && touch(CACHE_PATH . '/index.html'),
+		'users' => is_dir(USERS_PATH) && touch(USERS_PATH . '/index.html'),
+		'favicons' => is_dir(DATA_PATH) && touch(DATA_PATH . '/favicons/index.html'),
+		'tokens' => is_dir(DATA_PATH) && touch(DATA_PATH . '/tokens/index.html'),
+	];
 }
 
-
 /**
  * Check database is well-installed.
  *