Skip to content

Commit

Permalink
Merge pull request #1 from redlahatarbus/cmd-and-hostname
Browse files Browse the repository at this point in the history
feat: run container with hostname and command
  • Loading branch information
redlahatarbus authored Aug 16, 2024
2 parents 68a2d6d + 6d85ffe commit a1545d9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ class Container
private ?string $entryPoint = null;

/**
* @var array<string, string>
*/
* @var array<string, string>
*/
private array $env = [];

private Process $process;
private WaitInterface $wait;

private ?string $hostname = null;
private bool $privileged = false;
private ?string $network = null;
private ?string $healthCheckCommand = null;
private int $healthCheckIntervalInMS;
private array $cmd = [];

Check failure on line 41 in src/Container/Container.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Property Testcontainers\Container\Container::$cmd type has no value type specified in iterable type array.

/**
* @var ContainerInspect
Expand Down Expand Up @@ -68,6 +70,13 @@ public function getId(): string
return $this->id;
}

public function withHostname(string $hostname): self
{
$this->hostname = $hostname;

return $this;
}

public function withEntryPoint(string $entryPoint): self
{
$this->entryPoint = $entryPoint;
Expand Down Expand Up @@ -104,6 +113,13 @@ public function withHealthCheckCommand(string $command, int $healthCheckInterval
return $this;
}

public function withCmd(array $cmd): self

Check failure on line 116 in src/Container/Container.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Method Testcontainers\Container\Container::withCmd() has parameter $cmd with no value type specified in iterable type array.
{
$this->cmd = $cmd;

return $this;
}

public function withMount(string $localPath, string $containerPath): self
{
$this->mounts[] = '-v';
Expand Down Expand Up @@ -166,6 +182,11 @@ public function run(bool $wait = true): self
$params[] = $this->network;
}

if ($this->hostname !== null) {
$params[] = '--hostname';
$params[] = $this->hostname;
}

if ($this->entryPoint !== null) {
$params[] = '--entrypoint';
$params[] = $this->entryPoint;
Expand All @@ -177,6 +198,10 @@ public function run(bool $wait = true): self

$params[] = $this->image;

if (count($this->cmd) > 0) {
array_push($params, ...$this->cmd);
}

$this->process = new Process($params);
$this->process->mustRun();

Expand Down

0 comments on commit a1545d9

Please sign in to comment.