build.go 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import "time"
  3. // BuildStatus represents the status of a build job.
  4. type BuildStatus string
  5. const (
  6. BuildStatusPending BuildStatus = "pending"
  7. BuildStatusFetching BuildStatus = "fetching"
  8. BuildStatusBuilding BuildStatus = "building"
  9. BuildStatusPushing BuildStatus = "pushing"
  10. BuildStatusSuccess BuildStatus = "success"
  11. BuildStatusFailed BuildStatus = "failed"
  12. BuildStatusCancelled BuildStatus = "cancelled"
  13. )
  14. // BuildRequest represents the information needed to initiate a build.
  15. type BuildRequest struct {
  16. ComponentID uint `json:"component_id"`
  17. Version string `json:"version"` // e.g., git commit hash, tag, or branch
  18. SourceURL string `json:"source_url"` // Git repository URL
  19. RegistryURL string `json:"registry_url"` // Target Docker registry URL
  20. RegistryUser string `json:"registry_user,omitempty"`
  21. RegistryPassword string `json:"registry_password,omitempty"`
  22. ImageName string `json:"image_name"` // Name of the image to build (without tag)
  23. BuildContext string `json:"build_context"` // Path to the Dockerfile within the repo, default "."
  24. Dockerfile string `json:"dockerfile"` // Path to the Dockerfile, default "Dockerfile"
  25. NoCache bool `json:"no_cache"` // Whether to use --no-cache for the build
  26. BuildArgs map[string]string `json:"build_args"` // Build-time variables
  27. Source string `json:"source,omitempty"` // "autodetect", "dockerfile", "docker-compose"
  28. DockerfileContent string `json:"dockerfile_content,omitempty"` // Generated or user-provided Dockerfile content
  29. DockerComposeContent string `json:"docker_compose_content,omitempty"` // docker-compose.yml content
  30. }
  31. // BuildJob represents a build job in the system.
  32. // This will correspond to a 'build_jobs' table in the database.
  33. type BuildJob struct {
  34. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  35. ComponentID uint `json:"component_id" gorm:"not null;index"`
  36. RequestID string `json:"request_id" gorm:"uniqueIndex"` // A unique ID for idempotency if needed
  37. SourceURL string `json:"source_url" gorm:"not null"`
  38. Version string `json:"version"`
  39. Status BuildStatus `json:"status" gorm:"not null;index"`
  40. ImageName string `json:"image_name"` // e.g., myapp
  41. ImageTag string `json:"image_tag"` // e.g., v1.0.0-commitsha
  42. FullImageURI string `json:"full_image_uri"` // e.g., registry.example.com/myapp:v1.0.0-commitsha
  43. RegistryURL string `json:"registry_url"`
  44. RegistryUser string `json:"registry_user,omitempty"`
  45. RegistryPassword string `json:"registry_password,omitempty"` // Consider how to store this securely if at all long-term
  46. BuildContext string `json:"build_context"`
  47. Dockerfile string `json:"dockerfile"`
  48. Source string `json:"source,omitempty"` // "autodetect", "dockerfile", "docker-compose"
  49. NoCache bool `json:"no_cache"`
  50. BuildArgs string `json:"build_args" gorm:"type:text"` // Stored as JSON string or similar
  51. DockerfileContent string `json:"dockerfile_content,omitempty" gorm:"type:text"` // Generated Dockerfile content
  52. Logs string `json:"logs" gorm:"type:text"`
  53. ErrorMessage string `json:"error_message"`
  54. RequestedAt time.Time `json:"requested_at" gorm:"not null;index"`
  55. StartedAt *time.Time `json:"started_at,omitempty"`
  56. FinishedAt *time.Time `json:"finished_at,omitempty"`
  57. WorkerNodeID string `json:"worker_node_id,omitempty"` // ID of the build machine that processed/is processing this job
  58. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  59. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  60. }