2021-03-22 20:19:12 +01:00
# Dagger Examples
2021-04-01 01:50:27 +02:00
All example commands should be executed in the `examples/` directory
in an up-to-date checkout of the [dagger repository ](https://github.com/dagger/dagger ).
2021-04-14 20:57:58 +02:00
## Deploy a static page to S3
This example shows how to generate a simple HTML page and serve it from an S3 bucket.
Components:
- [Amazon S3 ](https://aws.amazon.com/s3/ ) for hosting
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
2021-04-14 20:57:58 +02:00
```sh
cd ./simple-s3
2021-05-26 17:50:03 +02:00
dagger init
2021-04-14 20:57:58 +02:00
```
2021-05-26 17:50:03 +02:00
2. Create a new environment
2021-04-14 20:57:58 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new simple-s3
cp *.cue ./.dagger/env/simple-s3/plan/
```
3. Configure your AWS credentials
```sh
dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY
dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY
2021-04-14 20:57:58 +02:00
```
2021-05-26 17:50:03 +02:00
4. Specify the source code location
2021-04-14 20:57:58 +02:00
```sh
2021-05-12 00:03:28 +02:00
dagger input dir source website
2021-04-14 20:57:58 +02:00
```
2021-05-26 17:50:03 +02:00
5. Deploy!
2021-04-14 20:57:58 +02:00
```sh
dagger up
```
2021-05-26 17:50:03 +02:00
6. Check the URL
2021-05-12 00:03:28 +02:00
```sh
curl -i $(dagger query url -f text)
```
2021-04-02 00:37:14 +02:00
## Deploy a simple React application
2021-04-01 01:50:27 +02:00
2021-04-02 00:37:14 +02:00
This example shows how to deploy an example React Application. [Read the deployment plan ](https://github.com/dagger/dagger/tree/main/examples/react )
Audience: Javascript developers looking to deploy their application.
2021-04-01 01:50:27 +02:00
2021-04-01 03:01:17 +02:00
Components:
- [Netlify ](https://netlify.com ) for application hosting
- [Yarn ](https://yarnpkg.com ) for building
- [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.
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
2021-04-01 01:50:27 +02:00
```sh
2021-04-01 03:01:17 +02:00
cd ./react
2021-05-26 17:50:03 +02:00
dagger init
2021-04-01 01:50:27 +02:00
```
2021-05-26 17:50:03 +02:00
2. Create a new environment
2021-04-01 01:50:27 +02:00
2021-04-01 03:01:17 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new react
cp *.cue ./.dagger/env/react/plan/
2021-04-01 03:01:17 +02:00
```
3. Configure the deployment with your Netlify access token.
2021-04-14 00:32:23 +02:00
You can create new tokens from the [Netlify dashboard ](https://app.netlify.com/user/applications/personal ).
2021-04-01 01:50:27 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger input secret www.account.token MY_TOKEN
2021-04-01 01:50:27 +02:00
```
2021-04-14 00:32:23 +02:00
_NOTE: there is a dedicated command for encrypted secret inputs, but it is
not yet implemented. Coming soon!_
2021-04-01 03:01:17 +02:00
4. Deploy!
2021-04-01 01:50:27 +02:00
```sh
2021-04-01 03:01:17 +02:00
dagger up
2021-04-01 01:50:27 +02:00
```
2021-04-14 00:32:23 +02:00
## Deploy a complete JAMstack app
This example shows how to deploy a complete app with a backend, a database and a frontend.
2021-04-14 02:21:03 +02:00
This app assumes the following infrastructure is available:
2021-04-14 00:32:23 +02:00
- AWS ECS Cluster
- AWS ALB with a TLS certificate
- AWS RDS Instance (MySQL or PostgreSQL)
- AWS ECR repository
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
```sh
cd ./jamstack
dagger init
```
2. Create a new environment
2021-04-14 00:32:23 +02:00
2021-04-27 21:11:33 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new jamstack
cp *.cue ./.dagger/env/jamstack/plan/
2021-04-27 21:11:33 +02:00
```
2021-04-14 00:32:23 +02:00
2021-05-26 17:50:03 +02:00
3. Edit the inputs
2021-04-14 00:32:23 +02:00
2021-04-27 21:11:33 +02:00
Edit the file `inputs.yaml` and review all values to match to your infrastructure.
Add the inputs to the deployment:
2021-04-14 00:32:23 +02:00
```sh
2021-04-27 21:11:33 +02:00
dagger input yaml "" -f ./inputs.yaml
2021-04-14 00:32:23 +02:00
```
2021-05-26 17:50:03 +02:00
4. Deploy!
2021-04-14 00:32:23 +02:00
```sh
dagger up
```
2021-04-27 21:11:33 +02:00
The example `inputs.yaml` from the `./examples/jamstack` directory takes the source code from a remote git repository, but you can remove this from the file and instead points to a local source code:
2021-04-14 00:32:23 +02:00
```sh
dagger input dir backend.source ./my/local/backend/code
```
And the same mechanism applies for every single key in this file.
2021-05-26 17:50:03 +02:00
5. Get the App URL
2021-04-14 00:32:23 +02:00
```sh
dagger query url
```
2021-04-01 03:01:17 +02:00
2021-04-02 00:37:14 +02:00
## Provision a Kubernetes cluster on AWS
2021-03-22 20:19:12 +01:00
2021-04-02 00:37:14 +02:00
This example shows how to provision a new Kubernetes cluster on AWS, and configure your `kubectl` client to use it. [Read the deployment plan ](https://github.com/dagger/dagger/tree/main/examples/kubernetes-aws )
2021-03-22 20:19:12 +01:00
2021-04-02 00:37:14 +02:00
Audience: infrastructure teams looking to provisioning kubernetes clusters as part of automated CICD pipelines.
Components:
- [Amazon EKS ](https://aws.amazon.com/eks ) for Kubernetes hosting
- [Amazon CloudFormation ](https://aws.amazon.com/cloudformation ) for infrastructure provisioning
- [Kubectl ](https://kubernetes.io/docs/tasks/tools/#kubectl ) as kubernetes client
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
2021-03-22 20:19:12 +01:00
```sh
2021-04-02 00:37:14 +02:00
cd ./kubernetes-aws
2021-05-26 17:50:03 +02:00
dagger init
2021-04-02 00:37:14 +02:00
```
2021-05-26 17:50:03 +02:00
2. Create a new environment
2021-04-02 00:37:14 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new kubernetes-aws
cp *.cue ./.dagger/env/kubernetes-aws/plan/
2021-04-02 00:37:14 +02:00
```
3. Configure the deployment with your AWS credentials
```sh
2021-05-26 17:50:03 +02:00
dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY
dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY
2021-04-02 00:37:14 +02:00
```
4. Deploy!
```sh
dagger up
```
5. Export the generated kubectl config
```sh
dagger query kubeconfig.kubeconfig | jq . > kubeconfig
2021-03-22 20:19:12 +01:00
```
2021-04-02 01:52:21 +02:00
## Add HTTP monitoring to your application
2021-03-22 20:19:12 +01:00
2021-04-02 01:52:21 +02:00
This example shows how to implement a robust HTTP(s) monitoring service on top of AWS. [Read the deployment plan ](https://github.com/dagger/dagger/tree/main/examples/monitoring ).
2021-03-22 20:19:12 +01:00
2021-04-02 01:52:21 +02:00
Audience: application team looking to improve the reliability of their application.
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
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
2021-04-02 01:52:21 +02:00
```sh
cd ./monitoring
2021-05-26 17:50:03 +02:00
dagger init
2021-04-02 01:52:21 +02:00
```
2021-05-26 17:50:03 +02:00
2. Create a new environment
2021-04-02 01:52:21 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new monitoring
cp *.cue ./.dagger/env/monitoring/plan/
2021-04-02 01:52:21 +02:00
```
2021-05-26 17:50:03 +02:00
2. Configure the deployment with your AWS credentials
2021-03-22 20:19:12 +01:00
```sh
2021-04-02 01:52:21 +02:00
dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY
dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY
2021-03-22 20:19:12 +01:00
```
2021-05-26 17:50:03 +02:00
3. Configure the monitoring parameters
2021-04-02 01:52:21 +02:00
```sh
dagger input text website https://MYWEBSITE.TLD
```
```sh
dagger input text email my_email@my_domain.tld
```
2021-05-26 17:50:03 +02:00
4. Deploy!
2021-04-02 01:52:21 +02:00
```sh
dagger up
```
## Deploy an application to your Kubernetes cluster
This example shows two different ways to deploy an application to an existing Kubernetes cluster: with and without a Helm chart. Read the deployment plan](https://github.com/dagger/dagger/tree/main/examples/kubernetes-app)
2021-03-22 20:19:12 +01:00
2021-04-02 01:52:21 +02:00
NOTE: this example requires an EKS cluster to allow authentication with your AWS credentials; but can easily be adapter to deploy to any Kubernetes cluster.
Components:
- [Amazon EKS ](https://aws.amazon.com/eks ) for Kubernetes hosting
- [Kubectl ](https://kubernetes.io/docs/tasks/tools/#kubectl ) as kubernetes client
- [Helm ](https://helm.sh ) to manage kubernetes configuration (optional)
2021-03-22 20:19:12 +01:00
How to run:
2021-05-26 17:50:03 +02:00
1. Initialize a new workspace
2021-04-02 01:52:21 +02:00
```sh
cd ./kubernetes-app
2021-05-26 17:50:03 +02:00
dagger init
2021-04-02 01:52:21 +02:00
```
2021-05-26 17:50:03 +02:00
2. Create a new environment
2021-04-02 01:52:21 +02:00
```sh
2021-05-26 17:50:03 +02:00
dagger new kubernetes-app
cp *.cue ./.dagger/env/kubernetes-app/plan/
2021-04-02 01:52:21 +02:00
```
3. Configure the deployment with your AWS credentials
2021-03-22 20:19:12 +01:00
```sh
2021-05-26 17:50:03 +02:00
dagger input secret awsConfig.accessKey MY_AWS_ACCESS_KEY
dagger input secret awsConfig.secretKey MY_AWS_SECRET_KEY
2021-04-02 01:52:21 +02:00
```
4. Configure the EKS cluster to deploy to
Note: if you have run the `kubernetes-aws` example, you may skip this step.
```sh
dagger input text cluster.clusterName MY_CLUSTER_NAME
```
5. Load the Helm chart
```sh
2021-06-09 12:01:27 +02:00
dagger input dir helmChart.chart ./testdata/mychart
2021-04-02 01:52:21 +02:00
```
6. Deploy!
```sh
dagger up
2021-03-22 20:19:12 +01:00
```
2021-06-09 12:01:27 +02:00
## Deploy an application to GCP Cloud Run
2021-06-10 11:45:52 +02:00
This example shows how to deploy an application to GCP Cloud Run. Read the deployment [plan ](https://github.com/dagger/dagger/tree/main/examples/cloudrun-app )
2021-06-09 12:01:27 +02:00
2021-06-10 11:45:52 +02:00
NOTE: this example requires the right GCP IAM permissions: `https://cloud.google.com/run/docs/reference/iam/roles#additional-configuration`
2021-06-09 12:01:27 +02:00
Components:
- [Cloud Run ](https://cloud.google.com/run )
How to run:
1. Initialize a new workspace
```sh
2021-06-10 11:45:52 +02:00
cd ./cloudrun-app
2021-06-09 12:01:27 +02:00
dagger init
```
2. Create a new environment
```sh
2021-06-10 11:45:52 +02:00
dagger new cloudrun-app
cp main.cue ./.dagger/env/cloudrun-app/plan/
2021-06-09 12:01:27 +02:00
```
3. Configure the Cloud Run service
```sh
dagger input text serviceName MY_APP_NAME
dagger input text image MY_GCR_IMAGE_NAME
dagger input text gcpConfig.project MY_GCP_PROJECT
2021-06-10 11:45:52 +02:00
dagger input text gcpConfig.region MY_GCP_REGION
2021-06-09 12:01:27 +02:00
dagger input secret gcpConfig.serviceKey -f MY_GCP_SERVICE_KEY_FILE
```
4. Deploy!
```sh
dagger up
```