Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to run docker container with hostname and command #16

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@
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;

/**
* @var array<string>
*/
private array $cmd = [];
shyim marked this conversation as resolved.
Show resolved Hide resolved

/**
* @var ContainerInspect
*/
Expand Down Expand Up @@ -68,6 +74,13 @@
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 +117,13 @@
return $this;
}

public function withCmd(array $cmd): self

Check failure on line 120 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 +186,11 @@
$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 +202,10 @@

$params[] = $this->image;

if (count($this->cmd) > 0) {
array_push($params, ...$this->cmd);
shyim marked this conversation as resolved.
Show resolved Hide resolved
}

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

Expand Down
Loading