Skip to content

Commit f4a2dbe

Browse files
author
Merel Jossart
committed
watchtower
1 parent fafdb4e commit f4a2dbe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Spaceport/Commands/StartCommand.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
4949
private function runDocker(InputInterface $input, OutputInterface $output): void
5050
{
5151
$this->logStep("Building required containers");
52+
$this->startWatchtower();
5253
$this->startMaildev();
5354
$this->startContainers($output);
5455
$this->logSuccess($this->getDockerRunningTextMessage());
@@ -86,6 +87,27 @@ private function startMaildev(): void
8687
}
8788
}
8889

90+
private function startWatchtower()
91+
{
92+
$containerId = $this->runCommand('docker container ls -a -f name=watchtower -q');
93+
//Check if watchtower container is present
94+
if (empty($containerId)) {
95+
$this->logStep('Starting watchtower');
96+
$this->runCommand('docker container run -d --name watchtower --restart always -v /var/run/docker.sock:/var/run/docker.sock:ro containrrr/watchtower --cleanup --include-stopped --interval 3600', 600);
97+
98+
return;
99+
}
100+
101+
//Check if watchtower is running
102+
$containerRunning = $this->runCommand('docker container inspect -f {{.State.Running}} ' . $containerId);
103+
if ($containerRunning === 'false') {
104+
$this->logStep("Starting watchtower");
105+
$this->runCommand('docker start ' . $containerId);
106+
} else {
107+
$this->logStep("Watchtower already running -- Skipping");
108+
}
109+
}
110+
89111
private function getDockerRunningTextMessage(): string
90112
{
91113
return "Docker is up and running.\n\nWebsite ==> localhost:8080\n\nMaildev ==> http://localhost:1080";

0 commit comments

Comments
 (0)