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