public void ExpandProperties(Variables variables) { // Expand port mapping variables.ExpandValues(UserPortMappings); // Expand volume mounts variables.ExpandValues(UserMountVolumes); foreach (var volume in UserMountVolumes.Values) { // After mount volume variables are expanded, they are final MountVolumes.Add(new MountVolume(volume)); } }
public ContainerInfo(IHostContext hostContext, Pipelines.JobContainer container, bool isJobContainer = true, string networkAlias = null) { this.ContainerName = container.Alias; string containerImage = container.Image; ArgUtil.NotNullOrEmpty(containerImage, nameof(containerImage)); this.ContainerImage = containerImage; this.ContainerDisplayName = $"{container.Alias}_{Pipelines.Validation.NameValidation.Sanitize(containerImage)}_{Guid.NewGuid().ToString("N").Substring(0, 6)}"; this.ContainerCreateOptions = container.Options; _environmentVariables = container.Environment; this.IsJobContainer = isJobContainer; this.ContainerNetworkAlias = networkAlias; this.RegistryAuthUsername = container.Credentials?.Username; this.RegistryAuthPassword = container.Credentials?.Password; this.RegistryServer = DockerUtil.ParseRegistryHostnameFromImageName(this.ContainerImage); #if OS_WINDOWS _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Work), "C:\\__w")); _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Tools), "C:\\__t")); // Tool cache folder may come from ENV, so we need a unique folder to avoid collision _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Externals), "C:\\__e")); // add -v '\\.\pipe\docker_engine:\\.\pipe\docker_engine' when they are available (17.09) #else _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Work), "/__w")); _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Tools), "/__t")); // Tool cache folder may come from ENV, so we need a unique folder to avoid collision _pathMappings.Add(new PathMapping(hostContext.GetDirectory(WellKnownDirectory.Externals), "/__e")); if (this.IsJobContainer) { this.MountVolumes.Add(new MountVolume("/var/run/docker.sock", "/var/run/docker.sock")); } #endif if (container.Ports?.Count > 0) { foreach (var port in container.Ports) { UserPortMappings[port] = port; } } if (container.Volumes?.Count > 0) { foreach (var volume in container.Volumes) { UserMountVolumes[volume] = volume; MountVolumes.Add(new MountVolume(volume)); } } UpdateWebProxyEnv(hostContext.WebProxy); }
public void ExpandProperties(Variables variables) { // Expand port mapping variables.ExpandValues(UserPortMappings); // Expand volume mounts variables.ExpandValues(UserMountVolumes); foreach (var volume in UserMountVolumes.Values) { // After mount volume variables are expanded, they are final MountVolumes.Add(new MountVolume(volume)); } // Expand env vars variables.ExpandValues(ContainerEnvironmentVariables); // Expand image and options strings ContainerImage = variables.ExpandValue(nameof(ContainerImage), ContainerImage); ContainerCreateOptions = variables.ExpandValue(nameof(ContainerCreateOptions), ContainerCreateOptions); }