Initial Commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
Executable
+33
@@ -0,0 +1,33 @@
|
||||
# Docker configuration
|
||||
COMPOSE_PROJECT_NAME=
|
||||
|
||||
# Load several Docker compose files using Compose CLI env variables: https://docs.docker.com/compose/reference/envvars/
|
||||
# Append the additional containers you want to use like this: docker/container-name/docker-compose.override.yml
|
||||
# For example to add Redis: docker-compose.yml:docker/redis/docker-compose.override.yml
|
||||
COMPOSE_PATH_SEPARATOR=:
|
||||
COMPOSE_FILE=docker-compose.yml
|
||||
|
||||
# Configure ports
|
||||
NGINX_HTTPS_PORT=4443
|
||||
NGINX_HTTP_PORT=8080
|
||||
PHPMYADMIN_PORT=8081
|
||||
WEBPACK_PORT=4444
|
||||
MAILHOG_PORT=8025
|
||||
BROWSERSYNC_PORT=3000
|
||||
BROWSERSYNC_ADMIN_PORT=3001
|
||||
# DB and Redis port are set by DB_PORT and REDIS_PORT above
|
||||
|
||||
PHP_VERSION=7.4
|
||||
PHP_SERVER_NAME=laravel
|
||||
|
||||
MYSQL_VERSION=5.7
|
||||
|
||||
# User and Group ID for correct file permissions
|
||||
USER_ID=1000
|
||||
GROUP_ID=1000
|
||||
|
||||
# Mix mode can be one of: watch, hot, dev, prod
|
||||
MIX_MODE=watch
|
||||
|
||||
# Enable browsersync
|
||||
MIX_BROWSERSYNC=disabled
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
/.idea
|
||||
@@ -0,0 +1,26 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.1.1] - 2020-09-22
|
||||
### Changed
|
||||
- Bumped Docker-compose overrides version to 3.7
|
||||
|
||||
## [1.1.0] - 2020-09-07
|
||||
### Added
|
||||
- Scheduler container
|
||||
### Changed
|
||||
- Bumped Docker-compose version to 3.7
|
||||
- Used [extension fields](https://docs.docker.com/compose/compose-file/#extension-fields) for the PHP service
|
||||
|
||||
## [1.0.1] - 2020-08-17
|
||||
### Changed
|
||||
- Made MySQL version modifiable and defaulting to 5.7, as 8.0 has issues with PHP 7.3 and older
|
||||
|
||||
## [1.0.0] - 2020-06-22
|
||||
### Added
|
||||
- Initial version
|
||||
@@ -0,0 +1,282 @@
|
||||
# Laradose
|
||||
|
||||
Laradose aims to bring a light yet powerful and configurable Docker compose configuration to run a Laravel
|
||||
application locally. Installation and configuration are made easy with the provided Bash script.
|
||||
Custom settings are saved in Laravel's `.env`. Six containers are installed out of the box:
|
||||
|
||||
- PHP with configurable versions and xdebug support
|
||||
- Nginx with HTTPS support
|
||||
- MySQL with automatic database import
|
||||
- Artisan to run Laravel Artisan commands
|
||||
- Composer to install PHP packages
|
||||
- NPM with Hot Module Reload and Browsersync support
|
||||
|
||||
Additional containers can be enabled:
|
||||
|
||||
- Queues: Laravel's default queue manager
|
||||
- Redis: in-memory database to store cache
|
||||
- Laravel Horizon: Redis-powered queue manager
|
||||
- MailHog: local email server
|
||||
- PHPMyAdmin: database management
|
||||
- Scheduler: Laravel Scheduler
|
||||
|
||||
1. [Requirements](#1-requirements)
|
||||
2. [Installation Instructions](#2-installation-instructions)
|
||||
1. [Automated installation](#21-automated-installation)
|
||||
2. [Manual installation](#22-manual-installation)
|
||||
3. [Installation on Windows](#23-installation-on-windows)
|
||||
3. [Usage](#3-usage)
|
||||
1. [Configuration](#31-configuration)
|
||||
2. [Commands](#32-commands)
|
||||
4. [Container Specific Instructions](#4-container-specific-instructions)
|
||||
1. [PHP](#41-php)
|
||||
1. [Setup xdebug for PHPStorm](#411-setup-xdebug-for-phpstorm)
|
||||
2. [MySQL](#42-mysql)
|
||||
1. [Import a dump](#421-import-a-dump)
|
||||
3. [NPM](#43-npm)
|
||||
1. [Hot Module Reload](#431-hot-module-reload)
|
||||
2. [Browsersync](#432-browsersync)
|
||||
5. [Available Parameters](#5-available-parameters)
|
||||
6. [Q&A](#6-qa)
|
||||
|
||||
Found a bug, have a suggestion? Please [open an issue](https://github.com/AdrienPoupa/laradose/issues) so we can discuss it!
|
||||
|
||||
## 1. Requirements
|
||||
|
||||
- [Docker](https://docs.docker.com/engine/install//)
|
||||
- [Docker Compose](https://docs.docker.com/compose/install/)
|
||||
- unzip and wget or curl for the installation script
|
||||
|
||||
This was tested on Linux (Ubuntu, should work on all Debian derivatives), Windows 10 2004 (Docker Desktop and WSL2 Backend,
|
||||
Ubuntu 20.04 LTS) and MacOS.
|
||||
|
||||
## 2. Installation Instructions
|
||||
|
||||
### 2.1 Automated installation
|
||||
|
||||
A Bash script is provided to install Laradose automatically. It will add the required files to your project's folder
|
||||
and help you configure Laradose. This is the preferred method. If you are running Windows, please read
|
||||
[Installation on Windows](#23-installation-on-windows). Before running the script, it is recommended to commit your
|
||||
project so you can revert to the previous state if needed. To use it, `cd` into your project's folder and run:
|
||||
|
||||
```
|
||||
$ wget https://raw.githubusercontent.com/AdrienPoupa/laradose/master/laradose.sh && chmod +x laradose.sh
|
||||
$ ./laradose.sh --install
|
||||
```
|
||||
|
||||
The script will:
|
||||
|
||||
1. Download this repository's files
|
||||
2. Copy them in your project's folder
|
||||
3. Generate the SSL certificates needed for HTTPS
|
||||
4. Modify the following files to adapt them to the local environment: `.env.`, `.env.example`, `package.json`, `webpack.mix.js`
|
||||
5. Apply the correct permissions
|
||||
6. Run the configuration tool to specify which containers should be enabled, on which ports, etc
|
||||
|
||||
It is recommended to commit your files before running the script,
|
||||
so you can rollback the modifications it made if needed.
|
||||
|
||||
### 2.2 Manual installation
|
||||
|
||||
You can install Laradose manually if you do not wish to use the script.
|
||||
|
||||
1. Copy the following into your project folder:
|
||||
- The `docker` folder
|
||||
- The `docker-compose.yml` file
|
||||
2. Append the content of `.env` to your `.env` file
|
||||
3. Set `DB_HOST=mysql` and `REDIS_HOST=redis`
|
||||
4. Generate the SSL certificates:
|
||||
```
|
||||
$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout ./docker/nginx/keys/server.key -out ./docker/nginx/keys/server.crt -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=localhost" > /dev/null 2>&1
|
||||
$ openssl req -new -key ./docker/nginx/keys/server.key -out ./docker/nginx/keys/server.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=localhost" > /dev/null 2>&1
|
||||
```
|
||||
5. Append the content of `webpack.mix.js` to your `webpack.mix.js` file
|
||||
6. Add the `--https` argument to the `hot` section of your `package.json`
|
||||
7. Set write permissions on the host: `$ chown -R $(id -u):$(id -g) . && chmod -R 755 .`
|
||||
8. You can configure the environment variables manually as shown in [Available Parameters](#5-available-parameters).
|
||||
|
||||
### 2.3 Installation on Windows
|
||||
|
||||
Laradose was tested successfully on Windows 10 2004 with WSL2. Start by [installing WSL2](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
|
||||
|
||||
I would recommend using the Linux distribution Ubuntu 20.04 LTS.
|
||||
|
||||
Make sure Docker Desktop [uses the WSL2 backend](https://docs.docker.com/docker-for-windows/wsl/).
|
||||
|
||||
You can run the installation script from the Ubuntu 20.04 LTS application shell, and Docker compose from Powershell.
|
||||
|
||||
To setup xdebug, make sure to follow the instructions at [Setup xdebug for PHPStorm](#411-setup-xdebug-for-phpstorm).
|
||||
|
||||
## 3. Usage
|
||||
|
||||
If you need to import a database dump, place it in the `docker/mysql` folder. It will be imported automatically when
|
||||
the MySQL container boots.
|
||||
|
||||
### 3.1 Configuration
|
||||
|
||||
Run the Laradose script:
|
||||
|
||||
```
|
||||
$ ./laradose.sh
|
||||
```
|
||||
|
||||
Use the `1. Configure` option of the Laradose script to configure your installation. You will be able to enable and
|
||||
disable the additional containers and change the options shown in [Available Parameters](#5-available-parameters).
|
||||
Be aware the script will update your `.env` file.
|
||||
|
||||
### 3.2 Commands
|
||||
|
||||
Run the project. It will build the containers the first time.
|
||||
|
||||
```
|
||||
$ sudo docker-compose up -d
|
||||
```
|
||||
|
||||
By default, your application will be available at
|
||||
|
||||
- https://localhost:4443
|
||||
- http://localhost:8080
|
||||
|
||||
Check a container's logs:
|
||||
|
||||
```
|
||||
$ sudo docker-compose logs container-name
|
||||
```
|
||||
|
||||
For example, check Nginx logs:
|
||||
|
||||
```
|
||||
$ sudo docker-compose logs nginx
|
||||
```
|
||||
|
||||
Run artisan commands
|
||||
|
||||
```
|
||||
$ sudo docker-compose run --rm artisan <command>
|
||||
```
|
||||
|
||||
Install Composer dependencies
|
||||
|
||||
```
|
||||
$ sudo docker-compose run --rm composer install
|
||||
```
|
||||
|
||||
Install NPM dependencies
|
||||
|
||||
```
|
||||
$ sudo docker-compose run --rm --entrypoint npm npm install
|
||||
```
|
||||
|
||||
Restart a container:
|
||||
|
||||
```
|
||||
$ sudo docker-compose restart <container-name>
|
||||
```
|
||||
|
||||
Rebuild the containers:
|
||||
|
||||
```
|
||||
$ sudo docker-compose build
|
||||
```
|
||||
|
||||
## 4. Container Specific Instructions
|
||||
|
||||
### 4.1 PHP
|
||||
|
||||
#### 4.1.1 Setup xdebug for PHPStorm
|
||||
|
||||
In PHPStorm go to: `Languages & Frameworks` > `PHP` > `Servers` > and set the following settings:
|
||||
|
||||

|
||||
|
||||
The name field must match `PHP_SERVER_NAME` (set to `laravel` by default). The host is set to `localhost`, the port
|
||||
to the HTTP port, which is 8080 by defaut. The paths mappings are set appropriately.
|
||||
|
||||
If you are using Windows or MacOS, in the Docker-compose, you can add the following environment variable:
|
||||
|
||||
```
|
||||
XDEBUG_CONFIG: "remote_host=host.docker.internal"
|
||||
```
|
||||
|
||||
### 4.2 MySQL
|
||||
|
||||
#### 4.2.1 Import a dump
|
||||
|
||||
First, remove the existing volumes:
|
||||
|
||||
```
|
||||
$ sudo docker-compose down -v
|
||||
```
|
||||
|
||||
Then place your MySQL dump file in the `docker/mysql` folder, and start the containers normally.
|
||||
|
||||
### 4.3 NPM
|
||||
|
||||
#### 4.3.1 Hot Module Reload
|
||||
|
||||
Make sure your .js files load using the `mix` helper as shown here:
|
||||
|
||||
```
|
||||
<script src="{{ mix('js/app.js') }}" defer></script>
|
||||
```
|
||||
|
||||
#### 4.3.2 Browsersync
|
||||
|
||||
Add the following to your Blade layout:
|
||||
|
||||
```
|
||||
@if(config('app.env') === 'local')
|
||||
<script async src='https://localhost:3000/browser-sync/browser-sync-client.js'></script>
|
||||
@endif
|
||||
```
|
||||
|
||||
## 5. Available Parameters
|
||||
|
||||
| Parameter Name | Default Value | Description |
|
||||
|------------------------|--------------------|-----------------------------------------------------------------------------------------------------------------|
|
||||
| COMPOSE_PROJECT_NAME | APP_NAME | Sets the project name. This value is prepended along with the service name to the container on start up. |
|
||||
| COMPOSE_PATH_SEPARATOR | : | If set, the value of the COMPOSE_FILE environment variable is separated using this character as path separator. |
|
||||
| COMPOSE_FILE | docker-compose.yml | Specify the path to a Compose file. |
|
||||
| NGINX_HTTPS_PORT | 4443 | HTTPS port of the Nginx container. Accessible at https://localhost:4443 |
|
||||
| NGINX_HTTP_PORT | 8080 | HTTP port of the Nginx container. Accessible at http://localhost:8080 |
|
||||
| PHPMYADMIN_PORT | 8081 | HTTP port of the phpMyAdmin container. Accessible at http://localhost:8081 |
|
||||
| WEBPACK_PORT | 4444 | Webpack port, used to serve JavaScript files with the `mix` helper function. |
|
||||
| MAILHOG_PORT | 8025 | HTTP port of the MailHog container. Accessible at http://localhost:8025 |
|
||||
| BROWSERSYNC_PORT | 3000 | HTTP port of the Browsersync service of the NPM container |
|
||||
| BROWSERSYNC_ADMIN_PORT | 3001 | HTTP port of the Browsersync admin panel of the NPM container Accessible at https://localhost:3001 |
|
||||
| PHP_VERSION | 7.4 | PHP Version. Can be one of: 7.2, 7.3, 7.4 |
|
||||
| PHP_SERVER_NAME | laravel | PHP Server Name, used for xdebug |
|
||||
| MYSQL_VERSION | 5.7 | MySQL Version. Can be one of: 5.7, 8 |
|
||||
| USER_ID | 1000 | Linux User ID for file and folder permissions |
|
||||
| GROUP_ID | 1000 | Linux Group ID for file and folder permissions |
|
||||
| MIX_MODE | watch | Laravel Mix mode. Can be one of: watch, hot, dev, prod. |
|
||||
| MIX_BROWSERSYNC | disabled | Enable Browsersync (enabled or disabled) |
|
||||
|
||||
## 6. Q&A
|
||||
|
||||
1. Why use this over Laradock?
|
||||
|
||||
I respect Laradock's maintainers work, their solution works well for many people,
|
||||
but I find it to be very heavy as it tries to cover every possible use case. I wanted to create a lighter solution
|
||||
that would be easy to modify, be closer to a "vanilla" Docker-compose installation and would only include what is
|
||||
necessary (Laradock supports [GitLab](https://github.com/laradock/laradock/tree/master/gitlab),
|
||||
how is that relevant to Laravel? Is a [1,700 lines](https://github.com/laradock/laradock/blob/master/docker-compose.yml)
|
||||
long Docker-compose file necessary?).
|
||||
|
||||
2. Why version the Docker files?
|
||||
|
||||
I think this approach makes sense if you want to customize your local environment, like if you want to add a container,
|
||||
modify a Dockerfile, change an entrypoint... I played a bit with Git submodules, but I found that you have to explicitly
|
||||
tell Git to fetch them when cloning a repo: this creates an extra step when setting up the project.
|
||||
|
||||
Moreover, submodules are not updated automatically; a trivial change in a Dockerfile
|
||||
would result in a mess unless you fork the Git submodule repo by yourself but that creates more friction.
|
||||
|
||||
3. Why not create a package?
|
||||
|
||||
To install a PHP package, you need Composer. To run PHP files, you need PHP. But this solution aims to avoid installing Composer and/or PHP on your host to begin with. Thus it makes no sense to require Composer and PHP to install a package that aims to provide Composer and PHP.
|
||||
|
||||
4. Permission issue!
|
||||
|
||||
Make sure your `USER_ID` and `GROUP_ID` environment variables match your current user. Then, in your project's folder,
|
||||
do `chown -R $(id -u):$(id -g) . && chmod -R 755 .`
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
# Laradose
|
||||
# Author: Adrien Poupa
|
||||
# https://github.com/AdrienPoupa/laradose
|
||||
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: "mysql:${MYSQL_VERSION}"
|
||||
ports:
|
||||
- "${DB_PORT}:3306"
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||
MYSQL_DATABASE: ${DB_DATABASE}
|
||||
volumes:
|
||||
- ./docker/mysql:/docker-entrypoint-initdb.d
|
||||
networks:
|
||||
- laravel
|
||||
|
||||
x-php:
|
||||
&php-base
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
dockerfile: ./docker/php/Dockerfile
|
||||
environment:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
working_dir: /var/www
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
|
||||
php:
|
||||
<<: *php-base
|
||||
environment:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
PHP_IDE_CONFIG: "serverName=${PHP_SERVER_NAME}"
|
||||
|
||||
nginx:
|
||||
image: nginx:stable-alpine
|
||||
ports:
|
||||
- "${NGINX_HTTPS_PORT}:443"
|
||||
- "${NGINX_HTTP_PORT}:80"
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./docker/nginx/keys:/etc/nginx/ssl
|
||||
networks:
|
||||
- laravel
|
||||
|
||||
artisan:
|
||||
<<: *php-base
|
||||
depends_on:
|
||||
- mysql
|
||||
entrypoint: ['php', '/var/www/artisan']
|
||||
|
||||
composer:
|
||||
image: composer:latest
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
working_dir: /var/www
|
||||
entrypoint: "composer --ignore-platform-reqs"
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
|
||||
npm:
|
||||
image: node:12
|
||||
ports:
|
||||
- "${BROWSERSYNC_PORT}:3000"
|
||||
- "${BROWSERSYNC_ADMIN_PORT}:3001"
|
||||
- "${WEBPACK_PORT}:${WEBPACK_PORT}"
|
||||
environment:
|
||||
MIX_MODE: ${MIX_MODE}
|
||||
MIX_BROWSERSYNC: ${MIX_BROWSERSYNC}
|
||||
entrypoint: "npm run ${MIX_MODE}"
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
- ./docker/nginx/keys:/etc/ssl
|
||||
working_dir: /var/www
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
|
||||
networks:
|
||||
laravel:
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
# Redis should be installed when using Laravel Horizon
|
||||
horizon:
|
||||
environment:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
dockerfile: ./docker/php/Dockerfile
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
depends_on:
|
||||
- mysql
|
||||
- composer
|
||||
working_dir: /var/www
|
||||
entrypoint: ['/var/www/artisan', 'horizon']
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
@@ -0,0 +1,10 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
ports:
|
||||
- "${MAIL_PORT}:1025"
|
||||
- "${MAILHOG_PORT}:8025"
|
||||
networks:
|
||||
- laravel
|
||||
@@ -0,0 +1,2 @@
|
||||
# Ignore SQL dumps
|
||||
*.sql
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen 443 ssl http2;
|
||||
|
||||
ssl_certificate /etc/nginx/ssl/server.crt;
|
||||
ssl_certificate_key /etc/nginx/ssl/server.key;
|
||||
|
||||
index index.php index.html;
|
||||
server_name localhost;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /var/www/public;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
ARG PHP_VERSION
|
||||
|
||||
FROM php:${PHP_VERSION}-fpm-alpine
|
||||
|
||||
WORKDIR /var/www
|
||||
|
||||
COPY docker/php/xdebug.ini /usr/local/etc/php/conf.d
|
||||
|
||||
RUN apk add --no-cache $PHPIZE_DEPS \
|
||||
&& pecl install xdebug \
|
||||
&& docker-php-ext-install pdo pdo_mysql pcntl json posix calendar -j$(getconf _NPROCESSORS_ONLN) \
|
||||
&& docker-php-ext-enable xdebug \
|
||||
&& echo "xdebug.remote_host="`/sbin/ip route|awk '/default/ { print $3 }'` >> /usr/local/etc/php/conf.d/xdebug.ini
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
[Xdebug]
|
||||
xdebug.remote_enable = true
|
||||
xdebug.remote_autostart = false
|
||||
xdebug.remote_port = 9000
|
||||
xdebug.remote_connect_back = false
|
||||
xdebug.idekey = PHPSTORM
|
||||
@@ -0,0 +1,16 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||
PMA_HOST: ${DB_HOST}
|
||||
PMA_PORT: ${DB_PORT}
|
||||
PMA_USER: ${DB_USERNAME}
|
||||
PMA_PASSWORD: ${DB_PASSWORD}
|
||||
UPLOAD_LIMIT: 100000000
|
||||
ports:
|
||||
- "${PHPMYADMIN_PORT}:80"
|
||||
networks:
|
||||
- laravel
|
||||
@@ -0,0 +1,21 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
queue:
|
||||
environment:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
dockerfile: ./docker/php/Dockerfile
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
depends_on:
|
||||
- mysql
|
||||
- composer
|
||||
working_dir: /var/www
|
||||
entrypoint: ['/var/www/artisan', 'queue:work']
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
@@ -0,0 +1,10 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
container_name: redis
|
||||
ports:
|
||||
- "${REDIS_PORT:-6379}:6379"
|
||||
networks:
|
||||
- laravel
|
||||
@@ -0,0 +1,21 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
scheduler:
|
||||
environment:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
PHP_VERSION: ${PHP_VERSION}
|
||||
dockerfile: ./docker/php/Dockerfile
|
||||
volumes:
|
||||
- ./:/var/www
|
||||
depends_on:
|
||||
- mysql
|
||||
- composer
|
||||
working_dir: /var/www
|
||||
entrypoint: ['./docker/scheduler/entrypoint.sh']
|
||||
user: "${USER_ID}:${GROUP_ID}"
|
||||
networks:
|
||||
- laravel
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
while true
|
||||
do
|
||||
php /var/www/artisan schedule:run --verbose --no-interaction &
|
||||
sleep 60
|
||||
done
|
||||
Executable
+293
@@ -0,0 +1,293 @@
|
||||
#!/bin/bash
|
||||
|
||||
DOWNLOADER=
|
||||
GITHUB_URL=https://github.com/AdrienPoupa/laradose
|
||||
VERSION=1.0.1
|
||||
|
||||
install() {
|
||||
if [ -d ./docker ]; then
|
||||
fatal "Laradose is already installed"
|
||||
fi
|
||||
|
||||
echo "Installing Laradose to the current directory..."
|
||||
|
||||
copy_files
|
||||
|
||||
generate_ssl_certificate
|
||||
|
||||
post_install_commands
|
||||
|
||||
configure
|
||||
}
|
||||
|
||||
copy_files() {
|
||||
verify_download curl || verify_download wget || fatal 'curl or wget are required for downloading files'
|
||||
verify_command unzip || fatal 'unzip is required for the installation script'
|
||||
|
||||
echo "Downloading..."
|
||||
download laradose.zip ${GITHUB_URL}/archive/master.zip
|
||||
|
||||
echo "Unzipping..."
|
||||
unzip -q laradose.zip -d laradose
|
||||
|
||||
echo "Copying files..."
|
||||
cp -r ./laradose/laradose-master/docker ./docker
|
||||
cp ./laradose/laradose-master/docker-compose.yml ./
|
||||
cp ./laradose/laradose-master/laradose.sh ./laradose.sh
|
||||
|
||||
cat ./laradose/laradose-master/.env.example >> ./.env.example
|
||||
cat ./laradose/laradose-master/.env.example >> ./.env
|
||||
|
||||
cat ./laradose/laradose-master/webpack.mix.js >> ./webpack.mix.js
|
||||
|
||||
rm -rf ./laradose
|
||||
rm ./laradose.zip
|
||||
}
|
||||
|
||||
generate_ssl_certificate() {
|
||||
echo "Generating SSL certificate..."
|
||||
|
||||
# Create private and public key
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout ./docker/nginx/keys/server.key -out ./docker/nginx/keys/server.crt -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=localhost" > /dev/null 2>&1
|
||||
|
||||
# Create csr file
|
||||
openssl req -new -key ./docker/nginx/keys/server.key -out ./docker/nginx/keys/server.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=localhost" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
update() {
|
||||
echo "Be aware that this command will overwrite any modifications you made to Laradose configuration or Docker images."
|
||||
echo "Please make sure that your folder is versioned so you can revert to the previous state if needed."
|
||||
read -r -p "Press any key to continue..."
|
||||
echo "Updating Laradose..."
|
||||
copy_files
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Menu inspired by https://serverfault.com/a/298312
|
||||
additional_containers_menu() {
|
||||
echo "Select the additional containers you want to enable:"
|
||||
for i in "${!options[@]}"; do
|
||||
printf "%d. %s %s\n" $((i+1)) "${options[i]}" "${choices[i]:-}"
|
||||
done
|
||||
if [[ "$msg" ]]; then echo "$msg"; fi
|
||||
}
|
||||
|
||||
configure() {
|
||||
echo "Laradose configuration"
|
||||
|
||||
# Export the vars in .env into your shell:
|
||||
export $(grep -E -v '^#' .env | xargs)
|
||||
|
||||
options=("Queue" "Redis" "Laravel Horizon" "phpMyAdmin" "MailHog" "Scheduler")
|
||||
folders=("queue" "redis" "horizon" "phpmyadmin" "mailhog" "scheduler")
|
||||
|
||||
# Fill already selected options
|
||||
for i in "${!folders[@]}"; do
|
||||
if [[ $COMPOSE_FILE == *${folders[i]}* ]]; then
|
||||
choices[i]=$'\u2713'
|
||||
fi
|
||||
done
|
||||
|
||||
prompt="Type the container number (again to uncheck, ENTER when done): "
|
||||
while additional_containers_menu && read -rp "$prompt" num && [[ "$num" ]]; do
|
||||
[[ "$num" != *[![:digit:]]* ]] &&
|
||||
(( num > 0 && num <= ${#options[@]} )) ||
|
||||
{ msg="Invalid option: $num"; continue; }
|
||||
((num--)); msg="${options[num]} was ${choices[num]:+un}enabled"
|
||||
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]=$'\u2713'
|
||||
done
|
||||
|
||||
compose_file_input="docker-compose.yml:"
|
||||
for i in "${!options[@]}"; do
|
||||
[[ "${choices[i]}" ]] && compose_file_input=$compose_file_input"docker/${folders[i]}/docker-compose.override.yml":
|
||||
done
|
||||
|
||||
# Remove last :
|
||||
compose_file_input=${compose_file_input%?}
|
||||
|
||||
replace_in_file "s#COMPOSE_PROJECT_NAME=.*#COMPOSE_PROJECT_NAME=${APP_NAME}#" ./.env
|
||||
|
||||
replace_in_file "s#DB_HOST=.*#DB_HOST=mysql#" ./.env
|
||||
|
||||
replace_in_file "s#DB_PASSWORD=.*#DB_PASSWORD=${DB_USERNAME}#" ./.env
|
||||
|
||||
replace_in_file "s#COMPOSE_FILE=.*#COMPOSE_FILE=${compose_file_input}#" ./.env
|
||||
|
||||
env_input "NGINX_HTTPS_PORT" "Nginx HTTPS port"
|
||||
|
||||
env_input "NGINX_HTTP_PORT" "Nginx HTTP port"
|
||||
|
||||
env_input "DB_PORT" "MySQL port"
|
||||
|
||||
env_input "WEBPACK_PORT" "Webpack Development Server port"
|
||||
|
||||
if [[ $compose_file_input == *"redis"* ]]; then
|
||||
replace_in_file "s#REDIS_HOST=.*#REDIS_HOST=redis#" ./.env
|
||||
|
||||
env_input "REDIS_PORT" "Redis port"
|
||||
fi
|
||||
|
||||
if [[ $compose_file_input == *"phpmyadmin"* ]]; then
|
||||
env_input "PHPMYADMIN_PORT" "phpMyAdmin port"
|
||||
fi
|
||||
|
||||
if [[ $compose_file_input == *"mailhog"* ]]; then
|
||||
replace_in_file "s#MAIL_HOST=.*#MAIL_HOST=mailhog#" ./.env
|
||||
|
||||
replace_in_file "s#MAIL_MAILER=.*#MAIL_MAILER=smtp#" ./.env
|
||||
|
||||
replace_in_file "s#MAIL_PORT=.*#MAIL_PORT=1025#" ./.env
|
||||
|
||||
env_input "MAILHOG_PORT" "MailHog port"
|
||||
fi
|
||||
|
||||
env_input "PHP_VERSION" "PHP Version (7.2, 7.3, 7.4)"
|
||||
|
||||
env_input "PHP_SERVER_NAME" "PHP Server Name for xdebug"
|
||||
|
||||
env_input "MYSQL_VERSION" "MySQL Version (5.7, 8)"
|
||||
|
||||
env_input "USER_ID" "Linux User ID for file permissions (current user: $(id -u))"
|
||||
|
||||
env_input "GROUP_ID" "Linux Group ID for file permissions (current group: $(id -g))"
|
||||
|
||||
env_input "MIX_MODE" "Mix mode can be one of: watch, hot, dev, prod"
|
||||
|
||||
env_input "MIX_BROWSERSYNC" "Enable Browsersync (enabled or disabled)"
|
||||
|
||||
if [[ $new_value == "enabled" || $new_value == "" && $MIX_BROWSERSYNC == "enabled" ]]; then
|
||||
env_input "MIX_BROWSERSYNC_PORT" "Browsersync port"
|
||||
|
||||
env_input "MIX_BROWSERSYNC_ADMIN_PORT" "Browsersync admin port"
|
||||
fi
|
||||
|
||||
echo "Configuration complete! Restart docker-compose to apply the changes."
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
env_input() {
|
||||
key=$1
|
||||
description=$2
|
||||
|
||||
read -r -p "$description: [${!key}] " new_value
|
||||
|
||||
if [ -n "$new_value" ]; then
|
||||
replace_in_file "s/${key}=.*/${key}=${new_value}/" ./.env
|
||||
fi
|
||||
}
|
||||
|
||||
# We cant easily use sed since OS X has a different sed implementation than linux. Opting to use perl instead as it
|
||||
# should be readily available in most systems. See https://stackoverflow.com/a/22247781/3781678
|
||||
replace_in_file() {
|
||||
perl -pi -e "$1" "$2"
|
||||
}
|
||||
|
||||
post_install_commands() {
|
||||
echo "Applying permissions..."
|
||||
chown -R "$(id -u)":"$(id -g)" .
|
||||
chmod -R 755 .
|
||||
chmod +x docker/scheduler/entrypoint.sh
|
||||
|
||||
# Add the https argument to the "hot" npm run option,
|
||||
# since the webpack option passed in webpack is apparently not enough
|
||||
replace_in_file "s/--disable-host-check/--disable-host-check --https/" package.json
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo "Uninstalling Laradose..."
|
||||
|
||||
rm -rf ./docker
|
||||
rm ./docker-compose.yml
|
||||
|
||||
echo "Laradose was uninstalled successfully!"
|
||||
echo "You can now remove additional entries from your .env and .env.example files"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
show_menus() {
|
||||
clear
|
||||
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
||||
echo " L A R A D O S E"
|
||||
echo
|
||||
echo "Author: Adrien Poupa"
|
||||
echo "Version: "${VERSION}
|
||||
echo "URL: "${GITHUB_URL}
|
||||
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
||||
echo "1. Configure"
|
||||
echo "2. Update"
|
||||
echo "3. Uninstall"
|
||||
echo "0. Exit"
|
||||
}
|
||||
|
||||
read_options() {
|
||||
local choice
|
||||
read -r -p "Enter choice [1 - 3] " choice
|
||||
case $choice in
|
||||
1) configure ;;
|
||||
2) update ;;
|
||||
3) uninstall ;;
|
||||
*) exit 0;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Credits https://raw.githubusercontent.com/rancher/k3s/master/install.sh
|
||||
verify_download() {
|
||||
verify_command
|
||||
|
||||
# Set verified executable as our downloader program and return success
|
||||
DOWNLOADER=$1
|
||||
return 0
|
||||
}
|
||||
|
||||
# --- verify existence of a command executable ---
|
||||
verify_command() {
|
||||
# Return failure if it doesn't exist or is no executable
|
||||
[ -x "$(command -v "$1")" ] || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
download() {
|
||||
[ $# -eq 2 ] || fatal 'download needs exactly 2 arguments'
|
||||
|
||||
case $DOWNLOADER in
|
||||
curl)
|
||||
curl -o "$1" -sfL "$2"
|
||||
;;
|
||||
wget)
|
||||
wget -qO "$1" "$2"
|
||||
;;
|
||||
*)
|
||||
fatal "Incorrect executable '$DOWNLOADER'"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Abort if download command failed
|
||||
[ $? -eq 0 ] || fatal 'Download failed'
|
||||
}
|
||||
|
||||
fatal() {
|
||||
echo '[ERROR]' "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ "$1" == "--install" ]
|
||||
then
|
||||
install
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
verify_command docker || fatal 'Docker is required for Laradose'
|
||||
verify_command docker-compose || fatal 'docker-compose is required for Laradose'
|
||||
verify_command perl || fatal 'Perl is required for Laradose'
|
||||
|
||||
if ! [ -f ./.env ]; then
|
||||
fatal 'You must have a .env file'
|
||||
fi
|
||||
show_menus
|
||||
read_options
|
||||
done
|
||||
@@ -0,0 +1,39 @@
|
||||
const fs = require('fs');
|
||||
|
||||
if (process.env.MIX_MODE === 'hot') {
|
||||
mix.options({
|
||||
hmrOptions: {
|
||||
host: 'localhost',
|
||||
port: process.env.WEBPACK_PORT,
|
||||
}
|
||||
});
|
||||
mix.webpackConfig({
|
||||
devServer: {
|
||||
https: true,
|
||||
key: fs.readFileSync('/etc/ssl/server.key'),
|
||||
cert: fs.readFileSync('/etc/ssl/server.crt'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
},
|
||||
host: '0.0.0.0',
|
||||
port: process.env.WEBPACK_PORT,
|
||||
public: 'https://localhost:' + process.env.WEBPACK_PORT
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.MIX_BROWSERSYNC === 'enabled') {
|
||||
mix.browserSync({
|
||||
https: {
|
||||
key: "/etc/ssl/server.key",
|
||||
cert: "/etc/ssl/server.crt"
|
||||
},
|
||||
notify: false,
|
||||
open: false,
|
||||
files: [
|
||||
'./resources/views/**/*.blade.php',
|
||||
'./app/**/*.php',
|
||||
],
|
||||
reload: false
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user