core/generate/deploy_builder.go
core/generate/deploy_builder.goBrowse 1970 files
594 tokens
2,150 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package generate2 3import (4 "github.com/railwayapp/railpack/core/plan"5)6 7type DeployBuilder struct {8 Base plan.Layer9 DeployInputs []plan.Layer10 StartCmd string11 Variables map[string]string12 Paths []string13 AptPackages []string14}15 16func NewDeployBuilder() *DeployBuilder {17 return &DeployBuilder{18 Base: plan.NewImageLayer(plan.RailpackRuntimeImage),19 DeployInputs: []plan.Layer{},20 StartCmd: "",21 Variables: map[string]string{},22 Paths: []string{},23 AptPackages: []string{},24 }25}26 27func (b *DeployBuilder) SetInputs(layers []plan.Layer) {28 b.DeployInputs = layers29}30 31func (b *DeployBuilder) AddInputs(layers []plan.Layer) {32 b.DeployInputs = append(b.DeployInputs, layers...)33}34 35func (b *DeployBuilder) HasIncludeForStep(stepName string, path string) bool {36 for _, layer := range b.DeployInputs {37 if layer.Step != stepName {38 continue39 }40 for _, inc := range layer.Include {41 // exact match, or existing include is "." which covers everything42 if inc == path || inc == "." {43 return true44 }45 }46 }47 return false48}49 50// checks if any of the deploy inputs contain a given step name51func (b *DeployBuilder) HasInputForStep(stepName string) bool {52 for _, layer := range b.DeployInputs {53 if layer.Step == stepName {54 return true55 }56 }57 return false58}59 60func (b *DeployBuilder) AddAptPackages(packages []string) {61 b.AptPackages = append(b.AptPackages, packages...)62}63 64func (b *DeployBuilder) Build(p *plan.BuildPlan, options *BuildStepOptions) {65 baseLayer := b.Base66 67 if len(b.AptPackages) > 0 {68 runtimeAptStep := plan.NewStep("packages:apt:runtime")69 runtimeAptStep.Inputs = []plan.Layer{baseLayer}70 runtimeAptStep.AddCommands([]plan.Command{71 options.NewAptInstallCommand(b.AptPackages),72 })73 runtimeAptStep.Caches = options.Caches.GetAptCaches()74 runtimeAptStep.Secrets = []string{}75 p.Steps = append(p.Steps, *runtimeAptStep)76 baseLayer = plan.NewStepLayer(runtimeAptStep.Name)77 }78 79 p.Deploy.Base = baseLayer80 81 p.Deploy.Inputs = append(p.Deploy.Inputs, b.DeployInputs...)82 p.Deploy.StartCmd = b.StartCmd83 p.Deploy.Variables = b.Variables84 p.Deploy.Paths = b.Paths85}86