Skip to content

Commit

Permalink
feat: adds events for deployments (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Dec 6, 2024
1 parent 6d37883 commit a483245
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
deploy:
uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master
needs: [discover, check, build, test, release]
if: (fromJson(needs.discover.outputs.deployments)[0] != null) && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !failure() && !cancelled()
if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled()
with:
deployments: ${{ needs.discover.outputs.deployments }}
forge_version: ${{ inputs.forge_version }}
Expand Down
7 changes: 7 additions & 0 deletions cli/cmd/cmds/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/input-output-hk/catalyst-forge/cli/pkg/deployment"
"github.com/input-output-hk/catalyst-forge/cli/pkg/events"
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
)

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

eh := events.NewDefaultEventHandler(ctx.Logger)
if !eh.Firing(&project, project.GetDeploymentEvents()) {
ctx.Logger.Info("No deployment event is firing, skipping deployment")
return nil
}

deployer := deployment.NewGitopsDeployer(&project, &ctx.SecretStore, ctx.Logger)
if err := deployer.Load(); err != nil {
return fmt.Errorf("could not load deployer: %w", err)
Expand Down
6 changes: 5 additions & 1 deletion foundry/api/blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ project: {
}
}
deployment: {
on: {
merge: {}
tag: {}
}
environment: "dev"
modules: main: {
container: "foundry-api-deployment"
version: "0.1.1"
values: {
environment: name: "dev"
server: image: {
tag: _ @forge(name="GIT_COMMIT_HASH")
tag: _ @forge(name="GIT_HASH_OR_TAG")
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/project/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ func (p *Project) GetRelativePath() (string, error) {
return relPath, nil
}

// GetDeploymentEvents returns the deployment events for a project.
func (p *Project) GetDeploymentEvents() map[string]cue.Value {
events := make(map[string]cue.Value)
for event := range p.Blueprint.Project.Deployment.On {
config := p.RawBlueprint.Get(fmt.Sprintf("project.deployment.on.%s", event))
events[event] = config
}

return events
}

// GetReleaseEvents returns the release events for a release.
func (p *Project) GetReleaseEvents(releaseName string) map[string]cue.Value {
release, ok := p.Blueprint.Project.Release[releaseName]
Expand Down
5 changes: 5 additions & 0 deletions lib/project/schema/_embed/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ package schema
string
} @go(Environment)

// On contains the events that trigger the deployment.
on: {
...
} @go(On,map[string]any)

// Modules contains the configuration for the deployment modules for the project.
// +optional
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)
Expand Down
3 changes: 3 additions & 0 deletions lib/project/schema/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ type Deployment struct {
// Environment contains the environment to deploy the module to.
Environment string `json:"environment"`

// On contains the events that trigger the deployment.
On map[string]any `json:"on"`

// Modules contains the configuration for the deployment modules for the project.
// +optional
Modules *DeploymentModules `json:"modules"`
Expand Down
3 changes: 3 additions & 0 deletions lib/project/schema/deployment_go_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ package schema
// Environment contains the environment to deploy the module to.
environment: string @go(Environment)

// On contains the events that trigger the deployment.
on: {...} @go(On,map[string]any)

// Modules contains the configuration for the deployment modules for the project.
// +optional
modules?: null | #DeploymentModules @go(Modules,*DeploymentModules)
Expand Down

0 comments on commit a483245

Please sign in to comment.