This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/examples/jamstack/backend.cue

106 lines
2.9 KiB
CUE
Raw Normal View History

package main
import (
"dagger.io/dagger"
"dagger.io/aws/ecs"
"dagger.io/git"
)
// Backend configuration
backend: {
// Source code to build this container
source: git.#Repository | dagger.#Artifact
// Container environment variables
environment: [string]: string
// Public hostname (need to match the master domain configures on the loadbalancer)
hostname: string
// Container configuration
container: {
// Desired number of running containers
desiredCount: *1 | int
// Time to wait for the HTTP timeout to complete
healthCheckTimeout: *10 | int
// HTTP Path to perform the healthcheck request (HTTP Get)
healthCheckPath: *"/" | string
// Number of times the health check needs to fail before recycling the container
healthCheckUnhealthyThreshold: *2 | int
// Port used by the process inside the container
port: *80 | int
// Memory to allocate
memory: *1024 | int
// Override the default container command
command: [...string]
// Custom dockerfile path
dockerfilePath: *"" | string
// docker build args
dockerBuildArgs: [string]: string
}
// Init container runs only once when the main container starts
initContainer: {
command: [...string]
environment: [string]: string
}
}
// Backend deployment logic
backend: {
let slug = name
// Docker image built from source, pushed to ECR
image: #ECRImage & {
source: backend.source
repository: infra.ecrRepository
tag: slug
awsConfig: infra.awsConfig
if backend.container.dockerfilePath != "" {
dockerfilePath: backend.container.dockerfilePath
}
buildArgs: backend.container.dockerBuildArgs
}
// Creates an ECS Task + Service + deploy via Cloudformation
app: #ECSApp & {
awsConfig: infra.awsConfig
"slug": slug
clusterName: infra.ecsClusterName
vpcId: infra.vpcId
elbListenerArn: infra.elbListenerArn
if infra.ecsTaskRoleArn != _|_ {
taskRoleArn: infra.ecsTaskRoleArn
}
hostname: backend.hostname
healthCheck: {
timeout: backend.container.healthCheckTimeout
path: backend.container.healthCheckPath
unhealthyThresholdCount: backend.container.healthCheckUnhealthyThreshold
}
desiredCount: backend.container.desiredCount
container: {
command: backend.container.command
environment: backend.environment
port: backend.container.port
memory: backend.container.memory
"image": image.ref
}
}
// Optional container to run one-time during the deploy (eg. db migration)
if len(backend.initContainer.command) > 0 {
initContainer: ecs.#RunTask & {
config: infra.awsConfig
containerName: slug
cluster: infra.ecsClusterName
if infra.ecsTaskRoleArn != _|_ {
roleArn: infra.ecsTaskRoleArn
}
containerEnvironment: backend.initContainer.environment
containerCommand: backend.initContainer.command
taskArn: app.taskArn
}
}
}