event.go RawHistoryFolder
1package domain
2
3import (
4 "context"
5 "time"
6)
7
8// EventType defines the type of event that occurred.
9type EventType string
10
11const (
12 EventImagePushed EventType = "image.pushed"
13 EventImageDeleted EventType = "image.deleted"
14 EventConfigReload EventType = "config.reload"
15 EventManualReload EventType = "manual.reload"
16 EventManualDeploy EventType = "manual.deploy"
17 EventContainerStop EventType = "container.stop"
18 EventContainerStart EventType = "container.start"
19 EventContainerHealthCheck EventType = "container.health_check"
20 EventContainerDeployed EventType = "container.deployed"
21 EventSecretsChanged EventType = "secrets.changed"
22)
23
24// Event represents a domain event that occurred in the system.
25type Event struct {
26 ID string
27 Type EventType
28 Timestamp time.Time
29 ImageName string
30 Tag string
31 Route string
32 ContainerID string
33 Data any
34}
35
36// ImagePushedPayload contains data for image.pushed events.
37type ImagePushedPayload struct {
38 Name string
39 Reference string
40 Manifest []byte
41 Annotations map[string]string
42}
43
44// ContainerEventPayload contains data for container events.
45type ContainerEventPayload struct {
46 ContainerID string
47 Domain string
48 Image string
49 Action string
50}
51
52// ConfigReloadPayload contains data for config.reload events.
53type ConfigReloadPayload struct {
54 Source string // "file" or "manual"
55 AddedRoutes []string
56 RemovedRoutes []string
57 UpdatedRoutes []string
58}
59
60// ManualDeployPayload contains data for manual.deploy events.
61type ManualDeployPayload struct {
62 Domain string `json:"domain"`
63}
64
65// SecretsChangedPayload contains data for secrets.changed events.
66type SecretsChangedPayload struct {
67 Domain string // Route domain whose secrets changed
68 Operation string // "set" or "delete"
69 Keys []string // Secret key names (not values)
70}
71
72// Context keys for domain-level concerns.
73type contextKey string
74
75const (
76 // ContextKeyInternalDeploy indicates the deployment is triggered internally
77 // (e.g., from our own registry's image.pushed event) and should use
78 // internal registry authentication for image pulls.
79 ContextKeyInternalDeploy contextKey = "internal_deploy"
80)
81
82// IsInternalDeploy checks if the context indicates an internal deployment.
83func IsInternalDeploy(ctx context.Context) bool {
84 v, ok := ctx.Value(ContextKeyInternalDeploy).(bool)
85 return ok && v
86}
87
88// WithInternalDeploy returns a context marked as an internal deployment.
89func WithInternalDeploy(ctx context.Context) context.Context {
90 return context.WithValue(ctx, ContextKeyInternalDeploy, true)
91}
92
93const (
94 // ContextKeySkipReadiness indicates that readiness checks should be skipped
95 // (e.g., during AutoStart where the background monitor handles crash recovery).
96 ContextKeySkipReadiness contextKey = "skip_readiness"
97)
98
99// WithSkipReadiness returns a context that skips readiness checks on deploy.
100func WithSkipReadiness(ctx context.Context) context.Context {
101 return context.WithValue(ctx, ContextKeySkipReadiness, true)
102}
103
104// IsSkipReadiness checks if the context indicates readiness should be skipped.
105func IsSkipReadiness(ctx context.Context) bool {
106 v, ok := ctx.Value(ContextKeySkipReadiness).(bool)
107 return ok && v
108}