(composeMap map[string]interface{}, serviceName string, req request.AppContainerConfig, params map[string]interface{})
| 1798 | } |
| 1799 | |
| 1800 | func addDockerComposeCommonParam(composeMap map[string]interface{}, serviceName string, req request.AppContainerConfig, params map[string]interface{}) error { |
| 1801 | services, serviceValid := composeMap["services"].(map[string]interface{}) |
| 1802 | if !serviceValid { |
| 1803 | return buserr.New("ErrFileParse") |
| 1804 | } |
| 1805 | imagePreFix := xpack.MultiNodeProvider.GetImagePrefix() |
| 1806 | if imagePreFix != "" { |
| 1807 | for _, service := range services { |
| 1808 | serviceValue := service.(map[string]interface{}) |
| 1809 | if image, ok := serviceValue["image"]; ok { |
| 1810 | imageStr := image.(string) |
| 1811 | lastSlashIndex := strings.LastIndex(imageStr, "/") |
| 1812 | if lastSlashIndex != -1 { |
| 1813 | imageStr = imageStr[lastSlashIndex+1:] |
| 1814 | } |
| 1815 | imageStr = imagePreFix + "/" + imageStr |
| 1816 | serviceValue["image"] = imageStr |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | service, serviceExist := services[serviceName] |
| 1822 | if !serviceExist { |
| 1823 | return buserr.New("ErrFileParse") |
| 1824 | } |
| 1825 | serviceValue := service.(map[string]interface{}) |
| 1826 | |
| 1827 | deploy := map[string]interface{}{} |
| 1828 | if de, ok := serviceValue["deploy"]; ok { |
| 1829 | deploy = de.(map[string]interface{}) |
| 1830 | } |
| 1831 | resource := map[string]interface{}{} |
| 1832 | if res, ok := deploy["resources"]; ok { |
| 1833 | resource = res.(map[string]interface{}) |
| 1834 | } |
| 1835 | resource["limits"] = map[string]interface{}{ |
| 1836 | "cpus": "${CPUS}", |
| 1837 | "memory": "${MEMORY_LIMIT}", |
| 1838 | } |
| 1839 | if req.GpuConfig { |
| 1840 | resource["reservations"] = map[string]interface{}{ |
| 1841 | "devices": []map[string]interface{}{ |
| 1842 | { |
| 1843 | "driver": "nvidia", |
| 1844 | "count": "all", |
| 1845 | "capabilities": []string{"gpu"}, |
| 1846 | }, |
| 1847 | }, |
| 1848 | } |
| 1849 | } |
| 1850 | deploy["resources"] = resource |
| 1851 | serviceValue["deploy"] = deploy |
| 1852 | |
| 1853 | if req.RestartPolicy != "" { |
| 1854 | if req.RestartPolicy == "on-failure" { |
| 1855 | serviceValue["restart"] = "on-failure:5" |
| 1856 | } else { |
| 1857 | serviceValue["restart"] = req.RestartPolicy |
no test coverage detected