Skip to content
This repository was archived by the owner on Sep 15, 2019. It is now read-only.

Commit 67a9d2b

Browse files
Add options for choosing mysql or postgres
1 parent d42435d commit 67a9d2b

File tree

7 files changed

+85
-7
lines changed

7 files changed

+85
-7
lines changed

src/DockerPreset.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@
33
namespace JasonMcCallister\DockerPreset;
44

55
use Illuminate\Filesystem\Filesystem;
6+
use Illuminate\Support\Facades\Log;
67

78
class DockerPreset
89
{
9-
public static function install()
10+
public static function install(array $options)
1011
{
1112
tap(new Filesystem, function ($filesystem) {
1213
if (!$filesystem->isDirectory($directory = base_path('.docker'))) {
1314
$filesystem->makeDirectory($directory, 0755, true);
1415
}
1516
});
1617

18+
switch ($options['database']) {
19+
case 'PostgreSQL':
20+
copy(__DIR__ . '/stubs/postgres.docker-compose.yaml', base_path('docker-compose.yaml'));
21+
copy(__DIR__ . '/stubs/postgres.Dockerfile', base_path('Dockerfile'));
22+
break;
23+
default:
24+
copy(__DIR__ . '/stubs/mysql.docker-compose.yaml', base_path('docker-compose.yaml'));
25+
copy(__DIR__ . '/stubs/mysql.Dockerfile', base_path('Dockerfile'));
26+
break;
27+
}
28+
1729
copy(__DIR__ . '/stubs/000-default.conf', base_path('.docker/000-default.conf'));
1830
copy(__DIR__ . '/stubs/Makefile', base_path('Makefile'));
19-
copy(__DIR__ . '/stubs/Dockerfile', base_path('Dockerfile'));
20-
copy(__DIR__ . '/stubs/docker-compose.yaml', base_path('docker-compose.yaml'));
2131
copy(__DIR__ . '/stubs/.dockerignore', base_path('.dockerignore'));
2232
}
2333
}

src/DockerPresetServiceProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ class DockerPresetServiceProvider extends ServiceProvider
1010
public function boot()
1111
{
1212
PresetCommand::macro('docker', function ($command) {
13-
// TODO ask what type of database
14-
DockerPreset::install();
13+
$options = [];
14+
15+
$database = $command->choice('What database are you using?', ['MySQL', 'PostgreSQL'], 1);
16+
$options['database'] = $database;
17+
18+
DockerPreset::install($options);
1519

1620
$command->info('Docker scaffolding installed successfully.');
1721
$command->info('You can now run `make up` to get started running your Laravel app locally with Docker!');

src/stubs/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ IMAGE ?= jasonmccallister
44
TAG ?= local
55

66
build:
7-
docker build -t $(IMAGE):$(TAG)
7+
docker build -t $(IMAGE):$(TAG) .
88
composer:
99
docker run --interactive --tty \
1010
--volume $(PWD):/app \
@@ -16,6 +16,8 @@ composer:
1616
composer install --ignore-platform-reqs --no-interaction --no-plugins --prefer-dist
1717
down:
1818
docker-compose down
19+
logs:
20+
docker-compose logs -f
1921
migrate:
2022
docker-compose exec app php artisan migrate
2123
migrate-fresh:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3.6'
2+
services:
3+
app:
4+
image: jasonmccallister/laravel-docker-preset
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- 8000:80
10+
env_file: .env
11+
volumes:
12+
- .:/var/www/html:cached
13+
# uncomment if using laravel passport
14+
# - ./storage/oauth-private.key:/var/www/html/storage/oauth-private.key
15+
# - ./storage/oauth-public.key:/var/www/html/storage/oauth-public.key
16+
db:
17+
image: mysql:5.7
18+
environment:
19+
MYSQL_ROOT_PASSWORD: secret
20+
MYSQL_DATABASE: homestead
21+
MYSQL_USER: homestead
22+
MYSQL_PASSWORD: secret
23+
ports:
24+
- 3306:3306
25+
volumes:
26+
- db_data:/var/lib/mysql
27+
queue:
28+
image: jasonmccallister/laravel-docker-preset
29+
command: ["php", "artisan", "queue:work", "--tries=1"]
30+
build:
31+
context: .
32+
dockerfile: Dockerfile
33+
volumes:
34+
- .:/var/www/html:cached
35+
# uncomment if using laravel passport
36+
# - ./storage/oauth-private.key:/var/www/html/storage/oauth-private.key
37+
# - ./storage/oauth-public.key:/var/www/html/storage/oauth-public.key
38+
redis:
39+
image: redis
40+
ports:
41+
- 6379:6379
42+
volumes:
43+
db_data:

src/stubs/postgres.Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# composer
2+
FROM composer as vendor
3+
COPY database/ database/
4+
# uncomment if using nova
5+
# COPY nova/ nova/
6+
COPY composer.json composer.json
7+
COPY composer.lock composer.lock
8+
RUN composer install --ignore-platform-reqs --no-interaction --no-plugins --no-scripts --prefer-dist
9+
10+
# apache
11+
FROM php:7.2-apache-stretch
12+
RUN apt-get update && apt-get install -y zlib1g-dev
13+
RUN docker-php-source extract && docker-php-ext-install pdo pdo_pgsql pcntl zip bcmath && docker-php-source delete
14+
RUN sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \
15+
sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf && a2enmod rewrite
16+
COPY .docker/000-default.conf /etc/apache2/sites-enabled
17+
COPY . /var/www/html
18+
COPY --from=vendor /app/vendor/ /var/www/html/vendor/
19+
RUN chmod -R 777 /var/www/html/storage /var/www/html/bootstrap/cache
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
# uncomment if using laravel passport
1414
# - ./storage/oauth-private.key:/var/www/html/storage/oauth-private.key
1515
# - ./storage/oauth-public.key:/var/www/html/storage/oauth-public.key
16-
postgres:
16+
db:
1717
image: postgres:11-alpine
1818
environment:
1919
POSTGRES_USER: homestead

0 commit comments

Comments
 (0)