Skip to content

Commit 7009699

Browse files
committed
Add publish command for config file
1 parent 3eca0ae commit 7009699

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,23 @@ composer require --dev blamebutton/laravel-docker-builder
88

99
## Configuration
1010

11-
Two environment variables need to be set:
12-
13-
* `DOCKER_NGINX_TAG`
14-
* `DOCKER_PHP_TAG`
15-
16-
This can be done either by adding them to your `.env` file or passing them to the build command.
17-
18-
### Option 1: `.env`
19-
20-
```
21-
DOCKER_NGINX_TAG=laravel-app:nginx
22-
DOCKER_PHP_TAG=laravel-app:php
23-
```
24-
25-
### Option 2: CLI
11+
### Option 1: Config File
2612

2713
```shell
28-
DOCKER_NGINX_TAG=laravel-app:nginx DOCKER_PHP_TAG=laravel-app:php vendor/bin/docker-build
14+
php artisan vendor:publish --provider="BlameButton\LaravelDockerBuilder\DockerServiceProvider"
2915
```
3016

31-
### Option 3: Config File
17+
### Option 2: `.env`
18+
19+
By default, the configuration file reads the following environment variables to determine the Docker image tags.
3220

3321
```shell
34-
php artisan vendor:publish --provider="BlameButton\LaravelDockerBuilder\DockerServiceProvider"
22+
DOCKER_NGINX_TAG=laravel-app:nginx
23+
DOCKER_PHP_TAG=laravel-app:php
3524
```
3625

3726
## Usage
3827

39-
Set the `DOCKER_NGINX_TAG` and `DOCKER_PHP_TAG` environment variables and run:
40-
4128
```shell
42-
vendor/bin/docker-build
29+
php artisan docker:build
4330
```

bin/docker-build

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
source .env
4-
53
PACKAGE="$(dirname "${BASH_SOURCE[0]}")/.."
64

75
if ! [[ -f "${PWD}/public/index.php" ]]; then
@@ -14,6 +12,18 @@ if ! [[ -f "${PWD}/.dockerignore" ]]; then
1412
cp "${PACKAGE}/docker/.dockerignore" "${PWD}/.dockerignore"
1513
fi
1614

15+
if ! [[ -f "$PWD/.docker/nginx.dockerfile" ]]; then
16+
echo "Dockerfile [/.docker/nginx.dockerfile] not found."
17+
echo "Run: php artisan docker:generate"
18+
exit 1
19+
fi
20+
21+
if ! [[ -f "$PWD/.docker/php.dockerfile" ]]; then
22+
echo "Dockerfile [/.docker/php.dockerfile] not found."
23+
echo "Run: php artisan docker:generate"
24+
exit 1
25+
fi
26+
1727
NGINX_TAG="${DOCKER_NGINX_TAG}"
1828
PHP_TAG="${DOCKER_PHP_TAG}"
1929

@@ -27,13 +37,11 @@ if [[ -z "${PHP_TAG}" ]]; then
2737
exit 1
2838
fi
2939

30-
echo "Building [${NGINX_TAG}]"
3140
docker build \
3241
--tag "${NGINX_TAG}" \
3342
--file "${PWD}/.docker/nginx.dockerfile" \
3443
"${PWD}"
3544

36-
echo "Building [${PHP_TAG}]"
3745
docker build \
3846
--tag "${PHP_TAG}" \
3947
--file "${PWD}/.docker/php.dockerfile" \

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"email": "bram@ceulemans.dev"
1010
}
1111
],
12-
"bin": [
13-
"bin/docker-build"
14-
],
1512
"require": {
1613
"php": "^8.0",
1714
"illuminate/contracts": "^9.47",
File renamed without changes.

src/Commands/DockerBuildCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BlameButton\LaravelDockerBuilder\Commands;
44

5-
use BlameButton\LaravelDockerBuilder\DockerServiceProvider;
65
use Symfony\Component\Process\Process;
76

87
class DockerBuildCommand extends BaseCommand
@@ -16,6 +15,10 @@ public function handle(): int
1615
$process = new Process(
1716
command: [$command],
1817
cwd: base_path(),
18+
env: [
19+
'DOCKER_NGINX_TAG' => config('docker-builder.tags.nginx'),
20+
'DOCKER_PHP_TAG' => config('docker-builder.tags.php'),
21+
],
1922
);
2023

2124
$process->run(function ($type, $buffer) {

src/DockerServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public function boot(): void
1818
}
1919

2020
$this->publishes([
21-
__DIR__ . '/../config/docker-build.php' => config_path('docker-build.php'),
21+
__DIR__ . '/../config/docker-builder.php' => config_path('docker-builder.php'),
2222
]);
2323

2424
$this->mergeConfigFrom(
25-
__DIR__ . '/../config/docker-build.php', 'docker-builder',
25+
__DIR__ . '/../config/docker-builder.php', 'docker-builder',
2626
);
2727
}
2828

0 commit comments

Comments
 (0)