Rename "deployment" to "environment": code
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
@@ -9,18 +9,18 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetCurrentDeploymentState(ctx context.Context, store *dagger.Store) *dagger.DeploymentState {
|
||||
func GetCurrentEnvironmentState(ctx context.Context, store *dagger.Store) *dagger.EnvironmentState {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
deploymentName := viper.GetString("deployment")
|
||||
if deploymentName != "" {
|
||||
st, err := store.LookupDeploymentByName(ctx, deploymentName)
|
||||
environmentName := viper.GetString("environment")
|
||||
if environmentName != "" {
|
||||
st, err := store.LookupEnvironmentByName(ctx, environmentName)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Str("deploymentName", deploymentName).
|
||||
Msg("failed to lookup deployment by name")
|
||||
Str("environmentName", environmentName).
|
||||
Msg("failed to lookup environment by name")
|
||||
}
|
||||
return st
|
||||
}
|
||||
@@ -29,50 +29,50 @@ func GetCurrentDeploymentState(ctx context.Context, store *dagger.Store) *dagger
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("cannot get current working directory")
|
||||
}
|
||||
st, err := store.LookupDeploymentByPath(ctx, wd)
|
||||
st, err := store.LookupEnvironmentByPath(ctx, wd)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Str("deploymentPath", wd).
|
||||
Msg("failed to lookup deployment by path")
|
||||
Str("environmentPath", wd).
|
||||
Msg("failed to lookup environment by path")
|
||||
}
|
||||
if len(st) == 0 {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Str("deploymentPath", wd).
|
||||
Msg("no deployments match the current directory")
|
||||
Str("environmentPath", wd).
|
||||
Msg("no environments match the current directory")
|
||||
}
|
||||
if len(st) > 1 {
|
||||
deployments := []string{}
|
||||
environments := []string{}
|
||||
for _, s := range st {
|
||||
deployments = append(deployments, s.Name)
|
||||
environments = append(environments, s.Name)
|
||||
}
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Str("deploymentPath", wd).
|
||||
Strs("deployments", deployments).
|
||||
Msg("multiple deployments match the current directory, select one with `--deployment`")
|
||||
Str("environmentPath", wd).
|
||||
Strs("environments", environments).
|
||||
Msg("multiple environments match the current directory, select one with `--environment`")
|
||||
}
|
||||
return st[0]
|
||||
}
|
||||
|
||||
// Re-compute a deployment (equivalent to `dagger up`).
|
||||
func DeploymentUp(ctx context.Context, state *dagger.DeploymentState, noCache bool) *dagger.Deployment {
|
||||
// Re-compute an environment (equivalent to `dagger up`).
|
||||
func EnvironmentUp(ctx context.Context, state *dagger.EnvironmentState, noCache bool) *dagger.Environment {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
c, err := dagger.NewClient(ctx, "", noCache)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to create client")
|
||||
}
|
||||
result, err := c.Do(ctx, state, func(ctx context.Context, deployment *dagger.Deployment, s dagger.Solver) error {
|
||||
log.Ctx(ctx).Debug().Msg("bringing deployment up")
|
||||
return deployment.Up(ctx, s)
|
||||
result, err := c.Do(ctx, state, func(ctx context.Context, environment *dagger.Environment, s dagger.Solver) error {
|
||||
log.Ctx(ctx).Debug().Msg("bringing environment up")
|
||||
return environment.Up(ctx, s)
|
||||
})
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to up deployment")
|
||||
lg.Fatal().Err(err).Msg("failed to up environment")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ var computeCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
st := &dagger.DeploymentState{
|
||||
st := &dagger.EnvironmentState{
|
||||
ID: uuid.New().String(),
|
||||
Name: "FIXME",
|
||||
PlanSource: dagger.DirInput(args[0], []string{"*.cue", "cue.mod"}),
|
||||
@@ -149,16 +149,16 @@ var computeCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
deployment := common.DeploymentUp(ctx, st, viper.GetBool("no-cache"))
|
||||
environment := common.EnvironmentUp(ctx, st, viper.GetBool("no-cache"))
|
||||
|
||||
v := compiler.NewValue()
|
||||
if err := v.FillPath(cue.MakePath(), deployment.Plan()); err != nil {
|
||||
if err := v.FillPath(cue.MakePath(), environment.Plan()); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to merge")
|
||||
}
|
||||
if err := v.FillPath(cue.MakePath(), deployment.Input()); err != nil {
|
||||
if err := v.FillPath(cue.MakePath(), environment.Input()); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to merge")
|
||||
}
|
||||
if err := v.FillPath(cue.MakePath(), deployment.Computed()); err != nil {
|
||||
if err := v.FillPath(cue.MakePath(), environment.Computed()); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to merge")
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete a deployment after taking it offline (WARNING: may destroy infrastructure)",
|
||||
Short: "Delete an environment after taking it offline (WARNING: may destroy infrastructure)",
|
||||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
var downCmd = &cobra.Command{
|
||||
Use: "down",
|
||||
Short: "Take a deployment offline (WARNING: may destroy infrastructure)",
|
||||
Short: "Take an environment offline (WARNING: may destroy infrastructure)",
|
||||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
var historyCmd = &cobra.Command{
|
||||
Use: "history",
|
||||
Short: "List past changes to a deployment",
|
||||
Short: "List past changes to an environment",
|
||||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
|
@@ -22,7 +22,7 @@ var containerCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentInput(ctx, args[0], dagger.DockerInput(args[1]))
|
||||
updateEnvironmentInput(ctx, args[0], dagger.DockerInput(args[1]))
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ var dirCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentInput(ctx, args[0], dagger.DirInput(args[1], []string{}))
|
||||
updateEnvironmentInput(ctx, args[0], dagger.DirInput(args[1], []string{}))
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ var gitCmd = &cobra.Command{
|
||||
subDir = args[3]
|
||||
}
|
||||
|
||||
updateDeploymentInput(ctx, args[0], dagger.GitInput(args[1], ref, subDir))
|
||||
updateEnvironmentInput(ctx, args[0], dagger.GitInput(args[1], ref, subDir))
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ var jsonCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentInput(
|
||||
updateEnvironmentInput(
|
||||
ctx,
|
||||
args[0],
|
||||
dagger.JSONInput(readInput(ctx, args[1])),
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list [TARGET] [flags]",
|
||||
Short: "List for the inputs of a deployment",
|
||||
Short: "List for the inputs of an environment",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
@@ -35,12 +35,12 @@ var listCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
deployment := common.GetCurrentDeploymentState(ctx, store)
|
||||
environment := common.GetCurrentEnvironmentState(ctx, store)
|
||||
|
||||
// print any persisted inputs
|
||||
if len(deployment.Inputs) > 0 {
|
||||
if len(environment.Inputs) > 0 {
|
||||
fmt.Println("Saved Inputs:")
|
||||
for _, input := range deployment.Inputs {
|
||||
for _, input := range environment.Inputs {
|
||||
// Todo, how to pull apart an input to print relevant information
|
||||
fmt.Printf("%s: %v\n", input.Key, input.Value)
|
||||
}
|
||||
@@ -49,8 +49,8 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
lg = lg.With().
|
||||
Str("deploymentName", deployment.Name).
|
||||
Str("deploymentId", deployment.ID).
|
||||
Str("environmentName", environment.Name).
|
||||
Str("environmentId", environment.ID).
|
||||
Logger()
|
||||
|
||||
c, err := dagger.NewClient(ctx, "", false)
|
||||
@@ -58,7 +58,7 @@ var listCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("unable to create client")
|
||||
}
|
||||
|
||||
_, err = c.Do(ctx, deployment, func(lCtx context.Context, lDeploy *dagger.Deployment, lSolver dagger.Solver) error {
|
||||
_, err = c.Do(ctx, environment, func(lCtx context.Context, lDeploy *dagger.Environment, lSolver dagger.Solver) error {
|
||||
inputs, err := lDeploy.ScanInputs()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -105,7 +105,7 @@ var listCmd = &cobra.Command{
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to query deployment")
|
||||
lg.Fatal().Err(err).Msg("failed to query environment")
|
||||
}
|
||||
|
||||
},
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
// Cmd exposes the top-level command
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "input",
|
||||
Short: "Manage a deployment's inputs",
|
||||
Short: "Manage an environment's inputs",
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -31,7 +31,7 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func updateDeploymentInput(ctx context.Context, target string, input dagger.Input) {
|
||||
func updateEnvironmentInput(ctx context.Context, target string, input dagger.Input) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
store, err := dagger.DefaultStore()
|
||||
@@ -39,13 +39,13 @@ func updateDeploymentInput(ctx context.Context, target string, input dagger.Inpu
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
st := common.GetCurrentDeploymentState(ctx, store)
|
||||
st := common.GetCurrentEnvironmentState(ctx, store)
|
||||
st.SetInput(target, input)
|
||||
|
||||
if err := store.UpdateDeployment(ctx, st, nil); err != nil {
|
||||
lg.Fatal().Err(err).Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("cannot update deployment")
|
||||
if err := store.UpdateEnvironment(ctx, st, nil); err != nil {
|
||||
lg.Fatal().Err(err).Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("cannot update environment")
|
||||
}
|
||||
lg.Info().Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("updated deployment")
|
||||
lg.Info().Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("updated environment")
|
||||
}
|
||||
|
||||
func readInput(ctx context.Context, source string) string {
|
||||
|
@@ -22,7 +22,7 @@ var textCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentInput(
|
||||
updateEnvironmentInput(
|
||||
ctx,
|
||||
args[0],
|
||||
dagger.TextInput(readInput(ctx, args[1])),
|
||||
|
@@ -22,7 +22,7 @@ var yamlCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentInput(
|
||||
updateEnvironmentInput(
|
||||
ctx,
|
||||
args[0],
|
||||
dagger.YAMLInput(readInput(ctx, args[1])),
|
||||
|
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List available deployments",
|
||||
Short: "List available environments",
|
||||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
@@ -35,20 +35,20 @@ var listCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
deployments, err := store.ListDeployments(ctx)
|
||||
environments, err := store.ListEnvironments(ctx)
|
||||
if err != nil {
|
||||
lg.
|
||||
Fatal().
|
||||
Err(err).
|
||||
Msg("cannot list deployments")
|
||||
Msg("cannot list environments")
|
||||
}
|
||||
|
||||
deploymentID := getCurrentDeploymentID(ctx, store)
|
||||
environmentID := getCurrentEnvironmentID(ctx, store)
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
|
||||
for _, r := range deployments {
|
||||
for _, r := range environments {
|
||||
line := fmt.Sprintf("%s\t%s\t", r.Name, formatPlanSource(r.PlanSource))
|
||||
if r.ID == deploymentID {
|
||||
line = fmt.Sprintf("%s- active deployment", line)
|
||||
if r.ID == environmentID {
|
||||
line = fmt.Sprintf("%s- active environment", line)
|
||||
}
|
||||
fmt.Fprintln(w, line)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func getCurrentDeploymentID(ctx context.Context, store *dagger.Store) string {
|
||||
func getCurrentEnvironmentID(ctx context.Context, store *dagger.Store) string {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
@@ -71,7 +71,7 @@ func getCurrentDeploymentID(ctx context.Context, store *dagger.Store) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
st, err := store.LookupDeploymentByPath(ctx, wd)
|
||||
st, err := store.LookupEnvironmentByPath(ctx, wd)
|
||||
if err != nil {
|
||||
// Ignore error
|
||||
return ""
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
var newCmd = &cobra.Command{
|
||||
Use: "new",
|
||||
Short: "Create a new deployment",
|
||||
Short: "Create a new environment",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
@@ -34,41 +34,41 @@ var newCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
if viper.GetString("deployment") != "" {
|
||||
if viper.GetString("environment") != "" {
|
||||
lg.
|
||||
Fatal().
|
||||
Msg("cannot use option -d,--deployment for this command")
|
||||
Msg("cannot use option -d,--environment for this command")
|
||||
}
|
||||
|
||||
name := ""
|
||||
if len(args) > 0 {
|
||||
name = args[0]
|
||||
} else {
|
||||
name = getNewDeploymentName(ctx)
|
||||
name = getNewEnvironmentName(ctx)
|
||||
}
|
||||
|
||||
st := &dagger.DeploymentState{
|
||||
st := &dagger.EnvironmentState{
|
||||
Name: name,
|
||||
PlanSource: getPlanSource(ctx),
|
||||
}
|
||||
|
||||
err = store.CreateDeployment(ctx, st)
|
||||
err = store.CreateEnvironment(ctx, st)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to create deployment")
|
||||
lg.Fatal().Err(err).Msg("failed to create environment")
|
||||
}
|
||||
lg.
|
||||
Info().
|
||||
Str("deploymentId", st.ID).
|
||||
Str("deploymentName", st.Name).
|
||||
Msg("deployment created")
|
||||
Str("environmentId", st.ID).
|
||||
Str("environmentName", st.Name).
|
||||
Msg("environment created")
|
||||
|
||||
if viper.GetBool("up") {
|
||||
common.DeploymentUp(ctx, st, false)
|
||||
common.EnvironmentUp(ctx, st, false)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func getNewDeploymentName(ctx context.Context) string {
|
||||
func getNewEnvironmentName(ctx context.Context) string {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
workDir, err := os.Getwd()
|
||||
@@ -133,7 +133,7 @@ func getPlanSource(ctx context.Context) dagger.Input {
|
||||
}
|
||||
|
||||
func init() {
|
||||
newCmd.Flags().BoolP("up", "u", false, "Bring the deployment online")
|
||||
newCmd.Flags().BoolP("up", "u", false, "Bring the environment online")
|
||||
|
||||
newCmd.Flags().String("plan-dir", "", "Load plan from a local directory")
|
||||
newCmd.Flags().String("plan-git", "", "Load plan from a git repository")
|
||||
|
@@ -5,7 +5,7 @@ import "github.com/spf13/cobra"
|
||||
// Cmd exposes the top-level command
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "output",
|
||||
Short: "Manage a deployment's outputs",
|
||||
Short: "Manage an environment's outputs",
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@@ -22,7 +22,7 @@ var dirCmd = &cobra.Command{
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateDeploymentPlan(ctx, dagger.DirInput(args[0], []string{"*.cue", "cue.mod"}))
|
||||
updateEnvironmentPlan(ctx, dagger.DirInput(args[0], []string{"*.cue", "cue.mod"}))
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ var gitCmd = &cobra.Command{
|
||||
subDir = args[2]
|
||||
}
|
||||
|
||||
updateDeploymentPlan(ctx, dagger.GitInput(args[0], ref, subDir))
|
||||
updateEnvironmentPlan(ctx, dagger.GitInput(args[0], ref, subDir))
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
// Cmd exposes the top-level command
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "plan",
|
||||
Short: "Manage a deployment's plan",
|
||||
Short: "Manage an environment's plan",
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -24,7 +24,7 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func updateDeploymentPlan(ctx context.Context, planSource dagger.Input) {
|
||||
func updateEnvironmentPlan(ctx context.Context, planSource dagger.Input) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
store, err := dagger.DefaultStore()
|
||||
@@ -32,11 +32,11 @@ func updateDeploymentPlan(ctx context.Context, planSource dagger.Input) {
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
st := common.GetCurrentDeploymentState(ctx, store)
|
||||
st := common.GetCurrentEnvironmentState(ctx, store)
|
||||
st.PlanSource = planSource
|
||||
|
||||
if err := store.UpdateDeployment(ctx, st, nil); err != nil {
|
||||
lg.Fatal().Err(err).Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("cannot update deployment")
|
||||
if err := store.UpdateEnvironment(ctx, st, nil); err != nil {
|
||||
lg.Fatal().Err(err).Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("cannot update environment")
|
||||
}
|
||||
lg.Info().Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("updated deployment")
|
||||
lg.Info().Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("updated environment")
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
var queryCmd = &cobra.Command{
|
||||
Use: "query [TARGET] [flags]",
|
||||
Short: "Query the contents of a deployment",
|
||||
Short: "Query the contents of an environment",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
@@ -35,11 +35,11 @@ var queryCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
state := common.GetCurrentDeploymentState(ctx, store)
|
||||
state := common.GetCurrentEnvironmentState(ctx, store)
|
||||
|
||||
lg = lg.With().
|
||||
Str("deploymentName", state.Name).
|
||||
Str("deploymentId", state.ID).
|
||||
Str("environmentName", state.Name).
|
||||
Str("environmentId", state.ID).
|
||||
Logger()
|
||||
|
||||
cuePath := cue.MakePath()
|
||||
@@ -52,21 +52,21 @@ var queryCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("unable to create client")
|
||||
}
|
||||
|
||||
deployment, err := c.Do(ctx, state, nil)
|
||||
environment, err := c.Do(ctx, state, nil)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to query deployment")
|
||||
lg.Fatal().Err(err).Msg("failed to query environment")
|
||||
}
|
||||
|
||||
cueVal := compiler.NewValue()
|
||||
|
||||
if !viper.GetBool("no-plan") {
|
||||
if err := cueVal.FillPath(cue.MakePath(), deployment.Plan()); err != nil {
|
||||
if err := cueVal.FillPath(cue.MakePath(), environment.Plan()); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to merge plan")
|
||||
}
|
||||
}
|
||||
|
||||
if !viper.GetBool("no-input") {
|
||||
if err := cueVal.FillPath(cue.MakePath(), deployment.Input()); err != nil {
|
||||
if err := cueVal.FillPath(cue.MakePath(), environment.Input()); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to merge plan with output")
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func init() {
|
||||
queryCmd.Flags().BoolP("show-attributes", "A", false, "Display field attributes (cue format only)")
|
||||
|
||||
// FIXME: implement the flags below
|
||||
// queryCmd.Flags().String("revision", "latest", "Query a specific version of the deployment")
|
||||
// queryCmd.Flags().String("revision", "latest", "Query a specific version of the environment")
|
||||
queryCmd.Flags().StringP("format", "f", "json", "Output format (json|yaml|cue|text|env)")
|
||||
queryCmd.Flags().BoolP("no-plan", "P", false, "Exclude plan from query")
|
||||
queryCmd.Flags().BoolP("no-input", "I", false, "Exclude inputs from query")
|
||||
|
@@ -17,13 +17,13 @@ import (
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "dagger",
|
||||
Short: "A programmable deployment system",
|
||||
Short: "A programmable environment system",
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().String("log-format", "", "Log format (json, pretty). Defaults to json if the terminal is not a tty")
|
||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "Log level")
|
||||
rootCmd.PersistentFlags().StringP("deployment", "d", "", "Select a deployment")
|
||||
rootCmd.PersistentFlags().StringP("environment", "e", "", "Select an environment")
|
||||
|
||||
rootCmd.AddCommand(
|
||||
computeCmd,
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
var upCmd = &cobra.Command{
|
||||
Use: "up",
|
||||
Short: "Bring a deployment online with latest plan and inputs",
|
||||
Short: "Bring an environment online with latest plan and inputs",
|
||||
Args: cobra.NoArgs,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
@@ -28,11 +28,11 @@ var upCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to load store")
|
||||
}
|
||||
|
||||
state := common.GetCurrentDeploymentState(ctx, store)
|
||||
result := common.DeploymentUp(ctx, state, viper.GetBool("no-cache"))
|
||||
state := common.GetCurrentEnvironmentState(ctx, store)
|
||||
result := common.EnvironmentUp(ctx, state, viper.GetBool("no-cache"))
|
||||
state.Computed = result.Computed().JSON().String()
|
||||
if err := store.UpdateDeployment(ctx, state, nil); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to update deployment")
|
||||
if err := store.UpdateEnvironment(ctx, state, nil); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to update environment")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
64
cmd/spec.cue
64
cmd/spec.cue
@@ -29,27 +29,27 @@ import (
|
||||
description: "Write code to deploy your code"
|
||||
|
||||
doc: """
|
||||
A Dagger deployment is a continuously running workflow delivering a specific application in a specific way.
|
||||
A Dagger environment is a continuously running workflow delivering a specific application in a specific way.
|
||||
|
||||
The same application can be delivered via different deployments, each with a different configuration.
|
||||
For example a production deployment might include manual validation and addition performance testing,
|
||||
while a staging deployment might automatically deploy from a git branch, load test data into the database,
|
||||
The same application can be delivered via different environments, each with a different configuration.
|
||||
For example a production environment might include manual validation and addition performance testing,
|
||||
while a staging environment might automatically deploy from a git branch, load test data into the database,
|
||||
and run on a separate cluster.
|
||||
|
||||
A deployment is made of 3 parts: a deployment plan, inputs, and outputs.
|
||||
An environment is made of 3 parts: a plan, inputs, and outputs.
|
||||
"""
|
||||
|
||||
flag: {
|
||||
"--deployment": {
|
||||
"--environment": {
|
||||
alt: "-d"
|
||||
description:
|
||||
"""
|
||||
Select a deployment
|
||||
Select an environment
|
||||
|
||||
If no deployment is specified, dagger searches for deployments using the current
|
||||
If no environment is specified, dagger searches for environments using the current
|
||||
directory as input.
|
||||
|
||||
* If exactly one deployment matches the search, it is selected.
|
||||
* If exactly one environment matches the search, it is selected.
|
||||
* If there is more than one match, the user is prompted to select one.
|
||||
* If there is no match, the command returns an error.
|
||||
"""
|
||||
@@ -69,25 +69,25 @@ import (
|
||||
|
||||
command: {
|
||||
new: {
|
||||
description: "Create a new deployment"
|
||||
description: "Create a new environment"
|
||||
flag: {
|
||||
"--name": {
|
||||
alt: "-n"
|
||||
description: "Specify a deployment name"
|
||||
description: "Specify an environment name"
|
||||
default: "name of current directory"
|
||||
}
|
||||
|
||||
"--plan-dir": description: "Load deployment plan from a local directory"
|
||||
"--plan-dir": description: "Load plan from a local directory"
|
||||
|
||||
"--plan-git": description: "Load deployment plan from a git repository"
|
||||
"--plan-git": description: "Load plan from a git repository"
|
||||
|
||||
"--plan-package": description: "Load deployment plan from a cue package"
|
||||
"--plan-package": description: "Load plan from a cue package"
|
||||
|
||||
"--plan-file": description: "Load deployment plan from a cue or json file"
|
||||
"--plan-file": description: "Load plan from a cue or json file"
|
||||
|
||||
"--up": {
|
||||
alt: "-u"
|
||||
description: "Bring the deployment online"
|
||||
description: "Bring the environment online"
|
||||
}
|
||||
|
||||
"--setup": {
|
||||
@@ -97,26 +97,26 @@ import (
|
||||
}
|
||||
}
|
||||
|
||||
list: description: "List available deployments"
|
||||
list: description: "List available environments"
|
||||
|
||||
query: {
|
||||
arg: "[EXPR] [flags]"
|
||||
description: "Query the contents of a deployment"
|
||||
description: "Query the contents of an environment"
|
||||
doc:
|
||||
"""
|
||||
EXPR may be any valid CUE expression. The expression is evaluated against the deployment contents. The deployment is not changed.
|
||||
EXPR may be any valid CUE expression. The expression is evaluated against the environment contents. The environment is not changed.
|
||||
Examples:
|
||||
|
||||
# Print the entire deployment plan with inputs merged in (but no outputs)
|
||||
# Print the entire plan with inputs merged in (but no outputs)
|
||||
$ dagger query --no-output
|
||||
|
||||
# Print the deployment plan, inputs and outputs of a particular step
|
||||
# Print the plan, inputs and outputs of a particular step
|
||||
$ dagger query www.build
|
||||
|
||||
# Print the URL of a deployed service
|
||||
$ dagger query api.url
|
||||
|
||||
# Export environment variables from a deployment
|
||||
# Export environment variables from an environment
|
||||
$ dagger query -f json api.environment
|
||||
|
||||
"""
|
||||
@@ -127,7 +127,7 @@ import (
|
||||
// Use --revision or --change or --change-id instead?
|
||||
"--version": {
|
||||
alt: "-v"
|
||||
description: "Query a specific version of the deployment"
|
||||
description: "Query a specific version of the environment"
|
||||
default: "latest"
|
||||
}
|
||||
|
||||
@@ -147,29 +147,29 @@ import (
|
||||
}
|
||||
"--no-plan": {
|
||||
alt: "-L"
|
||||
description: "Exclude deployment plan from query"
|
||||
description: "Exclude plan from query"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
up: {
|
||||
description: "Bring a deployment online with latest deployment plan and inputs"
|
||||
description: "Bring an environment online with latest plan and inputs"
|
||||
flag: "--no-cache": description: "Disable all run cache"
|
||||
}
|
||||
|
||||
down: {
|
||||
description: "Take a deployment offline (WARNING: may destroy infrastructure)"
|
||||
description: "Take an environment offline (WARNING: may destroy infrastructure)"
|
||||
flag: "--no-cache": description: "Disable all run cache"
|
||||
}
|
||||
|
||||
history: description: "List past changes to a deployment"
|
||||
history: description: "List past changes to an environment"
|
||||
|
||||
delete: {
|
||||
description: "Delete a deployment after taking it offline (WARNING: may destroy infrastructure)"
|
||||
description: "Delete an environment after taking it offline (WARNING: may destroy infrastructure)"
|
||||
}
|
||||
|
||||
plan: {
|
||||
description: "Manage a deployment plan"
|
||||
description: "Manage an environment plan"
|
||||
|
||||
command: {
|
||||
package: {
|
||||
@@ -216,7 +216,7 @@ import (
|
||||
}
|
||||
|
||||
input: {
|
||||
description: "Manage a deployment's inputs"
|
||||
description: "Manage an environment's inputs"
|
||||
|
||||
command: {
|
||||
// FIXME: details of individual input commands
|
||||
@@ -229,10 +229,10 @@ import (
|
||||
}
|
||||
|
||||
output: {
|
||||
description: "Manage a deployment's outputs"
|
||||
description: "Manage an environment's outputs"
|
||||
// FIXME: bind output values or artifacts
|
||||
// to local dir or file
|
||||
// BONUS: bind a deployment output to another deployment's input?
|
||||
// BONUS: bind an environment output to another environment's input?
|
||||
}
|
||||
|
||||
login: description: "Login to Dagger Cloud"
|
||||
|
Reference in New Issue
Block a user