Merge pull request #1047 from samalba/docs-run-local-registry

docs: added abililty to run a local registry for todoapp example
This commit is contained in:
Andrea Luzzardi 2021-10-05 19:22:58 -07:00 committed by GitHub
commit 92a04fe001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 16 deletions

View File

@ -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.
@ -169,6 +170,7 @@ push.ref "localhost:5000/todoapp:latest@sha256:<hash>" Image ref
push.digest "sha256:<hash>" Image digest
run.ref "localhost:5000/todoapp:latest@sha256:<hash>" Image reference (e.g: nginx:alpine)
run.run.env.IMAGE_REF "localhost:5000/todoapp:latest@sha256:<hash>" -
appURL "http://localhost:8080/" Application URL
```
Congratulations! You&rsquo;ve deployed your first Dagger plan! You can now [view the todo app](http://localhost:8080) in your browser!

View File

@ -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.

View File

@ -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

View File

@ -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"
```
</TabItem>
@ -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"
```
</TabItem>
@ -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"
```
</TabItem>
@ -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"
```
</TabItem>
@ -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"
```
</TabItem>
@ -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"
```
</TabItem>
@ -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={[
<TabItem value="kind">
```cue file=tests/kube-kind/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue"
```
</TabItem>
<TabItem value="gke">
```cue file=tests/kube-gcp/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue"
```
</TabItem>
<TabItem value="eks">
```cue file=tests/kube-aws/cue-manifest/todoapp.cue title="todoapp/kube/todoapp.cue"
```
</TabItem>

View File

@ -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

View File

@ -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

View File

@ -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: ["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

View File

@ -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
}