From 9d1609187e64561780f8c4b79f384c94b1dcb2da Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 26 May 2021 16:25:42 +0200 Subject: [PATCH 1/4] cmd/init,new: added short description Signed-off-by: Sam Alba --- cmd/dagger/cmd/init.go | 5 +++-- cmd/dagger/cmd/input/list.go | 2 +- cmd/dagger/cmd/new.go | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/dagger/cmd/init.go b/cmd/dagger/cmd/init.go index 9d5d1872..36e3bde4 100644 --- a/cmd/dagger/cmd/init.go +++ b/cmd/dagger/cmd/init.go @@ -10,8 +10,9 @@ import ( ) var initCmd = &cobra.Command{ - Use: "init", - Args: cobra.MaximumNArgs(1), + Use: "init", + Short: "Initialize a new empty workspace", + Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: // https://github.com/spf13/viper/issues/233 diff --git a/cmd/dagger/cmd/input/list.go b/cmd/dagger/cmd/input/list.go index 6dd65538..f0309cb9 100644 --- a/cmd/dagger/cmd/input/list.go +++ b/cmd/dagger/cmd/input/list.go @@ -20,7 +20,7 @@ import ( var listCmd = &cobra.Command{ Use: "list [TARGET] [flags]", - Short: "List for the inputs of an environment", + Short: "List the inputs of an environment", Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index 81979cfc..96371951 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -8,8 +8,9 @@ import ( ) var newCmd = &cobra.Command{ - Use: "new", - Args: cobra.ExactArgs(1), + Use: "new", + Short: "Create a new empty environment", + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: // https://github.com/spf13/viper/issues/233 From 1f4bbc53ad0d58d63cf4e2de45f4854fbc5322c9 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 26 May 2021 16:26:13 +0200 Subject: [PATCH 2/4] cmd/init: print workspace path Signed-off-by: Sam Alba --- cmd/dagger/cmd/init.go | 4 +++- state/workspace.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/dagger/cmd/init.go b/cmd/dagger/cmd/init.go index 36e3bde4..aa89d9fe 100644 --- a/cmd/dagger/cmd/init.go +++ b/cmd/dagger/cmd/init.go @@ -36,10 +36,12 @@ var initCmd = &cobra.Command{ dir = cwd } - _, err := state.Init(ctx, dir) + ws, err := state.Init(ctx, dir) if err != nil { lg.Fatal().Err(err).Msg("failed to initialize workspace") } + + lg.Info().Str("path", ws.DaggerDir()).Msg("initialized new empty workspace") }, } diff --git a/state/workspace.go b/state/workspace.go index 6b926390..65253014 100644 --- a/state/workspace.go +++ b/state/workspace.go @@ -268,3 +268,7 @@ func (w *Workspace) Create(ctx context.Context, name string) (*State, error) { return st, nil } + +func (w *Workspace) DaggerDir() string { + return path.Join(w.Path, daggerDir) +} From 97be7b917a6a8fe0b76bed49e6c39015c71e9a76 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 26 May 2021 17:41:37 +0200 Subject: [PATCH 3/4] cmd/new+init: added instructions for new + fix for init arg Signed-off-by: Sam Alba --- cmd/dagger/cmd/init.go | 2 +- cmd/dagger/cmd/new.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/dagger/cmd/init.go b/cmd/dagger/cmd/init.go index aa89d9fe..ca6a4f84 100644 --- a/cmd/dagger/cmd/init.go +++ b/cmd/dagger/cmd/init.go @@ -12,7 +12,7 @@ import ( var initCmd = &cobra.Command{ Use: "init", Short: "Initialize a new empty workspace", - Args: cobra.MaximumNArgs(1), + Args: cobra.NoArgs, PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: // https://github.com/spf13/viper/issues/233 diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index 96371951..8f32cb50 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -1,6 +1,8 @@ package cmd import ( + "fmt" + "github.com/spf13/cobra" "github.com/spf13/viper" "go.dagger.io/dagger/cmd/dagger/cmd/common" @@ -8,7 +10,7 @@ import ( ) var newCmd = &cobra.Command{ - Use: "new", + Use: "new ", Short: "Create a new empty environment", Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { @@ -30,9 +32,13 @@ var newCmd = &cobra.Command{ Msg("cannot use option -e,--environment for this command") } name := args[0] - if _, err := workspace.Create(ctx, name); err != nil { + ws, err := workspace.Create(ctx, name) + if err != nil { lg.Fatal().Err(err).Msg("failed to create environment") } + + lg.Info().Str("name", name).Msg("created new empty environment") + lg.Info().Str("name", name).Msg(fmt.Sprintf("to add code to the plan, copy or create cue files under: %s", ws.Plan)) }, } From 49dcef0614eac9163dc9c7424618cec26383ffb7 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 26 May 2021 17:50:03 +0200 Subject: [PATCH 4/4] examples: updated README to match gitflow UX Signed-off-by: Sam Alba --- examples/README.md | 92 ++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/examples/README.md b/examples/README.md index 61df51a9..5de5c8b1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,33 +11,40 @@ Components: - [Amazon S3](https://aws.amazon.com/s3/) for hosting -1. Change the current directory to the example deployment plan and create a new deployment +1. Initialize a new workspace ```sh cd ./simple-s3 -dagger new +dagger init ``` -2. Configure your AWS credentials +2. Create a new environment ```sh -dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +dagger new simple-s3 +cp *.cue ./.dagger/env/simple-s3/plan/ ``` -3. Specify the source code location +3. Configure your AWS credentials + +```sh +dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY +dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY +``` + +4. Specify the source code location ```sh dagger input dir source website ``` -4. Deploy! +5. Deploy! ```sh dagger up ``` -5. Check the URL +6. Check the URL ```sh curl -i $(dagger query url -f text) @@ -56,23 +63,25 @@ Components: - [Github](https://github.com) for source code hosting - [React-Todo-App](https://github.com/kabirbaidhya/react-todo-app) by Kabir Baidhya as a sample application. -1. Change the current directory to the example deployment plan +1. Initialize a new workspace ```sh cd ./react +dagger init ``` -2. Create a new deployment from the plan +2. Create a new environment ```sh -dagger new +dagger new react +cp *.cue ./.dagger/env/react/plan/ ``` 3. Configure the deployment with your Netlify access token. You can create new tokens from the [Netlify dashboard](https://app.netlify.com/user/applications/personal). ```sh -dagger input text www.account.token MY_TOKEN +dagger input secret www.account.token MY_TOKEN ``` _NOTE: there is a dedicated command for encrypted secret inputs, but it is @@ -95,14 +104,21 @@ This app assumes the following infrastructure is available: - AWS RDS Instance (MySQL or PostgreSQL) - AWS ECR repository -1. Create a new deployment from the plan +1. Initialize a new workspace ```sh -cd ./examples/jamstack -dagger new +cd ./jamstack +dagger init ``` -2. Edit the inputs +2. Create a new environment + +```sh +dagger new jamstack +cp *.cue ./.dagger/env/jamstack/plan/ +``` + +3. Edit the inputs Edit the file `inputs.yaml` and review all values to match to your infrastructure. @@ -112,7 +128,7 @@ Add the inputs to the deployment: dagger input yaml "" -f ./inputs.yaml ``` -1. Deploy! +4. Deploy! ```sh dagger up @@ -126,7 +142,7 @@ dagger input dir backend.source ./my/local/backend/code And the same mechanism applies for every single key in this file. -4. Get the App URL +5. Get the App URL ```sh dagger query url @@ -144,23 +160,25 @@ Components: - [Amazon CloudFormation](https://aws.amazon.com/cloudformation) for infrastructure provisioning - [Kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) as kubernetes client -1. Change the current directory to the example deployment plan +1. Initialize a new workspace ```sh cd ./kubernetes-aws +dagger init ``` -2. Create a new deployment from the plan +2. Create a new environment ```sh -dagger new +dagger new kubernetes-aws +cp *.cue ./.dagger/env/kubernetes-aws/plan/ ``` 3. Configure the deployment with your AWS credentials ```sh -dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY +dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY ``` 4. Deploy! @@ -186,26 +204,28 @@ Components: - [Amazon Cloudwatch Synthetics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html) for hosting the monitoring scripts - [Amazon CloudFormation](https://aws.amazon.com/cloudformation) for infrastructure provisioning -1. Change the current directory to the example deployment plan +1. Initialize a new workspace ```sh cd ./monitoring +dagger init ``` -2. Create a new deployment from the plan +2. Create a new environment ```sh -dagger new +dagger new monitoring +cp *.cue ./.dagger/env/monitoring/plan/ ``` -3. Configure the deployment with your AWS credentials +2. Configure the deployment with your AWS credentials ```sh dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY ``` -4. Configure the monitoring parameters +3. Configure the monitoring parameters ```sh dagger input text website https://MYWEBSITE.TLD @@ -215,7 +235,7 @@ dagger input text website https://MYWEBSITE.TLD dagger input text email my_email@my_domain.tld ``` -5. Deploy! +4. Deploy! ```sh dagger up @@ -235,23 +255,25 @@ Components: How to run: -1. Change the current directory to the example deployment plan +1. Initialize a new workspace ```sh cd ./kubernetes-app +dagger init ``` -2. Create a new deployment from the plan +2. Create a new environment ```sh -dagger new +dagger new kubernetes-app +cp *.cue ./.dagger/env/kubernetes-app/plan/ ``` 3. Configure the deployment with your AWS credentials ```sh -dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY -dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY +dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY ``` 4. Configure the EKS cluster to deploy to @@ -265,7 +287,7 @@ dagger input text cluster.clusterName MY_CLUSTER_NAME 5. Load the Helm chart ```sh -dagger input dir helmChart.chart=./kubernetes-app/testdata/mychart +dagger input dir helmChart.chart ./kubernetes-app/testdata/mychart ``` 6. Deploy!