You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloudbrain.go 2.1 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package cloudbrain
  2. import (
  3. "errors"
  4. "code.gitea.io/gitea/models"
  5. "code.gitea.io/gitea/modules/context"
  6. "code.gitea.io/gitea/modules/log"
  7. )
  8. const (
  9. Command = `pip3 install jupyterlab==1.1.4;service ssh stop;jupyter lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=\"/userhome\" --port=80 --NotebookApp.token=\"\" --LabApp.allow_origin=\"self https://cloudbrain.pcl.ac.cn\"`
  10. CodeMountPath = "/code"
  11. DataSetMountPath = "/dataset"
  12. ModelMountPath = "/model"
  13. SubTaskName = "task1"
  14. DebugGPUType = "DEBUG"
  15. )
  16. func GenerateTask(ctx *context.Context, jobName, image, command string) error {
  17. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  18. JobName: jobName,
  19. RetryCount: 1,
  20. GpuType: DebugGPUType,
  21. Image: image,
  22. TaskRoles: []models.TaskRole{
  23. {
  24. Name: SubTaskName,
  25. TaskNumber: 1,
  26. MinSucceededTaskCount: 1,
  27. MinFailedTaskCount: 1,
  28. CPUNumber: 2,
  29. GPUNumber: 1,
  30. MemoryMB: 16384,
  31. ShmMB: 8192,
  32. Command: command,
  33. NeedIBDevice: false,
  34. IsMainRole: false,
  35. UseNNI: false,
  36. },
  37. },
  38. Volumes: []models.Volume{
  39. {
  40. HostPath: models.StHostPath{
  41. Path: "",
  42. MountPath: CodeMountPath,
  43. ReadOnly: true,
  44. },
  45. },
  46. {
  47. HostPath: models.StHostPath{
  48. Path: "",
  49. MountPath: DataSetMountPath,
  50. ReadOnly: false,
  51. },
  52. },
  53. {
  54. HostPath: models.StHostPath{
  55. Path: "",
  56. MountPath: ModelMountPath,
  57. ReadOnly: true,
  58. },
  59. },
  60. },
  61. })
  62. if err != nil {
  63. return err
  64. }
  65. if jobResult.Code != "S000" {
  66. log.Error("CreateJob(%s) failed:%s", jobName, jobResult.Msg)
  67. return errors.New(jobResult.Msg)
  68. }
  69. var jobID = jobResult.Payload["jobId"].(string)
  70. err = models.CreateCloudbrain(&models.Cloudbrain{
  71. Status: string(models.JobWaiting),
  72. UserID: ctx.User.ID,
  73. RepoID: ctx.Repo.Repository.ID,
  74. JobID: jobID,
  75. JobName: jobName,
  76. SubTaskName: SubTaskName,
  77. })
  78. if err != nil {
  79. return err
  80. }
  81. return nil
  82. }