From 61447f71db932d8d9002c43c52690eaafcfba07f Mon Sep 17 00:00:00 2001 From: Vedmant Date: Fri, 11 May 2018 19:21:21 +0300 Subject: [PATCH] Added Docker support for development --- .env.docker.example | 33 ++++++++++ Dockerfile | 65 +++++++++++++++++++ composer.json | 3 +- composer.lock | 52 ++++++++++++++- docker-compose.yml | 54 +++++++++++++++ docker/default.conf | 42 ++++++++++++ docker/php.ini | 3 + docker/supervisord.conf | 25 +++++++ readme.md | 37 ++++++++++- .../pages/admin/entry/partials/Row.vue | 2 +- .../pages/admin/user/partials/Row.vue | 2 +- 11 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 .env.docker.example create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker/default.conf create mode 100644 docker/php.ini create mode 100644 docker/supervisord.conf diff --git a/.env.docker.example b/.env.docker.example new file mode 100644 index 0000000..2a10176 --- /dev/null +++ b/.env.docker.example @@ -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= diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3205e5a --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/composer.json b/composer.json index 46d5196..23f4095 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 4aa0d9c..eca48dc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "cc7dfb4c4612c21e403ece2722307453", + "content-hash": "6697d5792ca0c4b90427e36a51810329", "packages": [ { "name": "defuse/php-encryption", @@ -1847,6 +1847,56 @@ ], "time": "2017-10-23T05:04:54+00:00" }, + { + "name": "predis/predis", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/nrk/predis.git", + "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1", + "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "suggest": { + "ext-curl": "Allows access to Webdis when paired with phpiredis", + "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol" + }, + "type": "library", + "autoload": { + "psr-4": { + "Predis\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniele Alessandri", + "email": "suppakilla@gmail.com", + "homepage": "http://clorophilla.net" + } + ], + "description": "Flexible and feature-complete Redis client for PHP and HHVM", + "homepage": "http://github.com/nrk/predis", + "keywords": [ + "nosql", + "predis", + "redis" + ], + "time": "2016-06-16T16:22:20+00:00" + }, { "name": "psr/container", "version": "1.0.0", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fc185c0 --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/docker/default.conf b/docker/default.conf new file mode 100644 index 0000000..5aac038 --- /dev/null +++ b/docker/default.conf @@ -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; + } +} diff --git a/docker/php.ini b/docker/php.ini new file mode 100644 index 0000000..fecd627 --- /dev/null +++ b/docker/php.ini @@ -0,0 +1,3 @@ +memory_limit = 256M +opcache.validate_timestamps = 1 +opcache.revalidate_freq = 1 diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 0000000..197e63d --- /dev/null +++ b/docker/supervisord.conf @@ -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 diff --git a/readme.md b/readme.md index fea6279..e1d8c5d 100644 --- a/readme.md +++ b/readme.md @@ -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 ### @@ -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 ### @@ -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 diff --git a/resources/assets/js/components/pages/admin/entry/partials/Row.vue b/resources/assets/js/components/pages/admin/entry/partials/Row.vue index 50edd93..09d36b0 100644 --- a/resources/assets/js/components/pages/admin/entry/partials/Row.vue +++ b/resources/assets/js/components/pages/admin/entry/partials/Row.vue @@ -1,5 +1,5 @@