Skip to content

Commit 8dbb8f8

Browse files
committed
Enable docker config override (#3908)
1 parent 60c3a9a commit 8dbb8f8

9 files changed

Lines changed: 43 additions & 162 deletions

BUILD.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ I've added the following Powershell scripts to make my life a bit easier, which
4545

4646
* `build.ps1` - Which runs the build but also restores the .env from a backup I make of it in a specifically placed folder. I place a copy of the configured .env file in a folder that has the following path from the working folder: `../env/<working-folder-name>/.env`
4747

48+
### Containerized setup
49+
Development using docker has the advantage that all the application's dependencies are contained within the docker environment. During development we want to have a live version of the code in the container when we edit it. This is accomplished by mounting the application folder within the /app of the docker container.
50+
51+
The file permissions for the repository in the container should be the same as on the host. That's why we have to startthe PHP process in docker with the host current uid.
52+
53+
```
54+
export UID=$(id -u)
55+
export GID=$(id -g)
56+
docker-compose -f docker-compose.dev.yml up
57+
```
58+
4859
## The Result
4960

5061
The build creates a developer version of a runnable instance of OSPOS. It contains a ton of developer stuff that **should not be deployed to a production environment**.

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ CMD ["/app/vendor/phpunit/phpunit/phpunit"]
2121

2222
FROM ospos AS ospos_dev
2323

24-
RUN mkdir -p /app/bower_components && ln -s /app/bower_components /var/www/html/bower_components
2524
RUN yes | pecl install xdebug \
2625
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
2726
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini \

app/Config/Database.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class Database extends Config
7676
*
7777
* @var array
7878
*/
79+
80+
81+
7982
public $development = [
8083
'DSN' => '',
8184
'hostname' => 'localhost',
@@ -102,21 +105,6 @@ public function __construct()
102105
{
103106
parent::__construct();
104107

105-
if(!getenv('database.development.hostname'))
106-
{
107-
$this->development['hostname'] = getenv('database.development.hostname');
108-
}
109-
110-
if(!getenv('database.development.hostname'))
111-
{
112-
$this->development['username'] = getenv('database.development.username');
113-
}
114-
115-
if(!getenv('database.development.hostname'))
116-
{
117-
$this->development['password'] = getenv('database.development.password');
118-
}
119-
120108
// Ensure that we always set the database group to 'tests' if
121109
// we are currently running an automated test suite, so that
122110
// we don't overwrite live data on accident.
@@ -129,5 +117,14 @@ public function __construct()
129117
$this->defaultGroup = 'development';
130118
break;
131119
}
120+
121+
foreach ([&$this->development, &$this->tests, &$this->default] as &$config) {
122+
$config['hostname'] = !getenv('MYSQL_HOST_NAME') ? $config['hostname'] : getenv('MYSQL_HOST_NAME');
123+
$config['username'] = !getenv('MYSQL_USERNAME') ? $config['username'] : getenv('MYSQL_USERNAME');
124+
$config['password'] = !getenv('MYSQL_PASSWORD') ? $config['password'] : getenv('MYSQL_PASSWORD');
125+
$config['database'] = !getenv('MYSQL_DB_NAME') ? $config['database'] : getenv('MYSQL_DB_NAME');
126+
127+
128+
}
132129
}
133130
}

docker-compose.dev.yml

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
version: '2'
2-
3-
volumes:
4-
uploads:
5-
driver: local
6-
logs:
7-
driver: local
8-
mysql:
9-
driver: local
10-
11-
networks:
12-
app_net:
13-
db_net:
1+
version: '3.4'
142

3+
include:
4+
- docker/docker-mysql.yml
155
services:
166
ospos:
177
build:
@@ -26,33 +16,13 @@ services:
2616
- "80:80"
2717
networks:
2818
- app_net
29-
- db_net
3019
volumes:
3120
- .:/app
32-
- uploads:/app/public/uploads
33-
- logs:/app/application/logs
3421
environment:
35-
- PHP_TIMEZONE=UTC
3622
- CI_ENVIRONMENT=development
3723
- MYSQL_USERNAME=admin
3824
- MYSQL_PASSWORD=pointofsale
3925
- MYSQL_DB_NAME=ospos
4026
- MYSQL_HOST_NAME=mysql
41-
- XDEBUG_CONFIG=remote_host=172.17.0.1
42-
43-
mysql:
44-
image: mariadb:10.5
45-
container_name: mysql
46-
restart: always
47-
expose:
48-
- "3306"
49-
networks:
50-
- db_net
51-
volumes:
52-
- ./app/Database:/docker-entrypoint-initdb.d
53-
- mysql:/var/lib/mysql:rw
54-
environment:
55-
- MYSQL_ROOT_PASSWORD=pointofsale
56-
- MYSQL_DATABASE=ospos
57-
- MYSQL_USER=admin
58-
- MYSQL_PASSWORD=pointofsale
27+
- PHP_TIMEZONE=UTC
28+
- XDEBUG_CONFIG=client_host=172.17.0.1

docker-compose.nginx.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.4'
1+
version: '2.2'
22

