Skip to content

Commit 35ef303

Browse files
committed
dev: add docker based development environment
To aid with development speed, as well as to ensure consistency, a standardised development environment has been created. We also provide a Makefile to take some more pain away which provides the following targeets: * `make install` - create .env, download dependencies, create the db, start everything up * `make start` - start the environment * `make stop` - tear it all down * `make reset` kill all the containers and run `install` Signed-off-by: Gavin-John Noonan <mail@gjnoonan.co.uk>
1 parent 02a237d commit 35ef303

7 files changed

Lines changed: 180 additions & 0 deletions

File tree

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dockerfile
2+
docker-compose*.yml
3+
.dockerignore
4+
.git
5+
.gitignore
6+
.env

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DB_HOST=localhost
2+
DB_PORT=3306
3+
DB_DATABASE=phpdvdprofiler
4+
DB_USERNAME=admin
5+
DB_PASSWORD=admin

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM php:7.2-fpm-alpine
2+
3+
RUN apk update && apk upgrade \
4+
&& apk add --no-cache \
5+
freetype \
6+
libpng \
7+
libjpeg-turbo \
8+
freetype-dev \
9+
libpng-dev \
10+
jpeg-dev \
11+
libjpeg \
12+
libjpeg-turbo-dev \
13+
&& docker-php-ext-configure gd \
14+
--with-freetype-dir=/usr/include/ \
15+
--with-jpeg-dir=/usr/include/ \
16+
--with-png-dir=/usr/include/ \
17+
&& docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) gd \
18+
&& docker-php-ext-install mysqli iconv mbstring \
19+
&& rm -rf /tmp/* /var/cache/apk/*
20+
RUN curl -sS https://getcomposer.org/installer | php \
21+
&& mv composer.phar /usr/local/bin/ \
22+
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
23+
24+
COPY . /var/www/
25+
26+
WORKDIR /var/www/
27+
RUN cp contrib/docker/php.ini /usr/local/etc/php/conf.d/phpdvdprofiler.ini
28+
29+
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
30+
ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}"
31+
32+
CMD exec php-fpm

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
DOCKER_COMPOSE = docker-compose
2+
EXEC_PHP = $(DOCKER_COMPOSE) run --rm -T php
3+
4+
build:
5+
@$(DOCKER_COMPOSE) pull --parallel --quiet --ignore-pull-failures 2> /dev/null
6+
$(DOCKER_COMPOSE) build --pull
7+
8+
kill:
9+
$(DOCKER_COMPOSE) kill
10+
$(DOCKER_COMPOSE) down --volumes --remove-orphans
11+
12+
install: ## Install and start the project
13+
install: .env build start
14+
15+
reset: ## Stop and start a fresh install of the project
16+
reset: kill install
17+
18+
start: ## Start the project
19+
$(DOCKER_COMPOSE) up -d --remove-orphans --no-recreate
20+
21+
stop: ## Stop the project
22+
$(DOCKER_COMPOSE) stop
23+
24+
clean: ## Stop the project and remove generated files
25+
clean: kill
26+
rm -rf .env vendor
27+
28+
.PHONY: build kill install reset start stop clean
29+
30+
.env: .env.example
31+
@if [ -f .env ]; \
32+
then\
33+
echo '\033[1;41m/!\ The .env.example file has changed. Please check your .env file (this message will not be displayed again).\033[0m';\
34+
touch .env;\
35+
exit 1;\
36+
else\
37+
echo cp .env.example .env;\
38+
cp .env.example .env;\
39+
fi
40+
41+
.DEFAULT_GOAL := help
42+
help:
43+
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
44+
.PHONY: help

contrib/docker/nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
upstream php-upstream {
2+
server app:9000;
3+
}
4+
5+
server {
6+
listen 80 default_server;
7+
listen [::]:80 default_server ipv6only=on;
8+
9+
server_name localhost;
10+
root /var/www;
11+
index index.php;
12+
13+
# location / {
14+
# try_files $uri $uri/ /index.php?$query_string;
15+
# }
16+
17+
location ~ \.php$ {
18+
try_files $uri /index.php =404;
19+
fastcgi_pass php-upstream;
20+
fastcgi_index index.php;
21+
fastcgi_buffers 16 16k;
22+
fastcgi_buffer_size 32k;
23+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
24+
#fixes timeouts
25+
fastcgi_read_timeout 600;
26+
include fastcgi_params;
27+
}
28+
29+
location ~ /\.ht {
30+
deny all;
31+
}
32+
}

contrib/docker/php.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file_uploads = On
2+
memory_limit = 128M
3+
upload_max_filesize = 64M
4+
post_max_size = 64M
5+
max_execution_time = 600

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: '3.3'
2+
3+
services:
4+
web:
5+
image: nginx:alpine
6+
volumes:
7+
- ./contrib/docker/nginx.conf:/etc/nginx/conf.d/default.conf
8+
- ./:/var/www
9+
networks:
10+
- internal
11+
- external
12+
depends_on:
13+
- app
14+
ports:
15+
- "8080:80"
16+
app:
17+
build:
18+
context: .
19+
dockerfile: Dockerfile
20+
restart: unless-stopped
21+
env_file:
22+
- ./.env
23+
volumes:
24+
- ./:/var/www
25+
networks:
26+
- external
27+
- internal
28+
db:
29+
image: mysql:5.6
30+
restart: unless-stopped
31+
env_file:
32+
- ./.env
33+
networks:
34+
- internal
35+
- external
36+
# command: --default-authentication-plugin=mysql_native_password
37+
environment:
38+
- MYSQL_DATABASE=phpdvdprofiler
39+
- MYSQL_USER=${DB_USERNAME}
40+
- MYSQL_PASSWORD=${DB_PASSWORD}
41+
- MYSQL_RANDOM_ROOT_PASSWORD=true
42+
volumes:
43+
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql
44+
- "db-data:/var/lib/mysql"
45+
ports:
46+
- '3306:3306'
47+
48+
volumes:
49+
db-data:
50+
app-storage:
51+
52+
networks:
53+
internal:
54+
internal: true
55+
external:
56+
driver: bridge

0 commit comments

Comments
 (0)