Initial commit
This commit is contained in:
		
						commit
						92bfd747c5
					
				
							
								
								
									
										33
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										33
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					FROM ubuntu
 | 
				
			||||||
 | 
					MAINTAINER Christian Lück <christian@lueck.tv>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
 | 
				
			||||||
 | 
					  nginx git supervisor php5-fpm php5-cli php5-curl php5-gd php5-json \
 | 
				
			||||||
 | 
					  php5-pgsql
 | 
				
			||||||
 | 
					# php5-mysql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# add ttrss as the only nginx site
 | 
				
			||||||
 | 
					ADD ttrss.nginx.conf /etc/nginx/sites-available/ttrss
 | 
				
			||||||
 | 
					RUN ln -s /etc/nginx/sites-available/ttrss /etc/nginx/sites-enabled/ttrss
 | 
				
			||||||
 | 
					RUN rm /etc/nginx/sites-enabled/default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# install ttrss and patch configuration
 | 
				
			||||||
 | 
					RUN git clone https://github.com/gothfox/Tiny-Tiny-RSS.git /var/www
 | 
				
			||||||
 | 
					WORKDIR /var/www
 | 
				
			||||||
 | 
					RUN cp config.php-dist config.php
 | 
				
			||||||
 | 
					RUN sed -i -e "/'SELF_URL_PATH'/s/ '.*'/ 'http:\/\/localhost\/'/" config.php
 | 
				
			||||||
 | 
					RUN chown www-data:www-data -R /var/www
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# expose only nginx HTTP port
 | 
				
			||||||
 | 
					EXPOSE 80
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# expose default database credentials via ENV in order to ease overwriting
 | 
				
			||||||
 | 
					ENV DB_NAME ttrss
 | 
				
			||||||
 | 
					ENV DB_USER ttrss
 | 
				
			||||||
 | 
					ENV DB_PASS ttrss
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# always re-configure database with current ENV when RUNning container, then monitor all services
 | 
				
			||||||
 | 
					ADD configure-db.php /configure-db.php
 | 
				
			||||||
 | 
					ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 | 
				
			||||||
 | 
					CMD php /configure-db.php && supervisord -c /etc/supervisor/conf.d/supervisord.conf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										94
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										94
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,94 @@
 | 
				
			|||||||
 | 
					# docker-ttrss
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This docker image allows you to run the [Tiny Tiny RSS](http://tt-rss.org) feed reader.
 | 
				
			||||||
 | 
					Keep your feed history to yourself and access your RSS and atom feeds from everywhere.
 | 
				
			||||||
 | 
					You can access it through an easy to use webinterface on your desktop, your mobile browser
 | 
				
			||||||
 | 
					or using one of available apps.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Instructions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					$ git clone https://github.com/clue/docker-ttrss.git
 | 
				
			||||||
 | 
					$ cd docker-ttrss
 | 
				
			||||||
 | 
					$ sudo docker build -t ttrss .
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Running
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Following docker's best practices, this container does not contain its own database,
 | 
				
			||||||
 | 
					but instead expects you to supply a running instance. 
 | 
				
			||||||
 | 
					While slightly more complicated at first, this gives your more freedom as to which
 | 
				
			||||||
 | 
					database instance and configuration you're relying on.
 | 
				
			||||||
 | 
					Also, this makes this container quite disposable, as it doesn't store any sensitive
 | 
				
			||||||
 | 
					information at all.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Starting a database instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This container requires a PostgreSQL database instance. You're free to pick (or build)
 | 
				
			||||||
 | 
					any, as long as is exposes its database port (5432) to the outside.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					$ sudo docker pull nornagon/postgres
 | 
				
			||||||
 | 
					$ sudo docker run -d --name=tinystore nornagon/postgres
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Testing ttrss in foreground
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For testing purposes it's recommended to initially start this container in foreground.
 | 
				
			||||||
 | 
					This is particular useful for your initial database setup, as errors get reported to
 | 
				
			||||||
 | 
					the console and further execution will halt.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					$ sudo docker run -it --link tinystore:db -p 80:80 ttrss
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##### Database configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Whenever your run ttrss, it will check your database setup. It assumes the following
 | 
				
			||||||
 | 
					default configuration, which can be changed by passing the following additional arguments:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					-e DB_NAME=ttrss
 | 
				
			||||||
 | 
					-e DB_USER=ttrss
 | 
				
			||||||
 | 
					-e DB_PASS=ttrss
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##### Database superuser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					When you run ttrss, it will check your database setup. If it can not connect using the above
 | 
				
			||||||
 | 
					configuration, it will automatically try to create a new database and user.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For this to work, it will need a superuser account that is permitted to create a new database
 | 
				
			||||||
 | 
					and user. It assumes the following default configuration, which can be changed by passing the
 | 
				
			||||||
 | 
					following additional arguments:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					-e DB_ENV_USER=docker
 | 
				
			||||||
 | 
					-e DB_ENV_PASS=docker
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Running ttrss daemonized
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Once you've confirmed everything works in the foreground, you can start your container
 | 
				
			||||||
 | 
					in the background by replacing the `-it` argument with `-d` (daemonize).
 | 
				
			||||||
 | 
					Remaining arguments can be passed just like before, the following is the recommended
 | 
				
			||||||
 | 
					minimum:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					$ sudo docker run -d --link tinystore:db -p 80:80 ttrss
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Accessing your webinterface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The above examples expose the Tiny Tiny RSS webinterface on port 80, so that you can browse to:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					http://localhost/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The default login credentials are:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Username: admin
 | 
				
			||||||
 | 
					Password: password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Obviously, you're recommended to change those ASAP.
 | 
				
			||||||
							
								
								
									
										114
									
								
								configure-db.php
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										114
									
								
								configure-db.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,114 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env php
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$ename = 'DB';
 | 
				
			||||||
 | 
					$eport = 5432;
 | 
				
			||||||
 | 
					$confpath = '/var/www/config.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// check DB_NAME, which will be set automatically for a linked "db" container
 | 
				
			||||||
 | 
					if (!env($ename . '_PORT', '')) {
 | 
				
			||||||
 | 
					    error('The env ' . $ename .'_PORT does not exist. Make sure to run with "--link mypostgresinstance:' . $ename . '"');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$config = array();
 | 
				
			||||||
 | 
					$config['DB_TYPE'] = 'pgsql';
 | 
				
			||||||
 | 
					$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
 | 
				
			||||||
 | 
					$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// database credentials for this instance
 | 
				
			||||||
 | 
					//   database name (DB_NAME) can be supplied or detaults to "ttrss"
 | 
				
			||||||
 | 
					//   database user (DB_USER) can be supplied or defaults to database name
 | 
				
			||||||
 | 
					//   database pass (DB_PASS) can be supplied or defaults to database user
 | 
				
			||||||
 | 
					$config['DB_NAME'] = env($ename . '_NAME', 'ttrss');
 | 
				
			||||||
 | 
					$config['DB_USER'] = env($ename . '_USER', $config['DB_NAME']);
 | 
				
			||||||
 | 
					$config['DB_PASS'] = env($ename . '_PASS', $config['DB_USER']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!dbcheck($config)) {
 | 
				
			||||||
 | 
					    echo 'Database login failed, trying to create...' . PHP_EOL;
 | 
				
			||||||
 | 
					    // superuser account to create new database and corresponding user account
 | 
				
			||||||
 | 
					    //   username (SU_USER) can be supplied or defaults to "docker"
 | 
				
			||||||
 | 
					    //   password (SU_PASS) can be supplied or defaults to username
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $super = $config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $super['DB_NAME'] = null;
 | 
				
			||||||
 | 
					    $super['DB_USER'] = env($ename . '_ENV_USER', 'docker');
 | 
				
			||||||
 | 
					    $super['DB_PASS'] = env($ename . '_ENV_PASS', $super['DB_USER']);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    $pdo = dbconnect($super);
 | 
				
			||||||
 | 
					    $pdo->exec('CREATE ROLE ' . ($config['DB_USER']) . ' WITH LOGIN PASSWORD ' . $pdo->quote($config['DB_PASS']));
 | 
				
			||||||
 | 
					    $pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']) . ' WITH OWNER ' . ($config['DB_USER']));
 | 
				
			||||||
 | 
					    unset($pdo);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (dbcheck($config)) {
 | 
				
			||||||
 | 
					        echo 'Database login created and confirmed' . PHP_EOL;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        error('Database login failed, trying to create login failed as well');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$pdo = dbconnect($config);
 | 
				
			||||||
 | 
					try {
 | 
				
			||||||
 | 
					    $pdo->query('SELECT 1 FROM ttrss_feeds');
 | 
				
			||||||
 | 
					    // reached this point => table found, assume db is complete
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					catch (PDOException $e) {
 | 
				
			||||||
 | 
					    echo 'Database table not found, applying schema... ' . PHP_EOL;
 | 
				
			||||||
 | 
					    $schema = file_get_contents('schema/ttrss_schema_' . $config['DB_TYPE'] . '.sql');
 | 
				
			||||||
 | 
					    $schema = preg_replace('/--(.*?);/', '', $schema);
 | 
				
			||||||
 | 
					    $schema = preg_replace('/[\r\n]/', ' ', $schema);
 | 
				
			||||||
 | 
					    $schema = trim($schema, ' ;');
 | 
				
			||||||
 | 
					    foreach (explode(';', $schema) as $stm) {
 | 
				
			||||||
 | 
					        $pdo->exec($stm);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    unset($pdo);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$contents = file_get_contents($confpath);
 | 
				
			||||||
 | 
					foreach ($config as $name => $value) {
 | 
				
			||||||
 | 
					    $contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					file_put_contents($confpath, $contents);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function env($name, $default = null)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    $v = getenv($name) ?: $default;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if ($v === null) {
 | 
				
			||||||
 | 
					        error('The env ' . $name . ' does not exist');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return $v;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function error($text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    echo 'Error: ' . $text . PHP_EOL;
 | 
				
			||||||
 | 
					    exit(1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function dbconnect($config)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    $map = array('host' => 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS');
 | 
				
			||||||
 | 
					    $dsn = $config['DB_TYPE'] . ':';
 | 
				
			||||||
 | 
					    foreach ($map as $d => $h) {
 | 
				
			||||||
 | 
					        if (isset($config['DB_' . $h])) {
 | 
				
			||||||
 | 
					            $dsn .= $d . '=' . $config['DB_' . $h] . ';';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    $pdo = new \PDO($dsn);
 | 
				
			||||||
 | 
					    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 | 
				
			||||||
 | 
					    return $pdo;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function dbcheck($config)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        dbconnect($config);
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (PDOException $e) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										15
									
								
								supervisord.conf
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										15
									
								
								supervisord.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					[supervisord]
 | 
				
			||||||
 | 
					nodaemon=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[program:php5-fpm]
 | 
				
			||||||
 | 
					command=/usr/sbin/php5-fpm --nodaemonize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[program:nginx]
 | 
				
			||||||
 | 
					command=/usr/sbin/nginx -g "daemon off;"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[program:ttrss-update-daemon]
 | 
				
			||||||
 | 
					command=/usr/bin/php /var/www/update_daemon2.php
 | 
				
			||||||
 | 
					user=www-data
 | 
				
			||||||
 | 
					stdout_logfile=/tmp/%(program_name)s.stdout
 | 
				
			||||||
 | 
					stderr_logfile=/tmp/%(program_name)s.stderr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										18
									
								
								ttrss.nginx.conf
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										18
									
								
								ttrss.nginx.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					server {
 | 
				
			||||||
 | 
						listen 80;
 | 
				
			||||||
 | 
						root /var/www;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						index index.php index.html;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						location / {
 | 
				
			||||||
 | 
							try_files $uri $uri/ =404;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						location ~ \.php$ {
 | 
				
			||||||
 | 
							fastcgi_split_path_info ^(.+\.php)(/.+)$;
 | 
				
			||||||
 | 
							fastcgi_pass unix:/var/run/php5-fpm.sock;
 | 
				
			||||||
 | 
							fastcgi_index index.php;
 | 
				
			||||||
 | 
							include fastcgi_params;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user