diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..e4521a73b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +image: docker:latest + +services: + - docker:dind + +before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + +master: + stage: build + script: + - docker build --pull + -t "$CI_REGISTRY_IMAGE" . + - docker push "${CI_REGISTRY_IMAGE}" + only: + - master + +tags: + stage: build + script: + - docker build --pull + -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + only: + - master + only: + - tags diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..332756cc2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM alpine:3.8 + +LABEL maintainer="Pascal A. " \ + org.photo-frontend.url="https://github.com/photo/frontend/blob/master/README.md" \ + org.photo-frontend.build-date=$BUILD_DATE \ + org.photo-frontend.version=$CI_COMMIT_REF_NAME \ + org.photo-frontend.vcs-url="https://github.com/photo/frontend.git" \ + org.photo-frontend.vcs-ref=$VCS_REF \ + org.photo-frontend.docker.dockerfile="/Dockerfile" \ + org.photo-frontend.description="Trovebox frontend" \ + org.photo-frontend.schema-version="1.0" + +RUN apk --update --no-cache add \ + nginx \ + php7 \ + php7-fpm \ + php7-pdo_mysql \ + php7-mysqli \ + php7-curl \ + php7-gd \ + php7-json \ + php7-oauth \ + php7-session \ + php7-ctype \ + php7-exif \ + php7-mcrypt \ + php7-apcu \ + php7-imagick \ + s6 + +COPY src/configs/docker/ / +COPY src/ /var/www/src + +RUN mkdir -p /var/www/src/userdata \ + && mkdir -p /var/www/src/html/photos \ + && mkdir -p /var/www/src/html/assets/cache \ + && chown nginx /var/www/src/userdata \ + /var/www/src/html/photos \ + /var/www/src/html/assets/cache + +RUN ln -sf /dev/stderr /var/log/fpm-php.log \ + && ln -sf /dev/stdout /var/log/nginx/access.log \ + && ln -sf /dev/stderr /var/log/nginx/error.log + +VOLUME /var/www/src/html/photos +EXPOSE 80 + +ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] +HEALTHCHECK CMD curl --fail http://localhost/ || exit 1 \ No newline at end of file diff --git a/documentation/guides/InstallationUbuntuXenialApache.sh b/documentation/guides/InstallationUbuntuXenialApache.sh new file mode 100755 index 000000000..9c0189645 --- /dev/null +++ b/documentation/guides/InstallationUbuntuXenialApache.sh @@ -0,0 +1,144 @@ +#!/bin/bash +####################################### +# OpenPhoto Install +# Run with sudo for best results +####################################### +SECONDS=0 +if [[ "$(/usr/bin/whoami)" != "root" ]]; then + echo "This script must be run as root or using sudo.Script aborted." + exit 1 +fi + +echo "" +echo "" +echo "====================================================" +echo "Updating Ubuntu and apt-get" +echo "====================================================" +echo "" +echo "" + +apt update +apt upgrade + +echo "" +echo "" +echo "====================================================" +echo "Installing needed packages and modules" +echo "====================================================" +echo "" +echo "" + +apt install -y apache2 curl vim git-core build-essential exiftran mysql-server mysql-client php7.0 libapache2-mod-php7.0 php7.0-curl curl php7.0-gd php7.0-mcrypt php7.0-mysql php-pear php-apcu libpcre3-dev php7.0-dev php-imagick +a2enmod rewrite +a2enmod deflate +a2enmod expires +a2enmod headers + +echo "" +echo "" +echo "====================================================" +echo "Installing oauth from pecl" +echo "====================================================" +echo "" +echo "" + +pecl install oauth +echo "extension=oauth.so" >> /etc/php/7.0/apache2/conf.d/oauth.ini + +echo "" +echo "" +echo "====================================================" +echo "Downloading OpenPhoto and unpacking" +echo "====================================================" +echo "" +echo "" + +wget https://github.com/photo/frontend/tarball/master -O openphoto.tar.gz +tar -zxvf openphoto.tar.gz > /dev/null 2>&1 +mv photo-frontend-* /var/www/openphoto +sudo rm openphoto.tar.gz + +echo "" +echo "" +echo "====================================================" +echo "Setting permissions for Dev server" +echo "====================================================" +echo "" +echo "" + +mkdir /var/www/openphoto/src/userdata +chown www-data:www-data /var/www/openphoto/src/userdata + +mkdir /var/www/openphoto/src/html/assets/cache +chown www-data:www-data /var/www/openphoto/src/html/assets/cache + +mkdir /var/www/openphoto/src/html/photos +chown www-data:www-data /var/www/openphoto/src/html/photos + +echo "" +echo "" +echo "====================================================" +echo "Setting up Apache" +echo "====================================================" +echo "" +echo "" + +cp /var/www/openphoto/src/configs/openphoto-vhost.conf /etc/apache2/sites-available/openphoto.conf +sed 's/\/path\/to\/openphoto\/html\/directory/\/var\/www\/openphoto\/src\/html/g' /var/www/openphoto/src/configs/openphoto-vhost.conf > /etc/apache2/sites-available/openphoto.conf +a2dissite 000-default +a2ensite openphoto + +echo "" +echo "" +echo "====================================================" +echo "Adjusting PHP settings" +echo "====================================================" +echo "" +echo "" + +sed -e 's/file_uploads.*/file_uploads = On/g' -e 's/upload_max_filesize.*/upload_max_filesize = 16M/g' -e 's/post_max_size.*/post_max_size = 16M/g' /etc/php/7.0/apache2/php.ini > /etc/php/7.0/apache2/php.ini.tmp +mv /etc/php/7.0/apache2/php.ini.tmp /etc/php/7.0/apache2/php.ini + +echo "" +echo "" +echo "====================================================" +echo "Launching Your OpenPhoto site" +echo "====================================================" +echo "" +echo "" + +service apache2 restart + +# finding IP address and compensating for possible EC2 installation +EC2=`curl --silent --connect-timeout 1 http://169.254.169.254/latest/meta-data/public-hostname` +if [[ $EC2 != "" ]]; +then + IP=`echo $EC2 | sed -rn 's/ec2-(.*?)\.compute.*/\1/p' | sed 's/-/./g'` +else + IP=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'` +fi + +echo "" +echo "" +echo "" +echo "****************************************************" +echo "====================================================" +echo "CONGRATULATIONS!!!" +echo "" +echo "The photographic heavens are applauding your" +echo "brand new installation of OpenPhoto." +echo "" +echo "" +echo "Took $SECONDS seconds to install." +echo "" +echo "" +echo "Now you can test your installation by directing your" +echo "browser to $IP" +echo "====================================================" +echo "****************************************************" +echo "" +echo "" +echo "" +echo "" +echo "" +echo "" diff --git a/src/configs/docker/etc/nginx/nginx.conf b/src/configs/docker/etc/nginx/nginx.conf new file mode 100644 index 000000000..88972aa8b --- /dev/null +++ b/src/configs/docker/etc/nginx/nginx.conf @@ -0,0 +1,81 @@ +user nginx nginx; +daemon off; +worker_processes 4; +pid /var/run/nginx.pid; + +events { + worker_connections 768; +} + +http { + include mime.types; + default_type application/octet-stream; + keepalive_timeout 20; + + client_max_body_size 10m; + + index index.html index.php; + + log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for" ' + '"$host" sn="$server_name" ' + 'rt=$request_time ' + 'ua="$upstream_addr" us="$upstream_status" ' + 'ut="$upstream_response_time" ul="$upstream_response_length" ' + 'cs=$upstream_cache_status' ; + + server { + listen 80 default_server; + server_name _; + root /var/www/src/html; + + index index.php; + client_max_body_size 25M; + default_type text/html; + charset utf-8; + + if (!-e $request_filename) { + rewrite ^/([^?]*)(\?+([^?]*))*$ /index.php?__route__=/$1&$3 last; + } + + location ~* \.php$ { + try_files $uri =404; + fastcgi_pass unix:/var/run/php-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_ignore_client_abort off; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } + + location ~ \.ini$ { + deny all; + access_log off; + log_not_found off; + } + + add_header Cache-Control "max-age=315360000"; + + location ~* ^.+\.(jpg|jpeg|gif|css|png|js|xml)$ { + expires 30d; + access_log off; + } + } +} diff --git a/src/configs/docker/etc/php7/php-fpm.d/php-fpm.conf b/src/configs/docker/etc/php7/php-fpm.d/php-fpm.conf new file mode 100644 index 000000000..a4850f860 --- /dev/null +++ b/src/configs/docker/etc/php7/php-fpm.d/php-fpm.conf @@ -0,0 +1,22 @@ +[global] +daemonize = no + +[frontend] +user = nginx +group = nginx +listen.owner = nginx +listen.group = nginx +clear_env = false +catch_workers_output = yes +listen = /var/run/php-fpm.sock + +pm = dynamic +pm.max_children = 20 +pm.start_servers = 1 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 2048 + +php_flag[display_errors] = off +php_admin_value[error_log] = /var/log/fpm-php.log +php_admin_flag[log_errors] = on diff --git a/src/configs/docker/etc/services.d/.s6-svscan/finish b/src/configs/docker/etc/services.d/.s6-svscan/finish new file mode 100755 index 000000000..1dadeeaf8 --- /dev/null +++ b/src/configs/docker/etc/services.d/.s6-svscan/finish @@ -0,0 +1,2 @@ +#!/bin/sh +/bin/true diff --git a/src/configs/docker/etc/services.d/nginx/run b/src/configs/docker/etc/services.d/nginx/run new file mode 100755 index 000000000..21e7b0d61 --- /dev/null +++ b/src/configs/docker/etc/services.d/nginx/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +nginx diff --git a/src/configs/docker/etc/services.d/php-fpm/run b/src/configs/docker/etc/services.d/php-fpm/run new file mode 100755 index 000000000..21dd01078 --- /dev/null +++ b/src/configs/docker/etc/services.d/php-fpm/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +php-fpm7 -F diff --git a/src/libraries/adapters/DatabaseMySql.php b/src/libraries/adapters/DatabaseMySql.php index 4d6d8d73d..7645942f9 100644 --- a/src/libraries/adapters/DatabaseMySql.php +++ b/src/libraries/adapters/DatabaseMySql.php @@ -1091,8 +1091,8 @@ public function postAlbumAdd($albumId, $type, $elementIds) $res = true; foreach($elementIds as $elementId) { - $tmpRes = $this->db->execute("REPLACE INTO `{$this->mySqlTablePrefix}elementAlbum`(`owner`,`type`,`element`,`album`) VALUES(:owner,:type,:elementId,:albumId)", - array(':owner' => $this->owner, ':type' => $type, ':elementId' => $elementId, ':albumId' => $albumId)); + $tmpRes = $this->db->execute("REPLACE INTO `{$this->mySqlTablePrefix}elementAlbum`(`owner`,`type`,`element`,`album`, `actor`) VALUES(:owner,:type,:elementId,:albumId,:actor)", + array(':owner' => $this->owner, ':type' => $type, ':elementId' => $elementId, ':albumId' => $albumId, ':actor' => $this->getActor())); $res = $res && $tmpRes !== 0; } return $res !== false; @@ -2493,8 +2493,8 @@ private function postVersions($id, $versions) { // TODO this is gonna fail if we already have the version -- hfiguiere // Possibly use REPLACE INTO? -- jmathai - $result = $this->db->execute("REPLACE INTO {$this->mySqlTablePrefix}photoVersion (`id`, `owner`, `key`, `path`) VALUES(:id, :owner, :key, :value)", - array(':id' => $id, ':owner' => $this->owner, ':key' => $key, ':value' => $value)); + $result = $this->db->execute("REPLACE INTO {$this->mySqlTablePrefix}photoVersion (`id`, `owner`, `key`, `path`, `actor`) VALUES(:id, :owner, :key, :value, :actor)", + array(':id' => $id, ':owner' => $this->owner, ':key' => $key, ':value' => $value, ':actor' => $this->getActor())); } // TODO, what type of return value should we have here -- jmathai return ($result != 1); diff --git a/src/libraries/external/epi/EpiRoute.php b/src/libraries/external/epi/EpiRoute.php index 0618efd12..5e0ce0a46 100644 --- a/src/libraries/external/epi/EpiRoute.php +++ b/src/libraries/external/epi/EpiRoute.php @@ -87,7 +87,7 @@ public function load($file) if(!file_exists($file)) { EpiException::raise(new EpiException("Config file ({$file}) does not exist")); - break; // need to simulate same behavior if exceptions are turned off + return; // need to simulate same behavior if exceptions are turned off } $parsed_array = parse_ini_file($file, true); diff --git a/src/libraries/models/Tag.php b/src/libraries/models/Tag.php index 03f3fdd3f..5135aa9b8 100644 --- a/src/libraries/models/Tag.php +++ b/src/libraries/models/Tag.php @@ -145,6 +145,7 @@ public function update($id, $params) { $params['owner'] = $this->owner; $params['actor'] = $this->getActor(); + $params['extra'] = ''; return $this->db->postTag($id, $params); }