2021-04-10 01:00:38 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"dagger.io/dagger"
|
|
|
|
"dagger.io/aws/ecs"
|
2021-04-27 21:11:33 +02:00
|
|
|
"dagger.io/git"
|
2021-04-10 01:00:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Backend configuration
|
|
|
|
backend: {
|
|
|
|
// Source code to build this container
|
2021-06-01 16:00:01 +02:00
|
|
|
source: git.#Repository | dagger.#Artifact @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
|
|
|
|
// Container environment variables
|
2021-06-01 16:00:01 +02:00
|
|
|
environment: {
|
|
|
|
[string]: string @dagger(input)
|
|
|
|
}
|
2021-04-10 01:00:38 +02:00
|
|
|
|
|
|
|
// Public hostname (need to match the master domain configures on the loadbalancer)
|
2021-06-01 16:00:01 +02:00
|
|
|
hostname: string @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
|
|
|
|
// Container configuration
|
|
|
|
container: {
|
|
|
|
// Desired number of running containers
|
2021-06-01 16:00:01 +02:00
|
|
|
desiredCount: *1 | int @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Time to wait for the HTTP timeout to complete
|
2021-06-01 16:00:01 +02:00
|
|
|
healthCheckTimeout: *10 | int @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// HTTP Path to perform the healthcheck request (HTTP Get)
|
2021-06-01 16:00:01 +02:00
|
|
|
healthCheckPath: *"/" | string @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Number of times the health check needs to fail before recycling the container
|
2021-06-01 16:00:01 +02:00
|
|
|
healthCheckUnhealthyThreshold: *2 | int @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Port used by the process inside the container
|
2021-06-01 16:00:01 +02:00
|
|
|
port: *80 | int @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Memory to allocate
|
2021-06-01 16:00:01 +02:00
|
|
|
memory: *1024 | int @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Override the default container command
|
2021-06-01 16:00:01 +02:00
|
|
|
command: [...string] @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// Custom dockerfile path
|
2021-06-01 16:00:01 +02:00
|
|
|
dockerfilePath: *"" | string @dagger(input)
|
2021-04-10 01:00:38 +02:00
|
|
|
// docker build args
|
2021-06-01 16:00:01 +02:00
|
|
|
dockerBuildArgs: {
|
|
|
|
[string]: string @dagger(input)
|
|
|
|
}
|
2021-04-10 01:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init container runs only once when the main container starts
|
|
|
|
initContainer: {
|
2021-06-01 16:00:01 +02:00
|
|
|
command: [...string] @dagger(input)
|
|
|
|
environment: {
|
|
|
|
[string]: string @dagger(input)
|
|
|
|
}
|
2021-04-10 01:00:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backend deployment logic
|
|
|
|
backend: {
|
|
|
|
let slug = name
|
|
|
|
|
|
|
|
// Docker image built from source, pushed to ECR
|
|
|
|
image: #ECRImage & {
|
2021-04-10 02:41:36 +02:00
|
|
|
source: backend.source
|
2021-04-10 01:00:38 +02:00
|
|
|
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
|
|
|
|
}
|
2021-04-10 02:41:36 +02:00
|
|
|
hostname: backend.hostname
|
2021-04-10 01:00:38 +02:00
|
|
|
healthCheck: {
|
|
|
|
timeout: backend.container.healthCheckTimeout
|
|
|
|
path: backend.container.healthCheckPath
|
|
|
|
unhealthyThresholdCount: backend.container.healthCheckUnhealthyThreshold
|
|
|
|
}
|
|
|
|
desiredCount: backend.container.desiredCount
|
|
|
|
container: {
|
|
|
|
command: backend.container.command
|
2021-04-10 02:41:36 +02:00
|
|
|
environment: backend.environment
|
2021-04-10 01:00:38 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|