Skip to content

Commit

Permalink
* Add missing support_url and auto_upgrade_from fields (PR #55)
Browse files Browse the repository at this point in the history
* Add more envirinment variables to override configuration (for use with docker)

* Upgrade Docker to jdel/alpine:3.8, php7, composer 1.6.5, remove supervisor, change volumes to `/packages` and `/cache`

* Update README with docker instructions
  • Loading branch information
jdel committed Jul 25, 2018
1 parent a890e34 commit 979721a
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 44 deletions.
17 changes: 17 additions & 0 deletions .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
43 changes: 17 additions & 26 deletions Dockerfile
@@ -1,24 +1,16 @@
FROM alpine:3.5
MAINTAINER Julien Del-Piccolo <julien@del-piccolo.com>
ARG BRANCH="master"
ARG COMMIT=""
ENV SSPKS_BRANCH=${BRANCH}
ENV SSPKS_COMMIT=${COMMIT}
FROM jdel/alpine:3.8
LABEL maintainer="Julien Del-Piccolo <julien@del-piccolo.com>"
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 \
Expand All @@ -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"]
34 changes: 34 additions & 0 deletions README.md
Expand Up @@ -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
==========
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2b
1.1.3
1 change: 1 addition & 0 deletions conf/sspks.yaml
Expand Up @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions docker/supervisord.conf

This file was deleted.

24 changes: 24 additions & 0 deletions lib/SSpkS/Config.php
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/SSpkS/Output/JsonOutput.php
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions lib/SSpkS/Package/Package.php
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/JsonOutputTest.php
Expand Up @@ -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"]}'
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/example_configs/sspks.yaml
Expand Up @@ -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/
Expand Down

0 comments on commit 979721a

Please sign in to comment.