Beispiel #1
0
        private async Task <string> RunSingleImageBuild(DockerfileBuild imageBuild, string proxyNetworkId, IReadOnlyDictionary <string, string> buildMapping, IOutputObserver outputObserver, CancellationToken cancellationToken)
        {
            string id = imageBuild.FromCommand.Image;

            if (id == "scratch")
            {
                throw new Exception("FROM scratch is not supported");
            }

            var state = await InitialBuildState(id);

            foreach (var command in imageBuild.Commands)
            {
                var prevId = id;
                id = command switch {
                    RunExecCommand runExec => await HandleRunExecCommand(state, proxyNetworkId, runExec, outputObserver, cancellationToken),
                    RunShellCommand runShell => await HandleRunShellCommand(state, proxyNetworkId, runShell, outputObserver, cancellationToken),
                    _ => throw new Exception("Unexpected command"),
                };

                if (prevId != imageBuild.FromCommand.Image)
                {
                    await docker.Images.DeleteImageAsync(prevId, new ImageDeleteParameters(), cancellationToken);
                }

                state.Id = id;
            }

            return(id);
        }
Beispiel #2
0
 private Task <string> HandleRunExecCommand(BuildState state, string proxyNetworkId, RunExecCommand runExec, IOutputObserver outputObserver, CancellationToken cancellationToken) =>
 HandleRunCommandCommon(state, proxyNetworkId, runExec.BuildArgs, runExec.ExecCommand, outputObserver, cancellationToken);