DATA path, vhost automatically enable

This commit is contained in:
Michael RICOIS 2018-03-27 12:49:28 +02:00
parent d0d15c612c
commit 71688f4384
8 changed files with 124 additions and 31 deletions

View File

@ -30,6 +30,11 @@ Windows: ```C:\<user>\worspace```
Always go in `<workspace>/devcontainer` to execute docker-compose command. Always go in `<workspace>/devcontainer` to execute docker-compose command.
Create a `.env` file and add configuration vars:
- DATA : where you store database, vhost, ...
- WORKSPACE : your workspace files
## Launch services (first time build) ## Launch services (first time build)
```bash ```bash
docker-compose up -d docker-compose up -d
@ -71,6 +76,8 @@ docker-compose exec <container_name>
``` ```
## PHP-FPM & Apache vhosts ## PHP-FPM & Apache vhosts
Create a VHOST file in `<DATA>/httpd/`. Add this to your vhost to connect php.
``` ```
# Redirect to local php-fpm if mod_php is not available # Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c> <IfModule !mod_php7.c>
@ -81,7 +88,7 @@ docker-compose exec <container_name>
</IfModule> </IfModule>
<FilesMatch ".+\.ph(p[3457]?|t|tml)$"> <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:fcgi://fpm70/:9000 SetHandler "proxy:fcgi://fpm70:9000
</FilesMatch> </FilesMatch>
<FilesMatch ".+\.phps$"> <FilesMatch ".+\.phps$">
# Deny access to raw php sources by default # Deny access to raw php sources by default
@ -96,16 +103,15 @@ docker-compose exec <container_name>
</IfModule> </IfModule>
</IfModule> </IfModule>
``` ```
Don't forget to create the directory in your workspace.
To enable the new vhosts, simply stop an start the `httpd` container (`docker-compose stop && docker-compose start`).
## Database ## Database
Database files are store in `<workspace>/database`. Database files are store in `<DATA>/`.
Even if you delete your container date are preserved. Even if you delete your container, all data are preserved.
Read the doc official MariaDB: `https://hub.docker.com/_/mariadb/` Read the doc official MariaDB: `https://hub.docker.com/_/mariadb/`
## HTTPd
# Additional # Additional
## Ip Address ## Ip Address

View File

@ -1,4 +1,4 @@
version: '2.3' version: '3'
services: services:
# PHP 5.6 FPM # PHP 5.6 FPM
fpm56: fpm56:
@ -30,7 +30,7 @@ services:
image: mailcatcher:0.6.5 image: mailcatcher:0.6.5
container_name: mailcatcher container_name: mailcatcher
ports: ports:
- '1080:1080' - '1080:1080'
logging: logging:
driver: 'json-file' driver: 'json-file'
options: options:
@ -44,14 +44,15 @@ services:
ports: ports:
- '3306:3306' - '3306:3306'
volumes: volumes:
- ${WORKSPACE}/container-data/db:/var/lib/mysql - ${DATA}/db:/var/lib/mysql
logging: logging:
driver: 'json-file' driver: 'json-file'
options: options:
max-size: '500m' max-size: '500m'
max-file: '9' max-file: '9'
environment: environment:
MYSQL_ROOT_PASSWORD: 'password' MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ADMIN_PASSWORD: 'password'
# Apache HTTPd # Apache HTTPd
httpd: httpd:
build: ./dockerfiles/httpd/2.4/debian-9 build: ./dockerfiles/httpd/2.4/debian-9
@ -60,19 +61,10 @@ services:
ports: ports:
- '80:80' - '80:80'
volumes: volumes:
- ${WORKSPACE}/container-data/httpd:/etc/apache2/sites-available - ${DATA}/httpd:/sites-available
- ${WORKSPACE}:/home/vhosts - ${WORKSPACE}:/home/vhosts
logging: logging:
driver: 'json-file' driver: 'json-file'
options: options:
max-size: '1g' max-size: '1g'
max-file: '10' max-file: '10'
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/16
gateway: 172.18.0.1

View File

@ -1 +1,2 @@
WORKSPACE=/home/ubuntu/workspace WORKSPACE=/home/ubuntu/workspace
DATA=/home/ubuntu/cdata

View File

