1 | /**
|
2 | * Executes a Docker environment.
|
3 | *
|
4 | * This class has a single method, `execute`, which starts a container from an
|
5 | * image and runs the command specified in the Dockerfile `CMD` instruction.
|
6 | *
|
7 | * It mounts the project's directory into the container a `/work` and uses it
|
8 | * as the working directory.
|
9 | *
|
10 | * It also sets the current user and group as the
|
11 | * user and group in the container. This means that within the container the
|
12 | * command that runs has the same permissions as the current user does in the
|
13 | * `/work` directory.
|
14 | *
|
15 | * Finally, it removes the container (but not the image).
|
16 | *
|
17 | * This then is the equivalent of running the container with Docker from within
|
18 | * the project directory using,
|
19 | *
|
20 | * docker run --rm --volume $(pwd):/work --workdir=/work --user=$(id -u):$(id -g) <image>
|
21 | */
|
22 | export default class DockerExecutor {
|
23 | /**
|
24 | * Run a Docker container
|
25 | *
|
26 | * @param name Name of the Docker image to use
|
27 | * @param folder Path of the project folder which will be mounted into the image
|
28 | */
|
29 | execute(name: string, folder: string, command?: string): Promise<any>;
|
30 | }
|