Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 5610b85

Browse files
committed
Added db creation and seeding to Docker env
1 parent b2cbf20 commit 5610b85

11 files changed

+282
-15
lines changed

docker/docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ services:
2020
- default-net
2121
php:
2222
build:
23-
context: php
23+
context: ./php
2424
args:
2525
version: 7.2
2626
dockerfile: ./Dockerfile
27+
depends_on:
28+
- laravel
29+
- mysql
30+
- elastic
2731
volumes:
2832
- laravel:/app/laravel
2933
networks:
@@ -61,6 +65,8 @@ services:
6165
args:
6266
version: 6.2.4
6367
dockerfile: ./Dockerfile
68+
depends_on:
69+
- elastic
6470
environment:
6571
ELASTICSEARCH_URL: http://elastic:9200
6672
networks:

docker/laravel/.env

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
APP_NAME=Laravel
2+
APP_ENV=dev
3+
APP_KEY=base64:9MVmvPpCFaVdPKj3HJGDqnb/hTsvBdcDk2mPkt99e+Y=
4+
APP_DEBUG=true
5+
6+
LOG_CHANNEL=stack
7+
8+
DB_CONNECTION=mysql
9+
DB_HOST=mysql
10+
DB_PORT=3306
11+
DB_DATABASE=laravel
12+
DB_USERNAME=root
13+
DB_PASSWORD=2}3Av>3pWLPuP2
14+
15+
BROADCAST_DRIVER=log
16+
CACHE_DRIVER=file
17+
SESSION_DRIVER=file
18+
SESSION_LIFETIME=120
19+
QUEUE_DRIVER=sync

docker/laravel/Dockerfile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ WORKDIR /app/laravel
77
# Install Laravel
88
RUN composer create-project --no-interaction --prefer-dist laravel/laravel . $version
99

10-
# Todo copy default models, migrations, seeders
10+
# Setup environment
11+
COPY ./docker/laravel/.env .env
1112

