examples/jamstack: added README and example app config

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-13 15:32:23 -07:00
parent 41f78d948e
commit a9f76268a2
3 changed files with 113 additions and 8 deletions

View File

@ -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="<REPLACE_WITH_AWS_REGION>"
AWS_ID="<REPLACE_WITH_AWS_ACCOUNT_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

View File

@ -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: "<REPLACE WITH AWS ACCESS KEY>"
secretKey: "<REPLACE WITH AWS SECRET KEY>"
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: "<REPLACE WITH NETLIFY 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"
}
}

View File

@ -7,7 +7,7 @@ import (
database: {
let slug = name
dbType: "mysql"
dbType: "mysql" | "postgresql"
db: rds.#CreateDB & {
config: infra.awsConfig