Skip to content

Commit 41e8ab5

Browse files
committed
feat: adds events for deployments
1 parent 6d37883 commit 41e8ab5

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

cli/cmd/cmds/deploy/deploy.go

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/input-output-hk/catalyst-forge/cli/pkg/deployment"
7+
"github.com/input-output-hk/catalyst-forge/cli/pkg/events"
78
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
89
)
910

@@ -17,6 +18,12 @@ func (c *PushCmd) Run(ctx run.RunContext) error {
1718
return fmt.Errorf("could not load project: %w", err)
1819
}
1920

21+
eh := events.NewDefaultEventHandler(ctx.Logger)
22+
if !eh.Firing(&project, project.GetDeploymentEvents()) {
23+
ctx.Logger.Info("No deployment event is firing, skipping deployment")
24+
return nil
25+
}
26+
2027
deployer := deployment.NewGitopsDeployer(&project, &ctx.SecretStore, ctx.Logger)
2128
if err := deployer.Load(); err != nil {
2229
return fmt.Errorf("could not load deployer: %w", err)

foundry/api/blueprint.cue

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ project: {
1414
}
1515
}
1616
deployment: {
17+
on: {
18+
always: {}
19+
}
1720
environment: "dev"
1821
modules: main: {
1922
container: "foundry-api-deployment"
2023
version: "0.1.1"
2124
values: {
2225
environment: name: "dev"
2326
server: image: {
24-
tag: _ @forge(name="GIT_COMMIT_HASH")
27+
tag: _ @forge(name="GIT_HASH_OR_TAG")
2528
}
2629
}
2730
}

lib/project/project/project.go

+11
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ func (p *Project) GetRelativePath() (string, error) {
8181
return relPath, nil
8282
}
8383

84+
// GetDeploymentEvents returns the deployment events for a project.
85+
func (p *Project) GetDeploymentEvents() map[string]cue.Value {
86+
events := make(map[string]cue.Value)
87+
for event := range p.Blueprint.Project.Deployment.On {
88+
config := p.RawBlueprint.Get(fmt.Sprintf("project.deployment.on.%s", event))
89+
events[event] = config
90+
}
91+
92+
return events
93+
}
94+
8495
// GetReleaseEvents returns the release events for a release.
8596
func (p *Project) GetReleaseEvents(releaseName string) map[string]cue.Value {
8697
release, ok := p.Blueprint.Project.Release[releaseName]

lib/project/schema/_embed/schema.cue

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ package schema
193193
string
194194
} @go(Environment)
195195

196+
// On contains the events that trigger the deployment.
197+
on: {
198+
...
199+
} @go(On,map[string]any)
200+
196201
// Modules contains the configuration for the deployment modules for the project.
197202
// +optional
198203
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)

lib/project/schema/deployment.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ type Deployment struct {
55
// Environment contains the environment to deploy the module to.
66
Environment string `json:"environment"`
77

8+
// On contains the events that trigger the deployment.
9+
On map[string]any `json:"on"`
10+
811
// Modules contains the configuration for the deployment modules for the project.
912
// +optional
1013
Modules *DeploymentModules `json:"modules"`

lib/project/schema/deployment_go_gen.cue

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ package schema
99
// Environment contains the environment to deploy the module to.
1010
environment: string @go(Environment)
1111

12+
// On contains the events that trigger the deployment.
13+
on: {...} @go(On,map[string]any)
14+
1215
// Modules contains the configuration for the deployment modules for the project.
1316
// +optional
1417
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)

0 commit comments

Comments
 (0)