docker compose exemplified, .env integration
This commit is contained in:
1 parent
b1284f6fa9
commit
42ef989fb7
6 files changed
+22
-5
No files matched your search
@@ -4,4 +4,5 @@ config/config.local.php
|
|||||||
logs/app.log
|
logs/app.log
|
||||||
agent-prompts
|
agent-prompts
|
||||||
.env
|
.env
|
||||||
|
docker-compose.yml
|
||||||
~*
|
~*
|
||||||
@@ -115,6 +115,14 @@ CMD ["php", "-S", "0.0.0.0:8080", "-t", "public"]
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Docker Compose
|
### Docker Compose
|
||||||
|
Use the example template as the base for a local override:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp docker-compose.example.yml docker-compose.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Then adapt the local values as needed:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
password-generator:
|
password-generator:
|
||||||
@@ -132,6 +140,7 @@ services:
|
|||||||
CORS_METHODS: "GET,POST,OPTIONS"
|
CORS_METHODS: "GET,POST,OPTIONS"
|
||||||
CORS_HEADERS: "Content-Type,Authorization"
|
CORS_HEADERS: "Content-Type,Authorization"
|
||||||
volumes:
|
volumes:
|
||||||
|
- ./.env:/var/www/html/.env:ro
|
||||||
- ./logs:/var/www/html/logs
|
- ./logs:/var/www/html/logs
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
```
|
```
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ COPY . /var/www/html/
|
|||||||
RUN composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist \
|
RUN composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist \
|
||||||
&& mkdir -p logs \
|
&& mkdir -p logs \
|
||||||
&& chmod 755 logs \
|
&& chmod 755 logs \
|
||||||
&& cp -n .env.example .env \
|
&& if [ ! -f .env ]; then cp .env.example .env; fi \
|
||||||
&& chown -R www-data:www-data /var/www/html
|
&& chown -R www-data:www-data /var/www/html
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|||||||
@@ -219,10 +219,11 @@ docker run --rm -p 8080:8080 --name password-generator password-generator:latest
|
|||||||
|
|
||||||
### Docker Compose (project-local setup)
|
### Docker Compose (project-local setup)
|
||||||
|
|
||||||
The repository includes a project-specific Compose file for local development and testing.
|
The repository ships a compose template rather than a committed local override. Copy it to a host-specific file before running locally.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
|
cp docker-compose.example.yml docker-compose.yml
|
||||||
cp config/config.example.json config/config.json
|
cp config/config.example.json config/config.json
|
||||||
mkdir -p logs
|
mkdir -p logs
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ services:
|
|||||||
CORS_METHODS: "GET,POST,OPTIONS"
|
CORS_METHODS: "GET,POST,OPTIONS"
|
||||||
CORS_HEADERS: "Content-Type,Authorization"
|
CORS_HEADERS: "Content-Type,Authorization"
|
||||||
volumes:
|
volumes:
|
||||||
|
- ./.env:/var/www/html/.env:ro
|
||||||
- ./logs:/var/www/html/logs
|
- ./logs:/var/www/html/logs
|
||||||
- ./config/config.json:/var/www/html/config/config.json:ro
|
- ./config/config.json:/var/www/html/config/config.json:ro
|
||||||
healthcheck:
|
healthcheck:
|
||||||
+8
-3
@@ -9,9 +9,14 @@ use Slim\Factory\AppFactory;
|
|||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
// Load environment variables
|
// Load environment variables when a project .env file is present.
|
||||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
|
// Docker can provide these via env_file/environment as well; in that case
|
||||||
$dotenv->load();
|
// we should not crash if the file is not mounted into the container.
|
||||||
|
$dotenvPath = __DIR__ . '/../';
|
||||||
|
if (is_file($dotenvPath . '.env')) {
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable($dotenvPath);
|
||||||
|
$dotenv->safeLoad();
|
||||||
|
}
|
||||||
|
|
||||||
// Build DI container
|
// Build DI container
|
||||||
$containerBuilder = new ContainerBuilder();
|
$containerBuilder = new ContainerBuilder();
|
||||||
|
|||||||
Reference in new issue
Block a user