@ -6,22 +6,29 @@ ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Europe/Paris ENV TZ=Europe/Paris
# Installation # Installation
RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && \ RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade \
apt-get -y install nano apache2 libapache2-mod-xsendfile && \ && apt-get -y install nano apache2 libapache2-mod-xsendfile \
echo "ServerName 127.0.0.1" > /etc/apache2/conf-available/httpd.conf && \ && echo "ServerName 127.0.0.1" > /etc/apache2/conf-available/httpd.conf \
mkdir /var/run/apache2 && mkdir /var/lock/apache2 && \ && mkdir /var/run/apache2 && mkdir /var/lock/apache2 \
rm -f /var/log/apache2/error.log && ln -s /dev/stderr /var/log/apache2/error.log && \ && rm -f /var/log/apache2/error.log && ln -s /dev/stderr /var/log/apache2/error.log \
rm -f /var/log/apache2/access.log && ln -s /dev/stdout /var/log/apache2/access.log && rm -f /var/log/apache2/access.log && ln -s /dev/stdout /var/log/apache2/access.log \
&& echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata \
&& apt-get clean && rm -rf /var/lib/apt/lists/* && mkdir /docker-entrypoint.d && mkdir /sites-available
RUN perl /usr/sbin/a2enconf httpd RUN perl /usr/sbin/a2enconf httpd
RUN perl /usr/sbin/a2enmod autoindex deflate expires headers rewrite actions proxy proxy_fcgi RUN perl /usr/sbin/a2enmod autoindex deflate expires headers rewrite actions proxy proxy_fcgi
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
ADD vhosts/test.conf /etc/apache2/sites-available/
ADD run.sh /run.sh ADD run.sh /run.sh
RUN chmod +x /run.sh RUN chmod +x /run.sh
# Entrypoint
ADD vhost.sh /docker-entrypoint.d/
RUN chmod 775 /docker-entrypoint.d/vhost.sh
# Add VOLUMEs # Add VOLUMEs
VOLUME ["/home/vhosts"] VOLUME ["/home/vhosts", "/sites-available"]
# Expose and Run # Expose and Run
EXPOSE 80 EXPOSE 80

View File

@ -4,5 +4,9 @@ set -e
# Apache gets grumpy about PID files pre-existing # Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid rm -f /usr/local/apache2/logs/httpd.pid
if [ -f /docker-entrypoint.d/vhost.sh ]; then
/docker-entrypoint.d/vhost.sh
fi
source /etc/apache2/envvars source /etc/apache2/envvars
exec apache2 -D FOREGROUND exec apache2 -D FOREGROUND

View File

@ -0,0 +1,43 @@
#!/bin/bash
set -e
# --- Disable all website
cd /etc/apache2/sites-available/
for f in *.conf; do
if [ $f = "000-default.conf" ]; then
continue
fi
if [ $f = "default-ssl.conf" ]; then
continue
fi
if [ $f = "test.conf" ]; then
continue
fi
a2dissite $f;
rm -vf /etc/apache2/sites-available/$f;
done;
if [ ! -d /home/vhosts/test ]; then
mkdir /home/vhosts/test
fi
# --- Copy Vhosts files
VHOSTS='000-default.conf test.conf'
cd /etc/apache2/sites-available/
for f in *.conf; do
if [ $f = "000-default.conf" ]; then
continue
fi
if [ $f = "default-ssl.conf" ]; then
continue
fi
if [ $f = "test.conf" ]; then
continue
fi
if [ -f $f ]; then
cp -vf /sites-available/$f /etc/apache2/sites-available/
VHOSTS+=" $f"
fi
done;
a2ensite $VHOSTS

View File

@ -0,0 +1,40 @@
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster@localhost
DocumentRoot /home/vhosts/test
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>
# Enable http authorization headers
<IfModule mod_setenvif.c>
<IfModule mod_proxy_fcgi.c>
SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
</IfModule>
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:fcgi://fpm70:9000
</FilesMatch>
<FilesMatch ".+\.phps$">
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
Require all denied
</FilesMatch>
</IfModule>
</IfModule>
<Directory /home/vhosts/test/>
Options FollowSymLinks Indexes
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
PASS=${MYSQL_ROOT_PASSWORD:-$(pwgen -s 12 1)} PASS=${MYSQL_ADMIN_PASSWORD:-$(pwgen -s 12 1)}
_word=$( [ ${MYSQL_ROOT_PASSWORD} ] && echo "preset" || echo "random" ) _word=$( [ ${MYSQL_ADMIN_PASSWORD} ] && echo "preset" || echo "random" )
echo "=> Creating MariaDB admin user with ${_word} password" echo "=> Creating MariaDB admin user with ${_word} password"
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'" mysql -uroot -e "CREATE USER IF NOT EXISTS 'admin'@'%' IDENTIFIED BY '$PASS'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION" mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
echo "=> Done!" echo "=> Done!"