(isCreate bool, req dto.ContainerOperate, oldContainer *container.InspectResponse)
| 1852 | } |
| 1853 | |
| 1854 | func loadConfigInfo(isCreate bool, req dto.ContainerOperate, oldContainer *container.InspectResponse) (*container.Config, *container.HostConfig, *network.NetworkingConfig, error) { |
| 1855 | var config container.Config |
| 1856 | var hostConf container.HostConfig |
| 1857 | if !isCreate { |
| 1858 | config = *oldContainer.Config |
| 1859 | hostConf = *oldContainer.HostConfig |
| 1860 | } |
| 1861 | var networkConf network.NetworkingConfig |
| 1862 | |
| 1863 | portMap, err := checkPortStats(req.ExposedPorts) |
| 1864 | if err != nil { |
| 1865 | return nil, nil, nil, err |
| 1866 | } |
| 1867 | exposed := make(nat.PortSet) |
| 1868 | for port := range portMap { |
| 1869 | exposed[port] = struct{}{} |
| 1870 | } |
| 1871 | config.Image = req.Image |
| 1872 | config.Cmd = req.Cmd |
| 1873 | config.Entrypoint = req.Entrypoint |
| 1874 | config.Env = req.Env |
| 1875 | config.Labels = stringsToMap(req.Labels) |
| 1876 | config.ExposedPorts = exposed |
| 1877 | config.OpenStdin = req.OpenStdin |
| 1878 | config.Tty = req.Tty |
| 1879 | config.Hostname = req.Hostname |
| 1880 | config.Domainname = req.DomainName |
| 1881 | config.User = req.User |
| 1882 | config.WorkingDir = req.WorkingDir |
| 1883 | |
| 1884 | if len(req.Networks) != 0 { |
| 1885 | networkConf.EndpointsConfig = make(map[string]*network.EndpointSettings) |
| 1886 | for _, item := range req.Networks { |
| 1887 | switch item.Network { |
| 1888 | case "host", "none", "bridge": |
| 1889 | hostConf.NetworkMode = container.NetworkMode(item.Network) |
| 1890 | } |
| 1891 | if item.Ipv4 != "" || item.Ipv6 != "" { |
| 1892 | networkConf.EndpointsConfig[item.Network] = &network.EndpointSettings{ |
| 1893 | IPAMConfig: &network.EndpointIPAMConfig{ |
| 1894 | IPv4Address: item.Ipv4, |
| 1895 | IPv6Address: item.Ipv6, |
| 1896 | }, MacAddress: item.MacAddr} |
| 1897 | } else { |
| 1898 | networkConf.EndpointsConfig[item.Network] = &network.EndpointSettings{} |
| 1899 | } |
| 1900 | } |
| 1901 | } else { |
| 1902 | return nil, nil, nil, fmt.Errorf("please set up the network") |
| 1903 | } |
| 1904 | |
| 1905 | hostConf.Privileged = req.Privileged |
| 1906 | hostConf.AutoRemove = req.AutoRemove |
| 1907 | hostConf.CPUShares = req.CPUShares |
| 1908 | hostConf.PublishAllPorts = req.PublishAllPorts |
| 1909 | hostConf.RestartPolicy = container.RestartPolicy{Name: container.RestartPolicyMode(req.RestartPolicy)} |
| 1910 | if req.RestartPolicy == "on-failure" { |
| 1911 | hostConf.RestartPolicy.MaximumRetryCount = 5 |
no test coverage detected