build.go 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. DockerfileContent string `json:"dockerfile_content,omitempty"` // Generated Dockerfile content
  28. }
  29. // BuildJob represents a build job in the system.
  30. // This will correspond to a 'build_jobs' table in the database.
  31. type BuildJob struct {
  32. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  33. ComponentID uint `json:"component_id" gorm:"not null;index"`
  34. RequestID string `json:"request_id" gorm:"uniqueIndex"` // A unique ID for idempotency if needed
  35. SourceURL string `json:"source_url" gorm:"not null"`
  36. Version string `json:"version"`
  37. Status BuildStatus `json:"status" gorm:"not null;index"`
  38. ImageName string `json:"image_name"` // e.g., myapp
  39. ImageTag string `json:"image_tag"` // e.g., v1.0.0-commitsha
  40. FullImageURI string `json:"full_image_uri"` // e.g., registry.example.com/myapp:v1.0.0-commitsha
  41. RegistryURL string `json:"registry_url"`
  42. RegistryUser string `json:"registry_user,omitempty"`
  43. RegistryPassword string `json:"registry_password,omitempty"` // Consider how to store this securely if at all long-term
  44. BuildContext string `json:"build_context"`
  45. Dockerfile string `json:"dockerfile"`
  46. NoCache bool `json:"no_cache"`
  47. BuildArgs string `json:"build_args" gorm:"type:text"` // Stored as JSON string or similar
  48. DockerfileContent string `json:"dockerfile_content,omitempty" gorm:"type:text"` // Generated Dockerfile content
  49. Logs string `json:"logs" gorm:"type:text"`
  50. ErrorMessage string `json:"error_message"`
  51. RequestedAt time.Time `json:"requested_at" gorm:"not null;index"`
  52. StartedAt *time.Time `json:"started_at,omitempty"`
  53. FinishedAt *time.Time `json:"finished_at,omitempty"`
  54. WorkerNodeID string `json:"worker_node_id,omitempty"` // ID of the build machine that processed/is processing this job
  55. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  56. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  57. }