diff --git a/app/Blueprint/Infrastructure/Service/Events/ServiceWriterWritePreparedEvent.php b/app/Blueprint/Infrastructure/Service/Events/ServiceWriterWritePreparedEvent.php new file mode 100644 index 0000000..f8f300b --- /dev/null +++ b/app/Blueprint/Infrastructure/Service/Events/ServiceWriterWritePreparedEvent.php @@ -0,0 +1,64 @@ +service = $service; + $this->definition = $definition; + } + + /** + * @return Service + */ + public function getService() { + return $this->service; + } + + /** + * @return int + */ + public function getFileVersion(): int + { + return $this->fileVersion; + } + + /** + * @return ServiceYamlDefinition + */ + public function getDefinition(): ServiceYamlDefinition + { + return $this->definition; + } + +} \ No newline at end of file diff --git a/app/Blueprint/Infrastructure/Service/ServiceWriter.php b/app/Blueprint/Infrastructure/Service/ServiceWriter.php index ff8a986..e99a218 100644 --- a/app/Blueprint/Infrastructure/Service/ServiceWriter.php +++ b/app/Blueprint/Infrastructure/Service/ServiceWriter.php @@ -2,6 +2,7 @@ use Rancherize\Blueprint\Infrastructure\Dockerfile\Dockerfile; use Rancherize\Blueprint\Infrastructure\Dockerfile\DockerfileWriter; use Rancherize\Blueprint\Infrastructure\Service\Events\ServiceWriterServicePreparedEvent; +use Rancherize\Blueprint\Infrastructure\Service\Events\ServiceWriterWritePreparedEvent; use Rancherize\Configuration\Exceptions\FileNotFoundException; use Rancherize\File\FileLoader; use Rancherize\File\FileWriter; @@ -180,13 +181,23 @@ public function write(Service $service, FileWriter $fileWriter) { $rancherContentPreparedEvent = new ServiceWriterServicePreparedEvent($service, $content, $volumeDefinitions, $rancherContent); $this->event->dispatch(ServiceWriterServicePreparedEvent::NAME, $rancherContentPreparedEvent); + // might have been changed by the listeners $rancherContent = $rancherContentPreparedEvent->getRancherContent(); $content = $rancherContentPreparedEvent->getDockerContent(); $volumeDefinitions = $rancherContentPreparedEvent->getVolumeDefinition(); - $this->writeYaml($this->path . '/docker-compose.yml', $service, $fileWriter, $content, $volumeDefinitions); - $this->writeYaml($this->path . '/rancher-compose.yml', $service, $fileWriter, $rancherContent); + + $definition = ServiceYamlDefinition::make($content, $rancherContent, $volumeDefinitions); + $this->event->dispatch(ServiceWriterWritePreparedEvent::NAME, + new ServiceWriterWritePreparedEvent( + $service, + $definition + ) + ); + + $this->writeYaml($this->path . '/docker-compose.yml', $service, $fileWriter, $definition->dockerComposeEntry, $definition->volumeDefinition); + $this->writeYaml($this->path . '/rancher-compose.yml', $service, $fileWriter, $definition->rancherComposeEntry); } /** diff --git a/app/Blueprint/Infrastructure/Service/ServiceYamlDefinition.php b/app/Blueprint/Infrastructure/Service/ServiceYamlDefinition.php new file mode 100644 index 0000000..99ad321 --- /dev/null +++ b/app/Blueprint/Infrastructure/Service/ServiceYamlDefinition.php @@ -0,0 +1,39 @@ +dockerComposeEntry = $dockerComposeEntry; + $definition->rancherComposeEntry = $rancherComposeEntry; + $definition->volumeDefinition = $volumeDefinition; + return $definition; + } + +} \ No newline at end of file