Skip to content
This repository was archived by the owner on Aug 4, 2020. It is now read-only.

Commit 5d2de64

Browse files
committed
initial commit
added config files
1 parent 23936f8 commit 5d2de64

File tree

7 files changed

+342
-0
lines changed

7 files changed

+342
-0
lines changed

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#Pull php:7-fpm-alpine (https://store.docker.com/images/php)
2+
FROM php:7-fpm-alpine
3+
4+
MAINTAINER Adrian7 <adrian.silimon@yahoo.com>
5+
6+
#Install
7+
8+
RUN apk --no-cache add \
9+
libmcrypt-dev \
10+
freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \
11+
wget \
12+
git \
13+
nginx \
14+
ca-certificates \
15+
supervisor \
16+
bash \
17+
&& docker-php-ext-install \
18+
mcrypt \
19+
mbstring \
20+
mysqli \
21+
pdo_mysql \
22+
opcache \
23+
&& docker-php-ext-configure gd \
24+
--with-gd \
25+
--with-freetype-dir=/usr/include/ \
26+
--with-png-dir=/usr/include/ \
27+
--with-jpeg-dir=/usr/include/ \
28+
&& NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
29+
&& docker-php-ext-install -j${NPROC} gd \
30+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
31+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
32+
&& chown -R www-data:www-data /var/lib/nginx \
33+
&& chown -R www-data:www-data /var/www \
34+
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
35+
&& composer global require "hirak/prestissimo:^0.3"
36+
37+
#Configure
38+
39+
COPY ./container.sh /home/bin/container
40+
COPY ./nginx-host-template.conf /etc/nginx/sites-available/template.conf
41+
COPY ./start.sh /start.sh
42+
43+
#Set volumes
44+
45+
VOLUME /var/www
46+
47+
#Entrypoint
48+
49+
CMD ["/bin/bash", "/start.sh"]

build.sh

Whitespace-only changes.

container.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
3+
### Set web server root folder according to env variable ###
4+
5+
NGINX_HOST_TPL_FILE=/etc/nginx/sites-available/template.conf
6+
NGINX_HOST_CFG_FILE=/etc/nginx/sites-available/active.conf
7+
8+
PHP_VERSION=$(php -v | grep --only-matching --perl-regexp "\\d\.\\d+\.\\d+" | head -n 1)
9+
PHP_MAJOR_VERSION=${PHP_VERSION:0:3}
10+
11+
if [ -n "$SERVER_ROOT" ] ;
12+
then
13+
echo "$SERVER_ROOT" >> /tmp/SERVER_ROOT
14+
else
15+
SERVER_ROOT=/var/www
16+
fi
17+
18+
if [ -f $NGINX_HOST_CFG_FILE ] ;
19+
then
20+
#remove previous config file
21+
rm $NGINX_HOST_CFG_FILE
22+
fi
23+
24+
PHP_COMMAND="echo str_replace('root __ROOTDIR__', 'root $SERVER_ROOT', file_get_contents('$NGINX_HOST_TPL_FILE'));"
25+
php -r "$PHP_COMMAND" >> /tmp/temporary.conf
26+
mv -f /tmp/temporary.conf $NGINX_HOST_CFG_FILE
27+
28+
mkdir /etc/nginx/sites-enabled
29+
rm /etc/nginx/sites-enabled/active
30+
ln -s /etc/nginx/sites-available/active.conf /etc/nginx/sites-enabled/active
31+
32+
33+
### Append Container variables to PHP-FPM pool configuration ###
34+
35+
FPM_POOL_CFG_FILE=/usr/local/etc/php-fpm.d/www.conf
36+
37+
echo "" >> $FPM_POOL_CFG_FILE;
38+
echo ";container environment variables" >> $FPM_POOL_CFG_FILE;
39+
40+
SAVEIFS=$IFS
41+
IFS=$(echo -en "\n\b")
42+
43+
for i in $(env)
44+
do
45+
46+
variable=$(echo "$i" | cut -d'=' -f1)
47+
value=$(echo "$i" | cut -d'=' -f2)
48+
49+
if [[ $variable == ENV_* ]] || [[ $variable == AWS_* ]] || [[ $variable == APP_* ]] || [[ $variable == RDS_* ]] || [[ $variable == PHP_* ]] ;
50+
then
51+
#Append variable to PHP pool config file
52+
echo "env[$variable] = \"$value\"" >> $FPM_POOL_CFG_FILE;
53+
fi
54+
55+
done
56+
57+
IFS=$SAVEIFS
58+
59+
### Run composer install & app bootstrap scripts ###
60+
cd /var/www
61+
62+
touch .env
63+
64+
#Run composer install
65+
if [ -f "/var/www/composer.json" ] ;
66+
then
67+
68+
if [ -n "$APP_ENV" ] ;
69+
then
70+
71+
if [ "$APP_ENV" = 'dev' ] ;
72+
then
73+
composer install
74+
fi
75+
76+
if [ "$APP_ENV" = 'test' ] ;
77+
then
78+
composer install
79+
fi
80+
81+
if [ "$APP_ENV" = 'staging' ] ;
82+
then
83+
composer install --no-dev
84+
fi
85+
86+
if [ "$APP_ENV" = 'production' ] ;
87+
then
88+
composer install --no-dev
89+
fi
90+
91+
else
92+
composer install --no-dev
93+
fi
94+
95+
fi
96+
97+
#Run app init script
98+
if [ -f "/var/www/init.sh" ] ;
99+
then
100+
bash /var/www/init.sh
101+
else
102+
#Download readme to /var/www
103+
fi

