Skip to content

Commit 32ceefc

Browse files
committed
Use hyperdisk balanced
And a couple edge case fixes
1 parent 85e8486 commit 32ceefc

8 files changed

Lines changed: 52 additions & 33 deletions

File tree

main.tf

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,20 @@ resource "google_project_iam_member" "log" {
7272

7373
resource "google_compute_disk" "boot" {
7474
# force re-create VM when cloud-init changes
75-
name = format("cloud-compose-boot-%s-%s", var.name, md5(data.cloudinit_config.ci.rendered))
75+
name = format("%s-boot-%s", var.name, md5(data.cloudinit_config.ci.rendered))
7676
project = var.project_id
77-
type = "pd-ssd"
77+
type = "hyperdisk-balanced"
7878
zone = var.zone
79-
size = 10
79+
size = 20
8080
image = "projects/cos-cloud/global/images/${var.os}"
8181
physical_block_size_bytes = 4096
8282
}
8383

8484
resource "google_compute_disk" "data" {
85-
name = format("%s-data-disk", var.name)
86-
project = var.project_id
87-
type = "pd-ssd"
88-
zone = var.zone
89-
# to resize, extend in console or gcloud CLI
90-
# then SSH into VM and run
91-
# sudo resize2fs /dev/sdb
85+
name = format("%s-data-disk", var.name)
86+
project = var.project_id
87+
type = "hyperdisk-balanced"
88+
zone = var.zone
9289
size = var.disk_size_gb
9390
image = "debian-13-trixie-v20251111"
9491
physical_block_size_bytes = 4096
@@ -100,7 +97,7 @@ resource "google_compute_instance" "cloud-compose" {
10097
machine_type = var.machine_type
10198
zone = var.zone
10299
allow_stopping_for_update = true
103-
tags = ["cloud-compose", format("cloud-compose-%s", var.name)]
100+
tags = ["cloud-compose", var.name]
104101
can_ip_forward = "false"
105102

106103
boot_disk {
@@ -148,7 +145,7 @@ resource "google_compute_instance" "cloud-compose" {
148145
}
149146

150147
service_account {
151-
email = google_service_account.cloud-compose.email
148+
email = google_service_account.cloud-compose.email
152149
scopes = [
153150
"https://www.googleapis.com/auth/logging.write",
154151
"https://www.googleapis.com/auth/monitoring.write",

rootfs/etc/systemd/system/internal-services.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Description=Internal Services (Ping, Metrics, Power Management)
33
BindsTo=docker.service
44
After=cloud-compose.service
5+
Requires=internal-services.timer
6+
After=internal-services.timer
57
StartLimitIntervalSec=120
68
StartLimitBurst=3
79

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Delay Internal Services until 10m after initial boot
3+
4+
[Timer]
5+
OnBootSec=10min
6+
RuntimeMaxSec=10min
7+
Unit=internal-services.service
8+
9+
[Install]
10+
WantedBy=timers.target

rootfs/home/cloud-compose/host-init.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,14 @@ done
4141
echo "GCP_PRIVATE_IP=$(jq -r '.instance.networkInterfaces[0].ip' tmp.attr)"
4242
} >> env.tmp
4343

44-
# shellcheck disable=SC1091
45-
. ./env.tmp
46-
47-
echo "SITE_DOCKER_REGISTRY=us-docker.pkg.dev/${GCP_PROJECT}/private" >> env.tmp
48-
4944
if ! diff <(md5sum env.tmp) <(md5sum env); then
5045
mv env.tmp env
51-
cp env /mnt/disks/data/compose/.env
52-
if [ -d /mnt/disks/data/compose ]; then
53-
cp env /mnt/disks/data/compose/.env
54-
fi
46+
cp env /mnt/disks/data/libops/.env
5547
fi
5648

49+
# shellcheck disable=SC1091
50+
. ./env
51+
5752
# generate the docker compose init/up/down commands
5853
# used by the systemd service
5954
SCRIPT_DIR="/mnt/disks/data"
@@ -68,6 +63,7 @@ for name in "${!SCRIPTS[@]}"; do
6863
6964
set -eou pipefail
7065
66+
echo "Running dokcer compose ${name}"
7167
${SCRIPTS[${name}]}
7268
EOT
7369
chmod +x "${SCRIPT_DIR}/${name}"

rootfs/home/cloud-compose/init-app.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ fi
1414
pushd "$DIR"
1515
git pull origin "$DOCKER_COMPOSE_BRANCH" || echo "Unable to git pull"
1616

17-
/usr/bin/docker-credential-gcr configure-docker --registries us-docker.pkg.dev
18-
1917
# run the docker compose init command if it exists
2018
/mnt/disks/data/init
2119

2220
bash /home/cloud-compose/rollout.sh
2321

24-
chgrp developers /mnt/disks/data/compose
25-
chmod g+s /mnt/disks/data/compose
26-
2722
popd

rootfs/home/cloud-compose/rollout.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ shopt -u nullglob
2626
if [ "$RESTART" -eq 1 ]; then
2727
SERVICE=$(grep -sl "WorkingDirectory=$DIR" /etc/systemd/system/*.service | xargs basename)
2828
if [ -n "$SERVICE" ]; then
29+
echo "Restarting $SERVICE"
2930
systemctl restart "$SERVICE"
3031
fi
3132
fi

templates/cloud-init.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
users:
44
- name: cloud-compose
55
shell: /bin/bash
6-
groups:
7-
- developers
86

97
bootcmd:
108
- fsck.ext4 -tvy $(readlink -f /dev/disk/by-id/google-data) || mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard $(readlink -f /dev/disk/by-id/google-data)
@@ -22,6 +20,5 @@ runcmd:
2220
- bash /home/cloud-compose/host-conf.sh
2321
- bash /home/cloud-compose/host-init.sh
2422
- bash /home/cloud-compose/init-app.sh
25-
- systemctl start cloud-compose.service
26-
- systemctl start internal-services.service
23+
- systemctl start internal-services.timer
2724
- systemctl start cron.timer

variables.tf

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,34 @@ variable "name" {
2727

2828
variable "machine_type" {
2929
type = string
30-
default = "e2-medium"
31-
description = "VM machine type"
30+
default = "n4-standard-2"
31+
description = "VM machine type (General-purpose series that support Hyperdisk Balanced"
32+
33+
validation {
34+
condition = contains([
35+
"n4-standard-2",
36+
"n4-standard-4",
37+
"n4-standard-8",
38+
"n4-standard-16",
39+
"n4-standard-32",
40+
"n4-standard-48",
41+
"n4-standard-64",
42+
"n4-standard-80",
43+
"c4-standard-2",
44+
"c4-standard-4",
45+
"c4-standard-8",
46+
"c4-standard-16",
47+
"c4-standard-32",
48+
"c4-standard-48",
49+
"c4-standard-96",
50+
], var.machine_type)
51+
error_message = "The 'machine_type' must be from a General-Purpose family that supports Hyperdisk Balanced (C4, or N4 series)"
52+
}
3253
}
3354

3455
variable "disk_size_gb" {
3556
type = number
36-
default = 25
57+
default = 50
3758
description = "Data disk size in GB"
3859
}
3960

0 commit comments

Comments
 (0)