791cd4d6af
Build / build (push) Successful in 12m20s
Rebrand the project as Tinyforge to reflect its evolution from a Docker container watcher into a self-hosted mini CI/deployment platform. Rename covers: Go module path, Docker labels, DB/config filenames, JWT issuer, Dockerfile binary, docker-compose, CI workflows, frontend i18n, README with static sites docs, and all code comments.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package deployer
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/alexei/tinyforge/internal/store"
|
|
)
|
|
|
|
// validatePromoteFrom checks that a tag is running in the promote_from stage
|
|
// before allowing it to be deployed to the target stage.
|
|
// Returns nil if no promote_from is configured or if the tag is eligible.
|
|
func (d *Deployer) validatePromoteFrom(stage store.Stage, imageTag string) error {
|
|
if stage.PromoteFrom == "" {
|
|
return nil
|
|
}
|
|
|
|
// Look up the source stage by name within the same project.
|
|
stages, err := d.store.GetStagesByProjectID(stage.ProjectID)
|
|
if err != nil {
|
|
return fmt.Errorf("get stages for project: %w", err)
|
|
}
|
|
|
|
var sourceStage *store.Stage
|
|
for _, s := range stages {
|
|
if s.Name == stage.PromoteFrom {
|
|
sCopy := s
|
|
sourceStage = &sCopy
|
|
break
|
|
}
|
|
}
|
|
|
|
if sourceStage == nil {
|
|
return fmt.Errorf("promote_from stage %q not found in project", stage.PromoteFrom)
|
|
}
|
|
|
|
// Check if the tag is running in the source stage.
|
|
instances, err := d.store.GetInstancesByStageID(sourceStage.ID)
|
|
if err != nil {
|
|
return fmt.Errorf("get instances for source stage: %w", err)
|
|
}
|
|
|
|
for _, inst := range instances {
|
|
if inst.ImageTag == imageTag && (inst.Status == "running" || inst.Status == "stopped") {
|
|
return nil // Tag found in source stage, promotion is allowed.
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("tag %q is not running in stage %q; promotion denied", imageTag, stage.PromoteFrom)
|
|
}
|