33
volumes:
44
uploads:
@@ -22,12 +22,11 @@ services:
2222
- "80"
2323
networks:
2424
- app_net
25-
- db_net
2625
volumes:
2726
- uploads:/app/public/uploads
2827
- logs:/app/application/logs
2928
environment:
30-
- CI_ENV=${OSPOS_CI_ENV}
29+
- CI_ENVIRONMENT=${OSPOS_CI_ENV}
3130
- FORCE_HTTPS=true
3231
- PHP_TIMEZONE=UTC
3332
- MYSQL_USERNAME=${OSPOS_MYSQL_USERNAME}
@@ -62,7 +61,6 @@ services:
6261
- "80"
6362
networks:
6463
- app_net
65-
- db_net
6664
environment:
6765
- MYSQL_USERNAME=${OSPOS_MYSQL_USERNAME}
6866
- MYSQL_ROOT_PASSWORD=${OSPOS_MYSQL_ROOT_PASSWORD}

docker-compose.phpmyadmin.yml

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,9 @@
1-
version: '3.4'
1+
version: '2.2'
22

3-
volumes:
4-
uploads:
5-
driver: local
6-
logs:
7-
driver: local
8-
mysql:
9-
driver: local
10-
11-
networks:
12-
app_net:
13-
db_net:
3+
include:
4+
- docker-compose.dev.yml
145

156
services:
16-
ospos:
17-
build:
18-
context: .
19-
target: ospos_dev
20-
container_name: ospos_dev
21-
restart: always
22-
depends_on:
23-
- mysql
24-
ports:
25-
- "80:80"
26-
networks:
27-
- app_net
28-
- db_net
29-
volumes:
30-
- .:/app
31-
- uploads:/app/public/uploads
32-
- logs:/app/application/logs
33-
environment:
34-
- PHP_TIMEZONE=UTC
35-
- MYSQL_USERNAME=admin
36-
- MYSQL_PASSWORD=pointofsale
37-
- MYSQL_DB_NAME=ospos
38-
- MYSQL_HOST_NAME=mysql
39-
- XDEBUG_CONFIG=remote_host=172.17.0.1
40-
41-
mysql:
42-
image: mariadb:10.5
43-
container_name: mysql
44-
restart: always
45-
expose:
46-
- "3306"
47-
networks:
48-
- db_net
49-
volumes:
50-
- ./database/database.sql:/docker-entrypoint-initdb.d/database.sql
51-
- mysql:/var/lib/mysql:rw
52-
environment:
53-
- MYSQL_ROOT_PASSWORD=pointofsale
54-
- MYSQL_DATABASE=ospos
55-
- MYSQL_USER=admin
56-
- MYSQL_PASSWORD=pointofsale
57-
587
phpmyadmin:
598
image: phpmyadmin/phpmyadmin
609
container_name: phpmyadmin
@@ -65,8 +14,7 @@ services:
6514
- "8000:80"
6615
networks:
6716
- app_net
68-
- db_net
6917
environment:
7018
- MYSQL_USERNAME=admin
7119
- MYSQL_ROOT_PASSWORD=pointofsale
72-
- PMA_HOST=mysql
20+
- PMA_HOST=mysql

docker-compose.test.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
version: '3.4'
1+
version: '2.2'
22

3+
include:
4+
- docker/docker-mysql.yaml
5+
36
services:
47
test:
58
build:
@@ -9,7 +12,7 @@ services:
912
- mysql
1013
container_name: ospos_test
1114
environment:
12-
- CI_ENV=testing
15+
- CI_ENVIRONMENT=testing
1316
- ENCRYPTION_KEY=
1417
- MYSQL_HOST_NAME=mysql
1518
- MYSQL_DATABASE=ospos
@@ -19,14 +22,3 @@ services:
1922
ports:
2023
- "80:80"
2124

22-
mysql:
23-
image: mariadb:10.5
24-
container_name: mysql
25-
restart: always
26-
volumes:
27-
- ./database/database.sql:/docker-entrypoint-initdb.d/database.sql
28-
environment:
29-
- MYSQL_ROOT_PASSWORD=pointofsale
30-
- MYSQL_DATABASE=ospos
31-
- MYSQL_USER=admin
32-
- MYSQL_PASSWORD=pointofsale

docker-compose.yml

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
version: '2'
22

3-
volumes:
4-
uploads:
5-
driver: local
6-
logs:
7-
driver: local
8-
mysql:
9-
driver: local
10-
11-
networks:
12-
app_net:
13-
db_net:
3+
include:
4+
- docker/docker-mysql.yml
145

156
services:
167
sqlscript:
17-
image: jekkos/opensourcepos:sql-ci4
8+
image: jekkos/opensourcepos:sql-ci4-branch
189
command: /bin/sh -c 'exit 0'
1910
ospos:
20-
image: jekkos/opensourcepos:ci4-upgrade
11+
image: jekkos/opensourcepos:ci4-branch
2112
restart: always
2213
depends_on:
2314
- mysql
2415
ports:
2516
- "127.0.0.1:80:80"
2617
networks:
2718
- app_net
28-
- db_net
2919
volumes:
3020
- uploads:/app/public/uploads
3121
- logs:/app/application/logs
@@ -38,21 +28,3 @@ services:
3828
- MYSQL_DB_NAME=ospos
3929
- MYSQL_HOST_NAME=mysql
4030

41-
mysql:
42-
image: mariadb:10.5
43-
container_name: mysql
44-
restart: always
45-
expose:
46-
- "3306"
47-
networks:
48-
- db_net
49-
volumes_from:
50-
- sqlscript
51-
volumes:
52-
- mysql:/var/lib/mysql:rw
53-
environment:
54-
- MYSQL_ROOT_PASSWORD=pointofsale
55-
- MYSQL_DATABASE=ospos
56-
- MYSQL_USER=admin
57-
- MYSQL_PASSWORD=pointofsale
58-

docker/build_assets.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)