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

Job container + container services #23

Merged
merged 25 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 17 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
63 changes: 0 additions & 63 deletions src/Misc/layoutbin/containerHandlerInvoker.js.template

This file was deleted.

4 changes: 0 additions & 4 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"AgentRunningBehindProxy": "Agent is running behind proxy server: '{0}'",
"AgentVersion": "Current runner version: '{0}'",
"AgentWithSameNameAlreadyExistInPool": "Pool {0} already contains an agent with name {1}.",
"AllowContainerUserRunDocker": "Allow user '{0}' run any docker command without SUDO.",
"AlreadyConfiguredError": "Cannot configure the agent because it is already configured. To reconfigure the agent, run 'config.cmd remove' or './config.sh remove' first.",
"AttachFileNotExist": "Can't attach (type:{0} name:{1}) file: {2}. File does not exist.",
"AttemptRemoveCredFromConfig": "An unsuccessful attempt was made using git command line to remove \"http.extraheader\" from the git config. Attempting to modify the git config file directly to remove the credential.",
Expand Down Expand Up @@ -170,10 +169,8 @@
"ConnectingToServer": "Connecting to server ...",
"ConnectSectionHeader": "Connect",
"ConnectToServer": "Connecting to the server.",
"ContainerJobRequireSystemDefaultWorkDir": "System.DefaultWorkingDirectory is required for running a container job.",
"ContainerWindowsVersionRequirement": "Container feature requires Windows Server 1803 or higher. Please reference documentation (https://go.microsoft.com/fwlink/?linkid=875268)",
"CouldNotRemoveService": "Could not delete service '{0}'",
"CreateUserWithSameUIDInsideContainer": "Try create an user with UID '{0}' inside the container.",
"DeletingCredentials": "Removing .credentials",
"DeletingSettings": "Removing .agent",
"DirectoryHierarchyUnauthorized": "Permission to read the directory contents is required for '{0}' and each directory up the hierarchy. {1}",
Expand All @@ -195,7 +192,6 @@
"FileNotFound": "File not found: '{0}'",
"FinalizeJob": "Finalize Job",
"GenerateAndRunUpdateScript": "Generate and execute update script.",
"GrantContainerUserSUDOPrivilege": "Grant user '{0}' SUDO privilege and allow it run any command without authentication.",
"GrantingFilePermissions": "Granting file permissions to '{0}'.",
"GroupDoesNotExists": "Group: {0} does not Exist",
"InitializeContainer": "Initialize containers",
Expand Down
1 change: 0 additions & 1 deletion src/Runner.Worker/ActionRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public async Task RunAsync()
var containerStepHost = HostContext.CreateService<IContainerStepHost>();
containerStepHost.Container = ExecutionContext.Container;
stepHost = containerStepHost;
throw new NotSupportedException("Call Ting to fix this.");
}