12-
# Copy driver package files
13-
COPY . ../scout-elasticsearch-driver
13+
# Copy migrations
14+
RUN rm database/migrations/*
15+
COPY ./docker/laravel/database/migrations/* database/migrations/
1416

15-
# Add driver repository
16-
RUN composer config --no-interaction repositories.scout-elasticsearch-driver \
17-
'{"type": "package", "package": {"name": "babenkoivan/scout-elasticsearch-driver-local", \
18-
"version": "dev", "dist": {"type": "path", "url": "../scout-elasticsearch-driver", \
19-
"options": {"symlink": true}}}}'
17+
# Copy seeders
18+
RUN rm database/seeds/*
19+
COPY ./docker/laravel/database/seeds/* database/seeds/
2020

21-
# Require driver package
22-
RUN composer require --no-interaction babenkoivan/scout-elasticsearch-driver-local:@dev
21+
# Regenerate autoloader
22+
RUN composer dump-autoload
23+
24+
# Bootstrap
25+
COPY ./docker/laravel/bootstrap.sh /usr/local/bin/bootstrap
26+
RUN chmod 544 /usr/local/bin/bootstrap
27+
CMD ["bootstrap"]

docker/laravel/bootstrap.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
# Add driver repository
4+
composer config --no-interaction repositories.scout-elasticsearch-driver \
5+
'{"type": "package", "package": {"name": "babenkoivan/scout-elasticsearch-driver-local",
6+
"version": "dev", "dist": {"type": "path", "url": "../scout-elasticsearch-driver",
7+
"options": {"symlink": true}}}}'
8+
9+
# Require driver package
10+
composer require --no-interaction babenkoivan/scout-elasticsearch-driver-local:@dev
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateCarModelsTable extends Migration
8+
{
9+
/**
10+
* @inheritdoc
11+
*/
12+
public function up()
13+
{
14+
Schema::create('car_models', function (Blueprint $table) {
15+
$table->increments('id');
16+
$table->integer('maker_id');
17+
$table->string('title');
18+
});
19+
}
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function down()
25+
{
26+
Schema::dropIfExists('car_models');
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateCarMakersTable extends Migration
8+
{
9+
/**
10+
* @inheritdoc
11+
*/
12+
public function up()
13+
{
14+
Schema::create('car_makers', function (Blueprint $table) {
15+
$table->increments('id');
16+
$table->string('title');
17+
});
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function down()
24+
{
25+
Schema::dropIfExists('car_makers');
26+
}
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
use Illuminate\Support\Facades\DB;
5+
6+
class CarMakersTableSeeder extends Seeder
7+
{
8+
/**
9+
* @inheritdoc
10+
*/
11+
public function run()
12+
{
13+
$table = DB::table('car_makers');
14+
15+
if ($table->count() > 0) {
16+
return;
17+
}
18+
19+
$table->insert([
20+
'id' => 1,
21+
'title' => 'Audi'
22+
]);
23+
24+
$table->insert([
25+
'id' => 2,
26+
'title' => 'BMW'
27+
]);
28+
29+
$table->insert([
30+
'id' => 3,
31+
'title' => 'Volkswagen'
32+
]);
33+
34+
$table->insert([
35+
'id' => 4,
36+
'title' => 'Volvo'
37+
]);
38+
39+
$table->insert([
40+
'id' => 5,
41+
'title' => 'Kia'
42+
]);
43+
}
44+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
use Illuminate\Support\Facades\DB;
5+
6+
class CarModelsTableSeeder extends Seeder
7+
{
8+
/**
9+
* @inheritdoc
10+
*/
11+
public function run()
12+
{
13+
$table = DB::table('car_models');
14+
15+
if ($table->count() > 0) {
16+
return;
17+
}
18+
19+
$table->insert([
20+
'id' => 1,
21+
'title' => 'A3',
22+
'maker_id' => 1
23+
]);
24+
25+
$table->insert([
26+
'id' => 2,
27+
'title' => 'A4',
28+
'maker_id' => 1
29+
]);
30+
31+
$table->insert([
32+
'id' => 3,
33+
'title' => 'Q3',
34+
'maker_id' => 1
35+
]);
36+
37+
$table->insert([
38+
'id' => 5,
39+
'title' => '1 Series',
40+
'maker_id' => 2
41+
]);
42+
43+
$table->insert([
44+
'id' => 6,
45+
'title' => '3 Series',
46+
'maker_id' => 2
47+
]);
48+
49+
$table->insert([
50+
'id' => 7,
51+
'title' => 'X1',
52+
'maker_id' => 2
53+
]);
54+
55+
$table->insert([
56+
'id' => 8,
57+
'title' => 'Golf',
58+
'maker_id' => 3
59+
]);
60+
61+
$table->insert([
62+
'id' => 9,
63+
'title' => 'Passat',
64+
'maker_id' => 3
65+
]);
66+
67+
$table->insert([
68+
'id' => 10,
69+
'title' => 'Tiguan',
70+
'maker_id' => 3
71+
]);
72+
73+
$table->insert([
74+
'id' => 11,
75+
'title' => 'S60',
76+
'maker_id' => 4
77+
]);
78+
79+
$table->insert([
80+
'id' => 12,
81+
'title' => 'XC40',
82+
'maker_id' => 4
83+
]);
84+
85+
$table->insert([
86+
'id' => 13,
87+
'title' => 'Rio',
88+
'maker_id' => 5
89+
]);
90+
91+
$table->insert([
92+
'id' => 14,
93+
'title' => 'Cerato',
94+
'maker_id' => 5
95+
]);
96+
97+
$table->insert([
98+
'id' => 15,
99+
'title' => 'Stinger',
100+
'maker_id' => 5
101+
]);
102+
}
103+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
5+
class DatabaseSeeder extends Seeder
6+
{
7+
/**
8+
* @inheritdoc
9+
*/
10+
public function run()
11+
{
12+
$this->call([
13+
CarMakersTableSeeder::class,
14+
CarModelsTableSeeder::class
15+
]);
16+
}
17+
}

docker/php/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ ARG version
22

33
FROM php:${version}-cli
44

5-
WORKDIR /app/laravel
6-
75
# Install necessary php extensions
86
RUN docker-php-ext-install \
97
pdo_mysql
108

11-
# Todo run migrations
9+
WORKDIR /app/laravel
1210

13-
ENTRYPOINT ["php", "artisan"]
11+
# Bootstrap
12+
COPY ./bootstrap.sh /usr/local/bin/bootstrap
13+
RUN chmod 544 /usr/local/bin/bootstrap
14+
CMD ["bootstrap"]

0 commit comments

Comments
 (0)