From a9f76268a2b3ef783b75ed8d83522ded8ea3d2b5 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 13 Apr 2021 15:32:23 -0700 Subject: [PATCH] examples/jamstack: added README and example app config Signed-off-by: Sam Alba --- examples/README.md | 57 +++++++++++++++++++++++++---- examples/jamstack/app_config.cue | 62 ++++++++++++++++++++++++++++++++ examples/jamstack/database.cue | 2 +- 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 examples/jamstack/app_config.cue diff --git a/examples/README.md b/examples/README.md index a3ef5b88..42eb3c7c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -29,14 +29,14 @@ dagger new ``` 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). + 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 ``` -*NOTE: there is a dedicated command for encrypted secret inputs, but it is -not yet implemented. Coming soon!* +_NOTE: there is a dedicated command for encrypted secret inputs, but it is +not yet implemented. Coming soon!_ 4. Deploy! @@ -44,6 +44,53 @@ not yet implemented. Coming soon!* dagger up ``` +## Deploy a complete JAMstack app + +This example shows how to deploy a complete app with a backend, a database and a frontend. + +This app assumes the followinf infrastructure is available: + +- AWS ECS Cluster +- AWS ALB with a TLS certificate +- AWS RDS Instance (MySQL or PostgreSQL) +- AWS ECR repository + +1. Prepare the app configuration + +Edit the file `./examples/jamstack/app_config.cue` and review all values to match to your own needs. + +2. Login your local docker daemon to ECR + +_This step is temporary and will be removed soon (gh issue #301)._ + +```sh +AWS_REGION="" +AWS_ID="" +aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "${AWS_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" +``` + +3. Deploy! + +```sh +cd ./examples/jamstack +dagger new +dagger up +``` + +The example `app_config.cue` 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: + +```sh +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 + +```sh +dagger query url +``` ## Provision a Kubernetes cluster on AWS @@ -79,7 +126,6 @@ dagger input text awsConfig.accessKey MY_AWS_ACCESS_KEY dagger input text awsConfig.secretKey MY_AWS_SECRET_KEY ``` - 4. Deploy! ```sh @@ -103,7 +149,6 @@ 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 @@ -142,7 +187,6 @@ dagger input text email my_email@my_domain.tld 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) @@ -157,7 +201,6 @@ Components: How to run: - 1. Change the current directory to the example deployment plan ```sh diff --git a/examples/jamstack/app_config.cue b/examples/jamstack/app_config.cue new file mode 100644 index 00000000..74fd4e88 --- /dev/null +++ b/examples/jamstack/app_config.cue @@ -0,0 +1,62 @@ +package main + +import ( + "dagger.io/git" +) + +name: "my-app" + +// DISCLAIMER: all values below are fake and are provided as examples + +infra: { + awsConfig: { + accessKey: "" + secretKey: "" + region: "us-east-1" + } + vpcId: "vpc-020ctgv0bcde4242" + ecrRepository: "8563296674124.dkr.ecr.us-east-1.amazonaws.com/apps" + ecsClusterName: "bl-ecs-acme-764-ECSCluster-lRIVVg09G4HX" + elbListenerArn: "arn:aws:elasticloadbalancing:us-east-1:8563296674124:listener/app/bl-ec-ECSAL-OSYI03K07BCO/3c2d3e78347bde5b/d02ac88cc007e24e" + rdsAdminSecretArn: "arn:aws:secretsmanager:us-east-1:8563296674124:secret:AdminPassword-NQbBi7oU4CYS9-IGgS3B" + rdsInstanceArn: "arn:aws:rds:us-east-1:8563296674124:cluster:bl-rds-acme-764-rdscluster-8eg3xbfjggkfdg" + netlifyAccount: { + token: "" + } +} + +database: { + dbType: "mysql" +} + +backend: { + source: git.#Repository & { + remote: "https://github.com/blocklayerhq/acme-clothing.git" + ref: "HEAD" + subdir: "./crate/code/api" + } + + // DNS needs to be already configured to the ALB load-balancer + // and a valid certificate needs to be configured for that listener + hostname: "\(name).acme-764-api.microstaging.io" + + container: { + healthCheckPath: "/health-check" + healthCheckTimeout: 40 + } +} + +frontend: { + source: git.#Repository & { + remote: "https://github.com/blocklayerhq/acme-clothing.git" + ref: "HEAD" + subdir: "./crate/code/web" + } + + writeEnvFile: ".env" + + yarn: { + buildDir: "public" + script: "build:client" + } +} diff --git a/examples/jamstack/database.cue b/examples/jamstack/database.cue index 93edbe43..a2ed656e 100644 --- a/examples/jamstack/database.cue +++ b/examples/jamstack/database.cue @@ -7,7 +7,7 @@ import ( database: { let slug = name - dbType: "mysql" + dbType: "mysql" | "postgresql" db: rds.#CreateDB & { config: infra.awsConfig