Skip to content

Commit

Permalink
feat(script-execution-context): Add support for rootFolder and pullLa…
Browse files Browse the repository at this point in the history
…testImage
  • Loading branch information
stmh committed Oct 30, 2022
1 parent 84a60e3 commit 4b577a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/scripts.md
Expand Up @@ -153,6 +153,8 @@ scripts:
test-in-docker-container:
context: docker-image
image: node:12
pullLatestImage: true
rootFolder: ./some/sub/folder
user: node
script:
- npm install
Expand All @@ -175,7 +177,7 @@ These script execution-contexts are available
* `docker-image`

the script will be executed in a docker-container created with the provided name of the docker-image to use, passing any environment variables to docker if any set. The current folder will be mounted as a volume inside the docker-container at `/app` and the script will be executed as the current user and group (if not a dedicated user is set via `user`). The container will be deleted afterwards, if you need to keep files persistent, make sure to move/ copy them to `/app`
The above example will install the node-based app and execute the `build`-command
The above example will install the node-based app and execute the `build`-command using `some/sub/folder` as the root folder. If you want to skip the pull of the latest image, then set `pullLatestImage` to false.

* `docker-compose-run`

Expand All @@ -190,6 +192,7 @@ These script execution-contexts are available
- vendor/bin/phpunit
context: docker-compose-run
rootFolder: ./hosting/tests
pullLatestImage: true
shellExecutable: /bin/bash # defaults to /bin/sh
service: php
environment:
Expand Down
13 changes: 9 additions & 4 deletions src/Method/ScriptExecutionContext.php
Expand Up @@ -107,7 +107,9 @@ public function enter(ShellProviderInterface $shell): ShellProviderInterface
$this->dockerComposeRootDir = $this->getArgument('rootFolder');
$shell->applyEnvironment($this->getArgument('environment', []));
$shell->cd($this->dockerComposeRootDir);
$shell->run($this->getDockerComposeCmd('pull'), false, true);
if ($this->getArgument('pullLatestImage', true)) {
$shell->run($this->getDockerComposeCmd('pull'), false, true);
}
$shell->run($this->getDockerComposeCmd('build'), false, true);
$this->shell = $shell->startSubShell($this->getDockerComposeCmdAsArray(
'run',
Expand All @@ -119,12 +121,15 @@ public function enter(ShellProviderInterface $shell): ShellProviderInterface
break;

case self::DOCKER_IMAGE:
$working_dir = $shell->realPath($this->workingDir);
$root_folder =$this->getArgument('rootFolder', $this->workingDir);
$working_dir = $shell->realPath($root_folder);
if (!$working_dir) {
throw new \RuntimeException(sprintf('Can\'t resolve working dir %s!', $this->workingDir));
throw new \RuntimeException(sprintf('Can\'t resolve working dir %s!', $root_folder));
}
$shell->applyEnvironment($this->getArgument('environment', []));
$shell->run(sprintf('docker pull %s', $this->getArgument('image')));
if ($this->getArgument('pullLatestImage', true)) {
$shell->run(sprintf('docker pull %s', $this->getArgument('image')));
}
$cmd = [
'docker',
'run',
Expand Down

0 comments on commit 4b577a2

Please sign in to comment.