Skip to content

Commit

Permalink
Added Docker support for development
Browse files Browse the repository at this point in the history
  • Loading branch information
vedmant committed May 11, 2018
1 parent d8cb7ec commit 61447f7
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
APP_DEMO=false

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=jogging_time
DB_USERNAME=jogging_time
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=file
QUEUE_DRIVER=redis

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mmailcatcher
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
FROM php:7.2-fpm

# Get repository and install wget and vim
RUN apt-get update && apt-get install --no-install-recommends -y wget vim git unzip apt-transport-https gnupg

RUN apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen

# Install PHP extensions deps
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
zlib1g-dev \
libicu-dev \
unixodbc-dev \
libssl-dev \
g++

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install \
mbstring \
pdo_mysql \
zip \
ftp \
&& docker-php-ext-enable \
opcache

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer

# Install supervisor
RUN apt-get install -y supervisor

# Install Node
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs

# Install Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn

# Clean repository
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN "date"

CMD mkdir -p /app

VOLUME /app

CMD chown -R www-data:www-data /app

WORKDIR /app

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"laravel/framework": "5.5.*",
"laravel/passport": "^4.0.3",
"laravel/tinker": "^1.0",
"mpociot/laravel-apidoc-generator": "^2.0"
"mpociot/laravel-apidoc-generator": "^2.0",
"predis/predis": "^1.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^2.3",
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '2'
services:

php:
build: ./
container_name: jogging_time_php
image: jogging_time_php
volumes:
- .:/app:cached
- ./docker/php.ini:/usr/local/etc/php/conf.d/custom.ini
- ./docker/supervisord.conf:/etc/supervisord.conf
links:
- mariadb
- mailcatcher
- redis

nginx:
image: nginx:alpine
container_name: jogging_time_nginx
ports:
- 8080:80
volumes:
- .:/app
- ./docker/default.conf:/etc/nginx/conf.d/default.conf
links:
- php

mariadb:
image: mariadb:latest
container_name: jogging_time_mysql
ports:
- 33060:3306
volumes:
- mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: jogging_time
MYSQL_USER: jogging_time
MYSQL_PASS: secret

mailcatcher:
image: schickling/mailcatcher
container_name: jogging_time_mailcatcher
ports:
- 1080:1080

redis:
image: redis:3-alpine
container_name: jogging_time_redis
ports:
- 63790:6379

volumes:
mysql:
42 changes: 42 additions & 0 deletions docker/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
server {
listen 80;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

client_max_body_size 200M;

index index.html index.php;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /app/public;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/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 php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
3 changes: 3 additions & 0 deletions docker/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
memory_limit = 256M
opcache.validate_timestamps = 1
opcache.revalidate_freq = 1
25 changes: 25 additions & 0 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor

[program:php-fpm]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/sbin/php-fpm -F
numprocs=1
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startretries=0

[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /app/artisan queue:work --sleep=1 --tries=3
numprocs=2
redirect_stderr=true
stdout_logfile=/app/storage/logs/queue.log
autorestart=true
startretries=0
37 changes: 36 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ If you don't have installed yarn, run `npm install -g yarn`
* Full Phpunit test coverage
* E2E tests with Cypress
* Continuous integration with Travis CI
* Development configuration with Docker


### Includes ###
Expand All @@ -62,6 +63,7 @@ If you don't have installed yarn, run `npm install -g yarn`
* [Vuex](https://vuex.vuejs.org/en/intro.html) State management pattern + library for Vue.js
* [Vue-Router](https://router.vuejs.org/en/) Router library for Vue.js
* [Axios](https://github.com/axios/axios) HTTP client
* [Docker](https://www.docker.com/) Development setup with Docker


### Other Features ###
Expand Down Expand Up @@ -109,9 +111,42 @@ yarn production -- --env.analyzer true
```


### Development with Docker ###

If you want to use more features like Redis queues, MariaDB database,
sending and viewing sent emails you can use Docker setup on this project.

For you you will need Docker installed on your host [https://docs.docker.com/install/](https://docs.docker.com/install/)

To build the image for Docker, run:

docker-compose build

It will build all images and run all needed containers.

Then use ENV variables, prepared specificly for Docker:

cp .env.docker.example .env
docker-compose run php php artisan key:generate

Migrate and seed database, and install Passport:

docker-compose run php php artisan migrate --seed
docker-compose run php php artisan passport:install

To run the project in Docker just run:

docker-compose up

And open http://localhost:8080

To run all the Artisan or Test commands you can use `docker-compose run php` before the command to run it in the container.
If you want to run command in currently running container, use `docker-compose exec php`.


### Tests ###

To run all Phpunit tests:
To run all PHPUnit tests:

```
./vendor/bin/phpunit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<tr :id="`entry-row-${row.id}`">>
<tr :id="`entry-row-${row.id}`">
<td>
<router-link v-if="row.user" :to="'/admin/user/show/' + row.user.id">{{ row.user.name }}</router-link>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<tr :id="`user-row-${row.id}`">>
<tr :id="`user-row-${row.id}`">
<td>
<router-link :to="'/admin/user/show/' + row.id">{{ row.name }}</router-link>
</td>
Expand Down

0 comments on commit 61447f7

Please sign in to comment.