From ca4da5e472244c60f35377c25152c8ee7ccceefb Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 1 Apr 2021 23:52:21 +0000 Subject: [PATCH] Docs: update and polish kubernetes-app and monitoring examples Signed-off-by: Solomon Hykes --- examples/README.md | 118 +++++++++++++++--- .../{kubernetes => kubernetes-app}/main.cue | 0 .../testdata/mychart/.helmignore | 0 .../testdata/mychart/Chart.yaml | 0 .../testdata/mychart/templates/NOTES.txt | 0 .../testdata/mychart/templates/_helpers.tpl | 0 .../mychart/templates/deployment.yaml | 0 .../testdata/mychart/templates/ingress.yaml | 0 .../testdata/mychart/templates/service.yaml | 0 .../mychart/templates/serviceaccount.yaml | 0 .../templates/tests/test-connection.yaml | 0 .../testdata/mychart/values.yaml | 0 .../http_monitor.cue | 0 .../{aws-monitoring => monitoring}/main.cue | 17 ++- 14 files changed, 110 insertions(+), 25 deletions(-) rename examples/{kubernetes => kubernetes-app}/main.cue (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/.helmignore (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/Chart.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/NOTES.txt (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/_helpers.tpl (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/deployment.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/ingress.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/service.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/serviceaccount.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/templates/tests/test-connection.yaml (100%) rename examples/{kubernetes => kubernetes-app}/testdata/mychart/values.yaml (100%) rename examples/{aws-monitoring => monitoring}/http_monitor.cue (100%) rename examples/{aws-monitoring => monitoring}/main.cue (50%) diff --git a/examples/README.md b/examples/README.md index 01fb5c00..a3ef5b88 100644 --- a/examples/README.md +++ b/examples/README.md @@ -92,30 +92,110 @@ dagger up dagger query kubeconfig.kubeconfig | jq . > kubeconfig ``` -## aws-monitoring: HTTP Monitoring on AWS +## Add HTTP monitoring to your application -This example implements a full HTTP(s) Monitoring solution on AWS using -Cloudformation and Cloudwatch Synthetics. +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). + +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 + + +1. Change the current directory to the example deployment plan + +```sh +cd ./monitoring +``` + +2. Create a new deployment from the plan + +```sh +dagger new +``` + +3. Configure the deployment with your AWS credentials + +```sh +dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY +``` + +```sh +dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +``` + +4. Configure the monitoring parameters + +```sh +dagger input text website https://MYWEBSITE.TLD +``` + +```sh +dagger input text email my_email@my_domain.tld +``` + +5. Deploy! + +```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) + +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) How to run: -```sh -dagger compute ./aws-monitoring \ - --input-string awsConfig.accessKey="MY_AWS_ACCESS_KEY" \ - --input-string awsConfig.secretKey="MY_AWS_SECRET_KEY" \ -``` -## kubernetes: Deploy to an existing Kubernetes cluster - -This example shows two different ways for deploying to an existing Kubernetes -(EKS) cluster: a simple deployment spec (written in Cue), and a local helm -chart. - -How to run: +1. Change the current directory to the example deployment plan ```sh -dagger compute ./kubernetes \ - --input-string awsConfig.accessKey="MY_AWS_ACCESS_KEY" \ - --input-string awsConfig.secretKey="MY_AWS_SECRET_KEY" \ - --input-dir helmChart.chart=./kubernetes/testdata/mychart +cd ./kubernetes-app +``` + +2. Create a new deployment from the plan + +```sh +dagger new +``` + +3. Configure the deployment with your AWS credentials + +```sh +dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY +``` + +```sh +dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY +``` + +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 +dagger input dir helmChart.chart=./kubernetes-app/testdata/mychart +``` + +6. Deploy! + +```sh +dagger up ``` diff --git a/examples/kubernetes/main.cue b/examples/kubernetes-app/main.cue similarity index 100% rename from examples/kubernetes/main.cue rename to examples/kubernetes-app/main.cue diff --git a/examples/kubernetes/testdata/mychart/.helmignore b/examples/kubernetes-app/testdata/mychart/.helmignore similarity index 100% rename from examples/kubernetes/testdata/mychart/.helmignore rename to examples/kubernetes-app/testdata/mychart/.helmignore diff --git a/examples/kubernetes/testdata/mychart/Chart.yaml b/examples/kubernetes-app/testdata/mychart/Chart.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/Chart.yaml rename to examples/kubernetes-app/testdata/mychart/Chart.yaml diff --git a/examples/kubernetes/testdata/mychart/templates/NOTES.txt b/examples/kubernetes-app/testdata/mychart/templates/NOTES.txt similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/NOTES.txt rename to examples/kubernetes-app/testdata/mychart/templates/NOTES.txt diff --git a/examples/kubernetes/testdata/mychart/templates/_helpers.tpl b/examples/kubernetes-app/testdata/mychart/templates/_helpers.tpl similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/_helpers.tpl rename to examples/kubernetes-app/testdata/mychart/templates/_helpers.tpl diff --git a/examples/kubernetes/testdata/mychart/templates/deployment.yaml b/examples/kubernetes-app/testdata/mychart/templates/deployment.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/deployment.yaml rename to examples/kubernetes-app/testdata/mychart/templates/deployment.yaml diff --git a/examples/kubernetes/testdata/mychart/templates/ingress.yaml b/examples/kubernetes-app/testdata/mychart/templates/ingress.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/ingress.yaml rename to examples/kubernetes-app/testdata/mychart/templates/ingress.yaml diff --git a/examples/kubernetes/testdata/mychart/templates/service.yaml b/examples/kubernetes-app/testdata/mychart/templates/service.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/service.yaml rename to examples/kubernetes-app/testdata/mychart/templates/service.yaml diff --git a/examples/kubernetes/testdata/mychart/templates/serviceaccount.yaml b/examples/kubernetes-app/testdata/mychart/templates/serviceaccount.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/serviceaccount.yaml rename to examples/kubernetes-app/testdata/mychart/templates/serviceaccount.yaml diff --git a/examples/kubernetes/testdata/mychart/templates/tests/test-connection.yaml b/examples/kubernetes-app/testdata/mychart/templates/tests/test-connection.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/templates/tests/test-connection.yaml rename to examples/kubernetes-app/testdata/mychart/templates/tests/test-connection.yaml diff --git a/examples/kubernetes/testdata/mychart/values.yaml b/examples/kubernetes-app/testdata/mychart/values.yaml similarity index 100% rename from examples/kubernetes/testdata/mychart/values.yaml rename to examples/kubernetes-app/testdata/mychart/values.yaml diff --git a/examples/aws-monitoring/http_monitor.cue b/examples/monitoring/http_monitor.cue similarity index 100% rename from examples/aws-monitoring/http_monitor.cue rename to examples/monitoring/http_monitor.cue diff --git a/examples/aws-monitoring/main.cue b/examples/monitoring/main.cue similarity index 50% rename from examples/aws-monitoring/main.cue rename to examples/monitoring/main.cue index 57819776..1021cdbf 100644 --- a/examples/aws-monitoring/main.cue +++ b/examples/monitoring/main.cue @@ -4,24 +4,29 @@ import ( "dagger.io/aws" ) -// Fill using: -// --input-string awsConfig.accessKey=XXX -// --input-string awsConfig.secretKey=XXX +// AWS account: credentials and region awsConfig: aws.#Config & { region: *"us-east-1" | string } +// URL of the website to monitor +website: string | *"https://www.google.com" + +// Email address to notify of monitoring alerts +email: string + +// The monitoring service running on AWS Cloudwatch monitor: #HTTPMonitor & { notifications: [ #Notification & { - endpoint: "sam+test@blocklayerhq.com" + endpoint: email protocol: "email" }, ] canaries: [ #Canary & { - name: "website-test" - url: "https://www.google.com/" + name: "default" + url: website }, ] cfnStackName: "my-monitor"