Skip to content

Commit aa6ab79

Browse files
committed
Merge branch 'docker'
2 parents 5bfeb90 + 157fbee commit aa6ab79

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,47 @@ You can add your own methods to entities and change getter/setter functions, the
184184
## Configuration
185185

186186
see src/Generator/Config.php
187+
188+
# Docker integration
189+
190+
## Entity Generator image
191+
192+
![Docker Pulls](https://img.shields.io/docker/pulls/pifou25/entity-generator)
193+
https://hub.docker.com/r/pifou25/entity-generator
194+
195+
## Generation from existing database
196+
The database should be accessible from the docker network, the hostname is either
197+
the name of the Mysql running container, or `localhost` if db is running on host.
198+
The below command will generate entities into `./entities` directory.
199+
200+
```
201+
docker run --rm -v $PWD/entities:/app/entities --network some-network \
202+
-e MYSQL_HOSTNAME=some-mariadb \
203+
-e MYSQL_DATABASE=exmple-database \
204+
-e MYSQL_USERNAME=example-user \
205+
-e MYSQL_PASSWORD=my_cool_secret \
206+
pifou25/entity-generator
207+
```
208+
209+
## namespace and extends example
210+
The base class must exist into /entities to be declared
211+
```
212+
docker run --rm -v $PWD/include/entities:/app/entities --network scripts_default \
213+
-e MYSQL_HOSTNAME=myhost \
214+
-e MYSQL_DATABASE=mydb \
215+
-e MYSQL_USERNAME=myuser \
216+
-e MYSQL_PASSWORD=mypwd \
217+
-e ENTITY_NAMESPACE=Example\\Pdo\\Entities \
218+
-e BASECLASS=Example\\Pdo\\Entities\Entity \
219+
entity-generator
220+
```
221+
222+
## Generation from flat plain SQL file
223+
224+
The `docker compose` file create a new database and initialize it with SQL data,
225+
you have to put SQL init file into `./examples` directory. When db is ready,
226+
the entity-generator start on it to generate PHP entities.
227+
228+
It is as simple as running this command from the `docker` directory :
229+
`docker compose up`
230+

docker/docker-compose.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.8'
2-
31
networks:
42
default:
53
name: default_network
@@ -16,7 +14,7 @@ services:
1614
- MYSQL_PASSWORD=my-password
1715
volumes:
1816
# directory for init sql and scripts
19-
- ./init:/docker-entrypoint-initdb.d
17+
- ../examples:/docker-entrypoint-initdb.d
2018
healthcheck:
2119
test: ["CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized"]
2220
interval: 1m30s

docker/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$params['baseclass'] = getenv('BASECLASS');
1111
$params['namespace'] = getenv('ENTITY_NAMESPACE');
1212

13-
// vérifier que les paramètres requis pour mysql sont présents
13+
// check all required mysql parameters
1414
if(!isset($params['hostname']) || !isset($params['database']) || !isset($params['username']) || !isset($params['password'])) {
1515
var_dump($params);
1616
die('Missing or bad command line parameters.');

0 commit comments

Comments
 (0)