예제 #1
0
        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);
        }
예제 #2
0
        public async Task <List <PortMapping> > DockerPort(IExecutionContext context, string containerId)
        {
            List <string> portMappingLines = await ExecuteDockerCommandAsync(context, "port", containerId);

            return(DockerUtil.ParseDockerPort(portMappingLines));
        }