nginx-host-template.conf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
server {
2+
listen 80; ## listen for ipv4; this line is default and implied
3+
listen [::]:80 default ipv6only=on; ## listen for ipv6
4+
5+
root __ROOTDIR__;
6+
index index.php index.html index.htm;
7+
8+
client_body_temp_path /tmp 1 2;
9+
10+
# Make site accessible from http://localhost
11+
server_name localhost;
12+
13+
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
14+
sendfile off;
15+
16+
# Add stdout logging
17+
error_log /dev/stdout info;
18+
access_log /dev/stdout;
19+
20+
location / {
21+
# First attempt to serve request as file, then
22+
# as directory, then fall back to index.html
23+
try_files $uri $uri/ /index.php$is_args$args;
24+
}
25+
26+
#error_page 404 /404.html;
27+
28+
# redirect server error pages to the static page /50x.html
29+
#error_page 500 502 503 504 /50x.html;
30+
31+
#location = /50x.html {
32+
# root /usr/share/nginx/html;
33+
#}
34+
35+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
36+
#
37+
location ~ \.php$ {
38+
39+
try_files $uri =404;
40+
41+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
42+
fastcgi_pass unix:/run/php/php-fpm.sock;
43+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
44+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
45+
fastcgi_index index.php;
46+
47+
include fastcgi_params;
48+
49+
}
50+
51+
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
52+
expires 30s;
53+
}
54+
55+
# deny access to . files
56+
#
57+
location ~ /\. {
58+
log_not_found off;
59+
deny all;
60+
}
61+
62+
}

nginx.conf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
user www-data;
2+
worker_processes auto;
3+
pid /run/nginx.pid;
4+
5+
# Daemonize
6+
daemon off;
7+
8+
events {
9+
worker_connections 2048;
10+
multi_accept on;
11+
}
12+
13+
http {
14+
15+
##
16+
# Basic Settings
17+
##
18+
19+
sendfile on;
20+
tcp_nopush on;
21+
tcp_nodelay on;
22+
23+
keepalive_timeout 15;
24+
client_max_body_size 64m;
25+
types_hash_max_size 2048;
26+
27+
# server_tokens off;
28+
29+
# server_names_hash_bucket_size 64;
30+
# server_name_in_redirect off;
31+
32+
include /etc/nginx/mime.types;
33+
default_type application/octet-stream;
34+
35+
##
36+
# SSL Settings
37+
##
38+
39+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
40+
ssl_prefer_server_ciphers on;
41+
42+
##
43+
# Logging Settings
44+
##
45+
46+
access_log /var/log/nginx/access.log;
47+
error_log /var/log/nginx/error.log;
48+
49+
##
50+
# Gzip Settings
51+
##
52+
53+
gzip on;
54+
gzip_disable "msie6";
55+
56+
# gzip_vary on;
57+
# gzip_proxied any;
58+
# gzip_comp_level 6;
59+
# gzip_buffers 16 8k;
60+
# gzip_http_version 1.1;
61+
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
62+
63+
##
64+
# Virtual Host Configs
65+
##
66+
67+
include /etc/nginx/conf.d/*.conf;
68+
include /etc/nginx/sites-enabled/*;
69+
}

start.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
### Initialize container ###
4+
if [ ! -f __initialized ] ;
5+
then
6+
7+
CTIME=`date +"%F %T"`
8+
echo "$CTIME" >> __initialized
9+
10+
#Execute container script
11+
bash /home/bin/container
12+
13+
fi
14+
15+
16+
# Start supervisord and services
17+
/usr/bin/supervisord -n -c /etc/supervisord.conf

supervisord.conf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[unix_http_server]
2+
file=/tmp/supervisor.sock ; (the path to the socket file)
3+
4+
[supervisord]
5+
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
6+
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
7+
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
8+
loglevel=info ; (log level;default info; others: debug,warn,trace)
9+
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
10+
nodaemon=false ; (start in foreground if true;default false)
11+
minfds=1024 ; (min. avail startup file descriptors;default 1024)
12+
minprocs=200 ; (min. avail process descriptors;default 200)
13+
user=root ;
14+
15+
; the below section must remain in the config file for RPC
16+
; (supervisorctl/web interface) to work, additional interfaces may be
17+
; added by defining them in separate rpcinterface: sections
18+
[rpcinterface:supervisor]
19+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
20+
21+
[supervisorctl]
22+
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
23+
24+
;Start php-fpm
25+
[program:php-fpm]
26+
command=/usr/local/sbin/php-fpm -F
27+
autostart=true
28+
autorestart=true
29+
priority=5
30+
stdout_logfile=/dev/stdout
31+
stdout_logfile_maxbytes=0
32+
33+
;Start nginx
34+
[program:nginx]
35+
command=/usr/sbin/nginx
36+
autostart=true
37+
autorestart=true
38+
priority=10
39+
stdout_events_enabled=true
40+
stderr_events_enabled=true
41+
stdout_logfile=/dev/stdout
42+
stdout_logfile_maxbytes=0

0 commit comments

Comments
 (0)