diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d368b78 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +.git +.gitignore +.scrutinizer.yml +.travis.yml +CHANGELOG +Dockerfile +INSTALL.md +LICENSE +Makefile +README.md +VERSION +_syno_package +hooks +packages +phpunit.xml.dist +selftest.php +tests \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 199400a..31ac2b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,16 @@ -FROM alpine:3.5 -MAINTAINER Julien Del-Piccolo -ARG BRANCH="master" -ARG COMMIT="" -ENV SSPKS_BRANCH=${BRANCH} -ENV SSPKS_COMMIT=${COMMIT} +FROM jdel/alpine:3.8 +LABEL maintainer="Julien Del-Piccolo " LABEL branch=${BRANCH} LABEL commit=${COMMIT} -RUN echo "BRANCH: ${BRANCH}" \ - && echo "COMMIT: ${COMMIT}" \ - && echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}" \ - && echo "TRAVIS_COMMIT: ${TRAVIS_COMMIT}" \ - && apk update && apk add --no-cache supervisor apache2 php5-apache2 php5-phar php5-ctype php5-json \ - && apk add --virtual=.build-dependencies openssl php5 php5-openssl git \ - && rm -rf /var/www/localhost/htdocs \ - && wget -O /var/www/localhost/sspks.zip https://github.com/jdel/sspks/archive/${COMMIT}.zip \ - && unzip /var/www/localhost/sspks.zip -d /var/www/localhost/ \ - && rm /var/www/localhost/sspks.zip \ - && mv /var/www/localhost/sspks-*/ /var/www/localhost/htdocs/ && cd /var/www/localhost/htdocs \ - && wget -q -O /usr/local/bin/composer https://getcomposer.org/download/1.3.1/composer.phar \ +USER root + +COPY . /var/www/localhost/htdocs/ + +RUN apk update && apk add --no-cache apache2 php7-apache2 php7-phar php7-ctype php7-json \ + && apk add --virtual=.build-dependencies curl openssl php7 php7-openssl git \ + && rm -f /var/www/localhost/htdocs/index.html \ + && curl -sSL https://getcomposer.org/download/1.6.5/composer.phar -o /usr/local/bin/composer \ && chmod +x /usr/local/bin/composer \ && cd /var/www/localhost/htdocs \ && composer install --no-dev \ @@ -27,14 +19,13 @@ RUN echo "BRANCH: ${BRANCH}" \ && rm -rf /var/cache/apk/* \ && mkdir /run/apache2 \ && sed -i 's/Listen 80/Listen 8080/' /etc/apache2/httpd.conf \ - && sed -i 's/^variables_order = "GPCS"/variables_order = "EGPCS"/' /etc/php5/php.ini \ + && sed -i 's/^variables_order = "GPCS"/variables_order = "EGPCS"/' /etc/php7/php.ini \ && ln -sf /dev/stdout /var/log/apache2/access.log \ - && ln -sf /dev/stderr /var/log/apache2/error.log - -COPY ./docker/supervisord.conf /usr/local/etc/supervisor/ + && ln -sf /dev/stderr /var/log/apache2/error.log \ + && ln -sf /var/www/localhost/htdocs/packages /packages \ + && ln -sf /var/www/localhost/htdocs/cache /cache EXPOSE 8080 -VOLUME "/var/www/localhost/htdocs/packages" -VOLUME "/var/www/localhost/htdocs/cache" -VOLUME "/tmp" -CMD ["/usr/bin/supervisord", "-c", "/usr/local/etc/supervisor/supervisord.conf"] +VOLUME "/packages" +VOLUME "/cache" +CMD ["/usr/sbin/httpd", "-DFOREGROUND"] diff --git a/README.md b/README.md index e6fa7d4..becaa59 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,40 @@ Installation Please see the [INSTALL](INSTALL.md) file for instructions. +Docker +=========== + +Docker images are built automatically from this repository and are available on [Docker Hub](https://hub.docker.com/r/jdel/sspks/tags/). + +In order to use them you will need a working installation of Docker. + +Simply run the following command: + +```bash +docker run -d --name sspks \ + -v /path/to/your/local/packages:/packages \ + -v /path/to/your/local/cache:/cache \ + -p 9999:8080 \ + -e SSPKS_SITE_NAME="My Packages" \ + -e SSPKS_PACKAGES_DISTRIBUTOR_URL=https://cake.com \ + jdel/sspks:v1.1.3 +``` + +More environment variables are available to configure `SSPKS`: + + - SSPKS_SITE_NAME + - SSPKS_SITE_THEME + - SSPKS_SITE_REDIRECTINDEX + - SSPKS_PACKAGES_FILE_MASK + - SSPKS_PACKAGES_MAINTAINER + - SSPKS_PACKAGES_MAINTAINER_URL + - SSPKS_PACKAGES_DISTRIBUTOR + - SSPKS_PACKAGES_DISTRIBUTOR_URL + - SSPKS_PACKAGES_SUPPORT_URL + +In the command above, replace `/path/to/your/local/packages` with the directory containing your packages, `/path/to/your/local/cache` with the directory that will hold the cache files and `-p 9999` with the port you intend to serve packages on. + +Should you want SSL/TLS (you really should), you need to handle SSL/TLS termination externally, for example with [Traefik](https://traefik.io/) that will automatically fetch [Let's Encrypt](https://letsencrypt.org/) certificates for you. Contribute ========== diff --git a/VERSION b/VERSION index 4ebdf24..781dcb0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2b +1.1.3 diff --git a/conf/sspks.yaml b/conf/sspks.yaml index 151e9fd..10335e9 100644 --- a/conf/sspks.yaml +++ b/conf/sspks.yaml @@ -11,6 +11,7 @@ packages: maintainer_url: "" distributor: "" distributor_url: "" + support_url: "" # ALL PATHS MUST BE RELATIVE TO THE ROOT # DIRECTORY (where the index.php is located) diff --git a/docker/supervisord.conf b/docker/supervisord.conf deleted file mode 100644 index 6764e9f..0000000 --- a/docker/supervisord.conf +++ /dev/null @@ -1,12 +0,0 @@ -[supervisord] -logfile=/dev/null -pidfile=/var/run/supervisord.pid -nodaemon=true - -[program:apache2] -command=/usr/sbin/httpd -DFOREGROUND -redirect_stderr=true -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -auto_start=true -autorestart=true \ No newline at end of file diff --git a/lib/SSpkS/Config.php b/lib/SSpkS/Config.php index 69fb2e5..3f543f8 100644 --- a/lib/SSpkS/Config.php +++ b/lib/SSpkS/Config.php @@ -66,6 +66,30 @@ public function __construct($basePath, $cfgFile = 'conf/sspks.yaml') if ($this->envVarIsNotEmpty('SSPKS_SITE_REDIRECTINDEX')) { $config['site']['redirectindex'] = $_ENV['SSPKS_SITE_REDIRECTINDEX']; } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_FILE_MASK')) { + $config['packages']['file_mask'] = $_ENV['SSPKS_PACKAGES_FILE_MASK']; + } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_MAINTAINER')) { + $config['packages']['maintainer'] = $_ENV['SSPKS_PACKAGES_MAINTAINER']; + } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_MAINTAINER_URL')) { + $config['packages']['maintainer_url'] = $_ENV['SSPKS_PACKAGES_MAINTAINER_URL']; + } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_DISTRIBUTOR')) { + $config['packages']['distributor'] = $_ENV['SSPKS_PACKAGES_DISTRIBUTOR']; + } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_DISTRIBUTOR_URL')) { + $config['packages']['distributor_url'] = $_ENV['SSPKS_PACKAGES_DISTRIBUTOR_URL']; + } + + if ($this->envVarIsNotEmpty('SSPKS_PACKAGES_SUPPORT_URL')) { + $config['packages']['support_url'] = $_ENV['SSPKS_PACKAGES_SUPPORT_URL']; + } $this->config = $config; $this->config['basePath'] = $this->basePath; diff --git a/lib/SSpkS/Output/JsonOutput.php b/lib/SSpkS/Output/JsonOutput.php index deb8603..134ee19 100644 --- a/lib/SSpkS/Output/JsonOutput.php +++ b/lib/SSpkS/Output/JsonOutput.php @@ -121,6 +121,7 @@ private function packageToJson($pkg, $language) 'maintainer_url' => $this->ifEmpty($pkg, 'maintainer_url', $this->config->packages['maintainer_url']), 'distributor' => $this->ifEmpty($pkg, 'distributor', $this->config->packages['distributor']), 'distributor_url' => $this->ifEmpty($pkg, 'distributor_url', $this->config->packages['distributor_url']), + 'support_url' => $this->ifEmpty($pkg, 'support_url', $this->config->packages['support_url']), 'changelog' => $this->ifEmpty($pkg, 'changelog', ''), 'thirdparty' => true, 'category' => 0, @@ -129,6 +130,7 @@ private function packageToJson($pkg, $language) 'silent_install' => $this->ifEmpty($pkg, 'silent_install', false), 'silent_uninstall' => $this->ifEmpty($pkg, 'silent_uninstall', false), 'silent_upgrade' => $this->ifEmpty($pkg, 'silent_upgrade', false), + 'auto_upgrade_from' => $this->ifEmpty($pkg, 'auto_upgrade_from'), 'beta' => $pkg->beta, // beta channel ); return $packageJSON; diff --git a/lib/SSpkS/Package/Package.php b/lib/SSpkS/Package/Package.php index aa46459..be7b61d 100644 --- a/lib/SSpkS/Package/Package.php +++ b/lib/SSpkS/Package/Package.php @@ -15,6 +15,7 @@ * @property string $maintainer_url URL of maintainer's web page * @property string $distributor Package distributor * @property string $distributor_url URL of distributor's web page + * @property string $support_url URL of support web page * @property array $arch List of supported architectures, or 'noarch' * @property array $thumbnail List of thumbnail files * @property array $thumbnail_url List of thumbnail URLs @@ -26,6 +27,7 @@ * @property bool $silent_install Allow silent install * @property bool $silent_uninstall Allow silent uninstall * @property bool $silent_upgrade Allow silent upgrade + * @property bool $auto_upgrade_from Allow auto upgrade if version is newer than this field * @property bool $qinst Allow silent install * @property bool $qupgrade Allow silent upgrade * @property bool $qstart Allow automatic start after install @@ -200,11 +202,11 @@ public function extractIfMissing($inPkgName, $targetFile) $tmp_dir = sys_get_temp_dir(); $free_tmp = @disk_free_space($tmp_dir); if (!empty($free_tmp) && $free_tmp < 2048) { - throw new \Exception('TMP folder only has ' . $free_tmp . ' Bytes space available. Disk full!'); + throw new \Exception('TMP folder only has ' . $free_tmp . ' Bytes available. Disk full!'); } - $free = @disk_free_space(dirname($targetFile)); + $free = @disk_free_space(dirname($targetFile)); if (!empty($free) && $free < 2048) { - throw new \Exception('Package folder only has ' . $free . ' Bytes space available. Disk full!'); + throw new \Exception('Package folder only has ' . $free . ' Bytes available. Disk full!'); } try { $p = new \PharData($this->filepath, \Phar::CURRENT_AS_FILEINFO | \Phar::KEY_AS_FILENAME); diff --git a/tests/JsonOutputTest.php b/tests/JsonOutputTest.php index 43ef5cd..c72482b 100644 --- a/tests/JsonOutputTest.php +++ b/tests/JsonOutputTest.php @@ -72,8 +72,8 @@ public function testJsonConversion() 'Hub, allows you to find shared applications from other talented developers.","price":0,"download_count":0,"recent_download_count":0,"link":"http://prefix' . $this->tempPkg . '","size":' . $pkgSize . ',"md5":"' . $pkgMd5 . '","thumbnail":["http://prefix' . $p->thumbnail[0] . '","http://prefix' . $p->thumbnail[1] . '"],' . '"snapshot":["http://prefix' . $p->snapshot[0] . '","http://prefix' . $p->snapshot[1] . '"],"qinst":true,"qstart":true,"qupgrade":true,"depsers":null,"deppkgs"' . - ':null,"conflictpkgs":null,"start":true,"maintainer":"Synology Inc.","maintainer_url":"http://dummy.org/","distributor":"SSpkS","distributor_url":"http://dummy.org/",' . - '"changelog":"","thirdparty":true,"category":0,"subcategory":0,"type":0,"silent_install":true,"silent_uninstall":true,"silent_upgrade":true,"beta":false}],"keyrings":["test\n12345"]}' + ':null,"conflictpkgs":null,"start":true,"maintainer":"Synology Inc.","maintainer_url":"http://dummy.org/","distributor":"SSpkS","distributor_url":"http://dummy.org/","support_url":"",' . + '"changelog":"","thirdparty":true,"category":0,"subcategory":0,"type":0,"silent_install":true,"silent_uninstall":true,"silent_upgrade":true,"auto_upgrade_from":"","beta":false}],"keyrings":["test\n12345"]}' ); } diff --git a/tests/example_configs/sspks.yaml b/tests/example_configs/sspks.yaml index 78484d2..d7135d0 100644 --- a/tests/example_configs/sspks.yaml +++ b/tests/example_configs/sspks.yaml @@ -8,6 +8,7 @@ packages: maintainer_url: http://dummy.org/ distributor: SSpkS distributor_url: http://dummy.org/ + support_url: http://dummy.org/ paths: cache: tests/example_packageset/