// Load the inputs.
Expand Down
19 changes: 5 additions & 14 deletions src/Runner.Worker/Container/ContainerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,21 @@ public ContainerInfo(IHostContext hostContext, Pipelines.ContainerResource conta

this.ContainerImage = containerImage;
this.ContainerDisplayName = $"{container.Alias}_{Pipelines.Validation.NameValidation.Sanitize(containerImage)}_{Guid.NewGuid().ToString("N").Substring(0, 6)}";
this.ContainerRegistryEndpoint = container.Endpoint?.Id ?? Guid.Empty;
this.ContainerCreateOptions = container.Properties.Get<string>("options");
this.SkipContainerImagePull = container.Properties.Get<bool>("localimage");
_environmentVariables = container.Environment;
this.ContainerEntryPoint = container.Properties.Get<string>("entrypoint", defaultValue: "");
this.ContainerCommand = container.Properties.Get<string>("command", defaultValue: "");
this.ContainerWorkDirectory = container.Properties.Get<string>("workdir", defaultValue: "");
this.IsJobContainer = isJobContainer;

#if OS_WINDOWS
this.ContainerWorkDirectory = "C:\\__w";
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Work)] = this.ContainerWorkDirectory;
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Tools)] = "C:\\__t"; // Tool cache folder may come from ENV, so we need a unique folder to avoid collision
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Work)] = "C:\\__w";
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Root)] = "C:\\__a";
// add -v '\\.\pipe\docker_engine:\\.\pipe\docker_engine' when they are available (17.09)
#else
this.ContainerWorkDirectory = "/__w";
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Work)] = this.ContainerWorkDirectory;
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Tools)] = "/__t"; // Tool cache folder may come from ENV, so we need a unique folder to avoid collision
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Work)] = "/__w";
_pathMappings[hostContext.GetDirectory(WellKnownDirectory.Root)] = "/__a";
if (this.IsJobContainer)
{
this.MountVolumes.Add(new MountVolume("/var/run/docker.sock", "/var/run/docker.sock"));
Expand Down Expand Up @@ -81,17 +78,11 @@ public ContainerInfo(IHostContext hostContext, Pipelines.ContainerResource conta
public string ContainerNetworkAlias { get; set; }
public string ContainerImage { get; set; }
public string ContainerName { get; set; }
public string ContainerEntryPointArgs { get; set; }
public string ContainerEntryPoint { get; set; }
public string ContainerCommand { get; set; }
public string ContainerWorkDirectory { get; set; }
public string ContainerBringNodePath { get; set; }
public Guid ContainerRegistryEndpoint { get; private set; }
public string ContainerCreateOptions { get; private set; }
public bool SkipContainerImagePull { get; private set; }
#if !OS_WINDOWS
public string CurrentUserName { get; set; }
public string CurrentUserId { get; set; }
#endif
public bool IsJobContainer { get; set; }

public IDictionary<string, string> ContainerEnvironmentVariables
Expand Down
23 changes: 19 additions & 4 deletions src/Runner.Worker/Container/DockerCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo
// OPTIONS
dockerOptions.Add($"--name {container.ContainerDisplayName}");
dockerOptions.Add($"--label {DockerInstanceLabel}");
if (!string.IsNullOrEmpty(container.ContainerWorkDirectory))
{
dockerOptions.Add($"--workdir {container.ContainerWorkDirectory}");
dakale marked this conversation as resolved.
Show resolved Hide resolved
}
if (!string.IsNullOrEmpty(container.ContainerNetwork))
{
dockerOptions.Add($"--network {container.ContainerNetwork}");
Expand All @@ -132,9 +136,8 @@ public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo
dockerOptions.Add($"{container.ContainerCreateOptions}");
foreach (var env in container.ContainerEnvironmentVariables)
{
if (String.IsNullOrEmpty(env.Value) && String.IsNullOrEmpty(context.Variables.Get("_VSTS_DONT_RESOLVE_ENV_FROM_HOST")))
if (String.IsNullOrEmpty(env.Value))
{
// TODO: Remove fallback variable if stable
dockerOptions.Add($"-e \"{env.Key}\"");
}
else
Expand Down Expand Up @@ -162,10 +165,18 @@ public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo
}
dockerOptions.Add(volumeArg);
}
if (!string.IsNullOrEmpty(container.ContainerEntryPoint))
{
dockerOptions.Add($"--entrypoint \"{container.ContainerEntryPoint}\"");
}
// IMAGE
dockerOptions.Add($"{container.ContainerImage}");

// COMMAND
dockerOptions.Add($"{container.ContainerCommand}");
// Intentionally blank. Always overwrite ENTRYPOINT and/or send ARGs

// [ARG...]
dockerOptions.Add($"{container.ContainerEntryPointArgs}");

var optionsString = string.Join(" ", dockerOptions);
List<string> outputStrings = await ExecuteDockerCommandAsync(context, "create", optionsString);
Expand Down Expand Up @@ -219,8 +230,12 @@ public async Task<int> DockerRun(IExecutionContext context, ContainerInfo contai
}
// IMAGE
dockerOptions.Add($"{container.ContainerImage}");

// COMMAND
dockerOptions.Add($"{container.ContainerCommand}");
// Intentionally blank. Always overwrite ENTRYPOINT and/or send ARGs

// [ARG...]
dockerOptions.Add($"{container.ContainerEntryPointArgs}");

var optionsString = string.Join(" ", dockerOptions);
return await ExecuteDockerCommandAsync(context, "run", optionsString, stdoutDataReceived, stderrDataReceived, context.CancellationToken);
Expand Down
Loading