From d39cc200ca6c52d89563b97117967f465b7d628e Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 5 Oct 2021 18:15:38 -0700 Subject: [PATCH 1/3] docs: added abililty to run a local registry for todoapp example Signed-off-by: Sam Alba --- docs/learn/1003-get-started.md | 17 +++++++++-------- docs/learn/tests/doc.bats | 2 +- .../tests/getting-started/plans/local/local.cue | 16 +++++++++++++++- docs/learn/tests/helpers.bash | 3 ++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/docs/learn/1003-get-started.md b/docs/learn/1003-get-started.md index 656a6a36..6b0208b1 100644 --- a/docs/learn/1003-get-started.md +++ b/docs/learn/1003-get-started.md @@ -81,6 +81,7 @@ We will now create the following files: Create the file `plans/todoapp.cue` with the following content: ```cue file=./tests/getting-started/plans/todoapp.cue + ``` This file will define the resources and relationships between them that are common across _all environments_. For example, here we are deploying to our local Docker engine in our `local` environment, but for staging or production as examples, we would deploy the same image to some other container orchestration system such as Kubernetes hosted somewhere out there among the various cloud providers. @@ -125,9 +126,9 @@ dagger -e local input list You should see the following output: ```bash -Input Value Set by user Description -app.source dagger.#Artifact false Application source code -run.socket struct false Mount local docker socket +Input Value Set by user Description +app.source dagger.#Artifact false Application source code +dockerSocket struct false Mount local docker socket ``` Notice that `Set by user` is _false_ for both, because we have not yet provided Dagger with those values. @@ -135,19 +136,19 @@ Notice that `Set by user` is _false_ for both, because we have not yet provided Let’s provide them now: ```shell -dagger -e local input socket run.socket /var/run/docker.sock +dagger -e local input socket dockerSocket /var/run/docker.sock dagger -e local input dir app.source ./ ``` -This defines the `run.socket` as a `socket` input type, and the `app.source` input as a `dir` input type. +This defines the `dockerSocket` as a `socket` input type, and the `app.source` input as a `dir` input type. Now let’s replay the `dagger input list` command: ```bash -Input Value Set by user Description -app.source dagger.#Artifact true Application source code -run.socket struct true Mount local docker socket +Input Value Set by user Description +app.source dagger.#Artifact true Application source code +dockerSocket struct true Mount local docker socket ``` Notice that Dagger now reports that both inputs have been set. diff --git a/docs/learn/tests/doc.bats b/docs/learn/tests/doc.bats index 9b3af3b1..a1a043e8 100644 --- a/docs/learn/tests/doc.bats +++ b/docs/learn/tests/doc.bats @@ -17,7 +17,7 @@ setup() { cp "$DAGGER_PROJECT"/getting-started/plans/local/local.cue "$DAGGER_SANDBOX"/plans/local/local.cue dagger --project "$DAGGER_SANDBOX" new 'local' -p "$DAGGER_SANDBOX"/plans/local - dagger --project "$DAGGER_SANDBOX" -e 'local' input socket run.socket /var/run/docker.sock + dagger --project "$DAGGER_SANDBOX" -e 'local' input socket dockerSocket /var/run/docker.sock dagger --project "$DAGGER_SANDBOX" -e 'local' input dir app.source "$DAGGER_SANDBOX" dagger --project "$DAGGER_SANDBOX" -e 'local' up diff --git a/docs/learn/tests/getting-started/plans/local/local.cue b/docs/learn/tests/getting-started/plans/local/local.cue index 590acffd..d3e0609f 100644 --- a/docs/learn/tests/getting-started/plans/local/local.cue +++ b/docs/learn/tests/getting-started/plans/local/local.cue @@ -5,15 +5,29 @@ import ( "alpha.dagger.io/docker" ) +// docker local socket +dockerSocket: dagger.#Stream & dagger.#Input + // run our todoapp in our local Docker engine run: docker.#Run & { ref: push.ref name: "todoapp" ports: ["8080:80"] - socket: dagger.#Stream & dagger.#Input + socket: dockerSocket +} + +// run our local registry +registry: docker.#Run & { + ref: "registry:2" + name: "registry-local" + ports: ["5000:5000"] + socket: dockerSocket } // push to our local registry // this concrete value satisfies the string constraint // we defined in the previous file push: target: "localhost:5000/todoapp" + +// output the application URL +appURL: "http://localhost:8080/" & dagger.#Output diff --git a/docs/learn/tests/helpers.bash b/docs/learn/tests/helpers.bash index 85334291..394f165c 100644 --- a/docs/learn/tests/helpers.bash +++ b/docs/learn/tests/helpers.bash @@ -40,6 +40,7 @@ setup_example_sandbox() { git -C "$DAGGER_SANDBOX" clone https://github.com/dagger/examples export DAGGER_SANDBOX="$DAGGER_SANDBOX"/examples/todoapp + dagger --project "$DAGGER_SANDBOX" init } @@ -91,4 +92,4 @@ skip_unless_local_kube() { else skip "local kubernetes cluster not available" fi -} \ No newline at end of file +} From 91ad12bff1240f29ffa971d25325905d5b7b8410 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 5 Oct 2021 18:59:34 -0700 Subject: [PATCH 2/3] docs: added missing dagger init Signed-off-by: Sam Alba --- docs/learn/1003-get-started.md | 1 + docs/learn/1004-first-env.md | 2 +- docs/learn/1006-google-cloud-run.md | 9 +++++++- docs/learn/1007-kubernetes.md | 23 ++++++++++++++++++- docs/learn/1008-aws-cloudformation.md | 8 ++++++- .../getting-started/plans/local/local.cue | 2 +- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/learn/1003-get-started.md b/docs/learn/1003-get-started.md index 6b0208b1..f30f505d 100644 --- a/docs/learn/1003-get-started.md +++ b/docs/learn/1003-get-started.md @@ -170,6 +170,7 @@ push.ref "localhost:5000/todoapp:latest@sha256:" Image ref push.digest "sha256:" Image digest run.ref "localhost:5000/todoapp:latest@sha256:" Image reference (e.g: nginx:alpine) run.run.env.IMAGE_REF "localhost:5000/todoapp:latest@sha256:" - +appURL "http://localhost:8080/" Application URL ``` Congratulations! You’ve deployed your first Dagger plan! You can now [view the todo app](http://localhost:8080) in your browser! diff --git a/docs/learn/1004-first-env.md b/docs/learn/1004-first-env.md index 9b439d8f..dcdc85d0 100644 --- a/docs/learn/1004-first-env.md +++ b/docs/learn/1004-first-env.md @@ -92,7 +92,7 @@ Otherwise, don't worry: a Cue module is simply a directory with one or more Cue This guide will use the same directory as the root of the Dagger project and the Cue module, but you can create your Cue module anywhere inside the Dagger project. In general, you won't have to worry about it at all. You will initialize a dagger project with the following command. ```shell -dagger init # Optional, already present in `todoapp` +dagger init ``` > In our case, `todoapp` already contains a `.dagger` directory, so this step is optional. diff --git a/docs/learn/1006-google-cloud-run.md b/docs/learn/1006-google-cloud-run.md index beec5f1e..da473cc5 100644 --- a/docs/learn/1006-google-cloud-run.md +++ b/docs/learn/1006-google-cloud-run.md @@ -36,13 +36,20 @@ mkdir gcpcloudrun ### Create a basic plan ```cue file=./tests/gcpcloudrun/source.cue title="todoapp/cue.mod/gcpcloudrun/source.cue" + ``` ## Set up the environment ### Create a new environment -Now that your Cue package is ready, let's create an environment to run it: +Let's create a project: + +```shell +dagger init +``` + +Let's create an environment to run it: ```shell dagger new 'gcpcloudrun' -p ./gcpcloudrun diff --git a/docs/learn/1007-kubernetes.md b/docs/learn/1007-kubernetes.md index c55dc680..5a1774bb 100644 --- a/docs/learn/1007-kubernetes.md +++ b/docs/learn/1007-kubernetes.md @@ -151,6 +151,7 @@ kubectl delete -f k8s/ Create a file named `todoapp.cue` and add the following configuration to it. ```cue file=tests/kube-kind/basic/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` This defines a `todoApp` variable containing the Kubernetes objects used to create a todoapp deployment. It also @@ -169,6 +170,7 @@ The following `config.cue` defines: - `kubeconfig` a generic value created to embed this string `kubeconfig` value ```cue file=tests/kube-kind/config.cue title="todoapp/kube/config.cue" + ``` @@ -183,6 +185,7 @@ The below `config.cue` defines: using `alpha.dagger.io/gcp/gke` ```cue file=tests/kube-gcp/basic/config.cue title="todoapp/kube/config.cue" + ``` @@ -197,6 +200,7 @@ The below `config.cue` defines: using `alpha.dagger.io/aws/eks` ```cue file=tests/kube-aws/basic/config.cue title="todoapp/kube/config.cue" + ``` @@ -207,7 +211,13 @@ The below `config.cue` defines: #### Create a new environment -Now that your Cue package is ready, let's create an environment to run it: +Let's create a project: + +```shell +dagger init +``` + +Let's create an environment to run it: ```shell dagger new 'kube' -p kube @@ -390,6 +400,7 @@ Let's see how to deploy an image locally and push it to the local cluster - `kustomization`, apply kustomization to image ```cue file=tests/kube-kind/deployment/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` @@ -406,6 +417,7 @@ The two files have to be edited to do so. - definition of a new `gcrCreds` value that contains ecr credentials for remote image push to GCR ```cue file=tests/kube-gcp/deployment/config.cue title="todoapp/kube/config.cue" + ``` `kube/todoapp.cue`, on the other hand, faces these changes: @@ -417,6 +429,7 @@ The two files have to be edited to do so. - `kustomization`, apply kustomization to image ```cue file=tests/kube-gcp/deployment/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` @@ -432,6 +445,7 @@ The two files have to be edited to do so. - definition of a new `ecrCreds` value that contains ecr credentials for remote image push to ECR ```cue file=tests/kube-aws/deployment/config.cue title="todoapp/kube/config.cue" + ``` `kube/todoapp.cue`, on the other hand, faces these changes: @@ -443,6 +457,7 @@ The two files have to be edited to do so. - `kustomization`, apply kustomization to image ```cue file=tests/kube-aws/deployment/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` @@ -542,11 +557,13 @@ repetition. Let's define a re-usable `#Deployment` definition in `kube/deployment.cue`. ```cue file=tests/kube-kind/cue-manifest/deployment.cue title="todoapp/kube/deployment.cue" + ``` Indeed, let's also define a re-usable `#Service` definition in `kube/service.cue`. ```cue file=tests/kube-kind/cue-manifest/service.cue title="todoapp/kube/service.cue" + ``` ### Generate Kubernetes manifest @@ -557,6 +574,7 @@ without having boilerplate nor repetition. Create a new definition named `#AppManifest` that will generate the YAML in `kube/manifest.cue`. ```cue file=tests/kube-kind/cue-manifest/manifest.cue title="todoapp/kube/manifest.cue" + ``` ### Update manifest @@ -580,18 +598,21 @@ values={[ ```cue file=tests/kube-kind/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` ```cue file=tests/kube-gcp/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` ```cue file=tests/kube-aws/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue" + ``` diff --git a/docs/learn/1008-aws-cloudformation.md b/docs/learn/1008-aws-cloudformation.md index 27a14e53..b6106b7f 100644 --- a/docs/learn/1008-aws-cloudformation.md +++ b/docs/learn/1008-aws-cloudformation.md @@ -108,7 +108,13 @@ This defines: ##### 1. Create a new environment -Now that the Cue package is ready, let's create an environment to run it: +Let's create a project: + +```shell +dagger init +``` + +Let's create an environment to run it: ```shell dagger new 'cloudformation' -p ./cloudformation diff --git a/docs/learn/tests/getting-started/plans/local/local.cue b/docs/learn/tests/getting-started/plans/local/local.cue index d3e0609f..05d7c064 100644 --- a/docs/learn/tests/getting-started/plans/local/local.cue +++ b/docs/learn/tests/getting-started/plans/local/local.cue @@ -29,5 +29,5 @@ registry: docker.#Run & { // we defined in the previous file push: target: "localhost:5000/todoapp" -// output the application URL +// Application URL appURL: "http://localhost:8080/" & dagger.#Output From 2da9d073027f954efcf36bbf141da799574b7c80 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 5 Oct 2021 19:12:16 -0700 Subject: [PATCH 3/3] docs: use different port for getting started registry Signed-off-by: Sam Alba --- docs/learn/tests/getting-started/plans/local/local.cue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/learn/tests/getting-started/plans/local/local.cue b/docs/learn/tests/getting-started/plans/local/local.cue index 05d7c064..a9460987 100644 --- a/docs/learn/tests/getting-started/plans/local/local.cue +++ b/docs/learn/tests/getting-started/plans/local/local.cue @@ -20,14 +20,14 @@ run: docker.#Run & { registry: docker.#Run & { ref: "registry:2" name: "registry-local" - ports: ["5000:5000"] + ports: ["5042:5000"] socket: dockerSocket } // push to our local registry // this concrete value satisfies the string constraint // we defined in the previous file -push: target: "localhost:5000/todoapp" +push: target: "localhost:5042/todoapp" // Application URL appURL: "http://localhost:8080/" & dagger.#Output