Skip to content

Commit f048f8d

Browse files
committed
Added secondary volume dedicated to docker storage
Added a secondary storage volume dedicated to Docker.
1 parent 0c274ad commit f048f8d

6 files changed

Lines changed: 119 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ override.tf.json
2727

2828
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2929
# example: *tfplan*
30+
__backend__.tf
31+
.nullstone/active-workspace.yml

.terraform.lock.hcl

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.2.3 (Apr 28, 2025)
2+
* Added a secondary storage volume dedicated to Docker. (`var.docker_volume_size`)
3+
14
# 0.2.2 (Mar 19, 2025)
25
* Sanitize invalid capacity provider name (i.e. starts with `aws`, `ecs`, or `fargate`).
36

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lock-providers:
2+
terraform providers lock -platform=linux_amd64 -platform=linux_arm64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=windows_amd64

autoscaling.tf

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ resource "aws_autoscaling_group" "this" {
3131
locals {
3232
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html
3333
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html
34-
user_data = join("\n", [
35-
"#!/bin/bash",
36-
"echo ECS_CLUSTER=${aws_ecs_cluster.this.name} >> /etc/ecs/ecs.config",
37-
])
34+
user_data = <<EOF
35+
#!/bin/bash
36+
37+
# Format and mount extra disk for Docker usage
38+
mkfs -t xfs /dev/xvdcz
39+
mkdir -p /var/lib/docker
40+
echo '/dev/xvdcz /var/lib/docker xfs defaults,noatime 0 0' >> /etc/fstab
41+
mount -a
42+
43+
# Configure ECS agent
44+
echo ECS_CLUSTER=${aws_ecs_cluster.this.name} >> /etc/ecs/ecs.config
45+
EOF
3846
}
3947

4048
resource "aws_launch_template" "this" {
@@ -43,6 +51,12 @@ resource "aws_launch_template" "this" {
4351
instance_type = var.node_instance_type
4452
vpc_security_group_ids = [aws_security_group.this.id]
4553
user_data = base64encode(local.user_data)
54+
tags = local.tags
55+
56+
tag_specifications {
57+
resource_type = "instance"
58+
tags = merge(local.tags, { "Name" = "${local.block_name}/node" })
59+
}
4660

4761
iam_instance_profile {
4862
name = aws_iam_instance_profile.this.name
@@ -57,8 +71,15 @@ resource "aws_launch_template" "this" {
5771
}
5872
}
5973

60-
// TODO: Mount volume for /dev/xvdcz (docker use) -> this can be used to tune docker image storage
61-
// See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html
74+
// Additional storage volume dedicated to Docker
75+
block_device_mappings {
76+
device_name = "/dev/xvdcz"
77+
78+
ebs {
79+
volume_type = "gp3"
80+
volume_size = var.docker_volume_size
81+
}
82+
}
6283

6384
lifecycle {
6485
create_before_destroy = true

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,12 @@ variable "node_volume_size" {
8989
The number of gigabytes to allocates for the root volume on each node.
9090
EOF
9191
}
92+
93+
variable "docker_volume_size" {
94+
type = number
95+
default = 100
96+
description = <<EOF
97+
The size of the storage volume used for Docker in gigabytes.
98+
This storage is used by Docker for building images and docker volumes.
99+
EOF
100+
}

0 commit comments

Comments
 (0)