Skip to content
Snippets Groups Projects
Commit 4941d07b authored by jurgenhaas's avatar jurgenhaas
Browse files

composer/plugin/docker4drupal#48 Call external command only if config file changed

parent 99a5647c
No related branches found
Tags v3.0.1
No related merge requests found
...@@ -102,13 +102,29 @@ class Traefik { ...@@ -102,13 +102,29 @@ class Traefik {
if (!$fs->exists($traefikConfigPath)) { if (!$fs->exists($traefikConfigPath)) {
$fs->mkdir($traefikConfigPath); $fs->mkdir($traefikConfigPath);
} }
file_put_contents($traefikConfigPath . '/certificates.toml', $this->defaultCertificatesConfig()); $upd1 = $this->updateFile($traefikConfigPath . '/certificates.toml', $this->defaultCertificatesConfig());
file_put_contents($traefikFile, Yaml::dump($this->defaultDockerCompose(), 9, 2)); $upd2 = $this->updateFile($traefikFile, Yaml::dump($this->defaultDockerCompose(), 9, 2));
$cwd = getcwd(); if ($upd1 || $upd2) {
chdir($traefikPath); $cwd = getcwd();
exec('docker network create traefik-public 2>/dev/null'); chdir($traefikPath);
exec('docker compose --project-name traefik up -d'); exec('docker network create traefik-public 2>/dev/null');
chdir($cwd); exec('docker compose --project-name traefik up -d');
chdir($cwd);
}
}
/**
* @param string $filename
* @param string $content
*
* @return bool
*/
private function updateFile(string $filename, string $content): bool {
if (file_exists($filename) && file_get_contents($filename) === $content) {
return FALSE;
}
file_put_contents($filename, $content);
return TRUE;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment