Skip to content

Commit

Permalink
Preparation for open source release.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladk1m0 committed Feb 23, 2018
0 parents commit 50103dd
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=owapassword
MYSQL_DATABASE=owadb
MYSQL_USER=owauser
MYSQL_PASSWORD=owapassword
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
- docker

env:
global:
- COMMIT=${TRAVIS_COMMIT::8}
- REPO=vladk1m0/alpine-owa

script:
- docker --version
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi`
- docker login -u $DOCKER_USER -p $DOCKER_PASS
- docker build -t $REPO:$COMMIT --build-arg OWA_VERSION=$TAG .
- docker tag $REPO:$COMMIT $REPO:$TAG
- docker push $REPO
81 changes: 81 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
FROM alpine:latest
LABEL Maintainer="Vladislav Mostovoi <[email protected]>" \
Description="Docker image for Open Web Analytics with Nginx & PHP-FPM 5.x based on Alpine Linux."

ARG OWA_VERSION
ARG TIMEZONE=Europe/Moscow

ENV OWA_UID="82"
ENV OWA_USER="www-data"

ENV OWA_GID="82"
ENV OWA_GROUP="www-data"

# Add application user and group
RUN set -ex \
&& addgroup -g $OWA_UID -S $OWA_GROUP \
&& adduser -u $OWA_GID -D -S -G $OWA_USER $OWA_GROUP

# Install packages
RUN apk update \
&& apk upgrade \
&& apk add --update tzdata \
&& apk --no-cache add \
php5-fpm \
php5-mysql \
php5-mysqli \
php5-pcntl \
php5-json \
php5-openssl \
php5-curl \
php5-zlib \
php5-xml \
php5-phar \
php5-intl \
php5-dom \
php5-xmlreader \
php5-ctype \
php5-gd \
nginx supervisor curl jq

# Configure nginx
COPY config/nginx.conf /etc/nginx/nginx.conf

# Configure PHP-FPM
COPY config/owa-www.conf /etc/php5/fpm.d/
COPY config/owa.ini /etc/php5/conf.d/

# Setup php-fpm unix user/group
RUN sed -i "s|user\s*=.*|user = ${OWA_USER}|g" /etc/php5/php-fpm.conf \
&& sed -i "s|group\s*=.*|group = ${OWA_GROUP}|g" /etc/php5/php-fpm.conf

# Configure supervisord
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Setup timezone
RUN rm -rf /etc/localtime \
&& ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
&& sed -i "s|;*date.timezone\s*=.*|date.timezone = \"${TIMEZONE}\"|i" /etc/php5/conf.d/owa.ini \
&& apk del tzdata \
&& rm -rf /var/cache/apk/*

# Add Open Web Analytics (OWA)
ENV WEBROOT_DIR=/var/www/html
RUN mkdir -p $WEBROOT_DIR

RUN if [ "x$OWA_VERSION" = "x" ] ; then \
OWA_VERSION=$(curl -L -s -H 'Accept: application/json' https://api.github.com/repos/padams/Open-Web-Analytics/releases/latest| jq '.tag_name'| tr -d \") ; \
fi \
&& echo "Install Open Web Analytics (OWA) version $OWA_VERSION" \
&& curl -fsSL -o /tmp/owa.tar.gz "https://github.com/padams/Open-Web-Analytics/archive/$OWA_VERSION.tar.gz" \
&& tar -xzf /tmp/owa.tar.gz -C /tmp \
&& mv /tmp/Open-Web-Analytics-$OWA_VERSION/* $WEBROOT_DIR \
&& rm /tmp/owa.tar.gz \
&& chown -R $OWA_USER:$OWA_GROUP $WEBROOT_DIR/ \
&& chmod -R 0775 $WEBROOT_DIR/ \
&& apk del jq

WORKDIR $WEBROOT_DIR
EXPOSE 80 443
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Open Web Analytics docker image based on Alpine Linux.
==============================================
Open Web Analytics docker image depends on PHP-FPM 5.x & Nginx and build on [Alpine Linux](http://www.alpinelinux.org/).
[Open Web Analytics (OWA)](http://www.openwebanalytics.com) is open source web analytics software licensed under GPL and provides website owners and developers with easy ways to add web analytics to their sites using simple Javascript, PHP, or REST based APIs.

[![Docker Pulls](https://img.shields.io/docker/pulls/vladk1m0/alpine-owa.svg)](https://hub.docker.com/r/vladk1m0/alpine-owa/)

How to use this image
-----
Start the Docker containers:
```
docker run -p 80:80 --name my-owa --link my-mysql:db -d vladk1m0/alpine-owa
```
Once started, you'll arrive at the configuration wizard.
At the Database Setup step, please enter the following

Database Server: db
Database Name: owadb (or you can choose)
Login: MYSQL_USER
Password: MYSQL_PASSWORD

Then you can continue the installation with the super user.

Via docker-compose
----
```
docker-compose up
```
Notice, that the .env file contains the default values for MYSQL_ environment vars.

Contribute
----
Pull requests are very welcome!

Special thanks to
-----
Padams for [Open-Web-Analytics](https://github.com/padams)
Tim de Pater for [docker-php-nginx](https://github.com/TrafeX/docker-php-nginx)
73 changes: 73 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
worker_processes 1;
pid /run/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

log_format main_timed '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time $upstream_response_time $pipe $upstream_cache_status';

access_log /dev/stdout main_timed;
error_log /dev/stderr notice;

keepalive_timeout 180s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;

server {
listen [::]:80 default_server;
listen 80 default_server;
server_name _;

sendfile off;

root /var/www/html;
index index.php index.html;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.php
try_files $uri $uri/ /index.php?q=$uri&$args;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/lib/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
expires 5d;
}

# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}
}
}
38 changes: 38 additions & 0 deletions config/owa-www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[global]
; Log to stderr
error_log = /dev/stderr

[www]
; Enable status page
pm.status_path = /fpm-status

; Ondemand process manager
pm = ondemand

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 50

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
pm.process_idle_timeout = 10s;

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500

; Make sure the FPM workers can reach the environment variables for configuration
clear_env = no

; Catch output from PHP
catch_workers_output = yes
3 changes: 3 additions & 0 deletions config/owa.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Date]
;date.timezone="UTC"
safe_mode = Off
26 changes: 26 additions & 0 deletions config/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm5 -F
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0

[program:nginx]
command=nginx -g 'daemon off;'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

version: '3'
services:
app:
image: vladk1m0/alpine-owa:latest
depends_on:
- db
networks:
- owa_net
ports:
- 9080:80
db:
image: mysql
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
networks:
- owa_net
networks:
owa_net:
driver: bridge

0 comments on commit 50103dd

Please sign in to comment.