Skip to content

Commit 0e5cfd2

Browse files
committed
Code cleanup and move prune into general cron service
1 parent 1498dc9 commit 0e5cfd2

17 files changed

Lines changed: 109 additions & 96 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ lint:
55
@find . -type f -name "*.sh" -exec shellcheck {} +
66

77
docs:
8-
terraform-docs markdown table --output-file README.md .
8+
terraform-docs markdown table --sort-by required --output-file README.md .
99

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Deploy a docker compose project to a Google Cloud Compute Instance.
44

5-
65
<!-- BEGIN_TF_DOCS -->
76
## Requirements
87

@@ -48,18 +47,20 @@ Deploy a docker compose project to a Google Cloud Compute Instance.
4847

4948
| Name | Description | Type | Default | Required |
5049
|------|-------------|------|---------|:--------:|
50+
| <a name="input_docker_compose_repo"></a> [docker\_compose\_repo](#input\_docker\_compose\_repo) | git repo to checkout that contains a docker compose project | `string` | n/a | yes |
51+
| <a name="input_name"></a> [name](#input\_name) | The site name (will be the name of the GCP instance) | `string` | n/a | yes |
52+
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The GCP project ID | `string` | n/a | yes |
53+
| <a name="input_project_number"></a> [project\_number](#input\_project\_number) | The GCP project number | `string` | n/a | yes |
5154
| <a name="input_allowed_ips"></a> [allowed\_ips](#input\_allowed\_ips) | CIDR IP Addresses allowed to turn on this site's GCP instance | `list(string)` | `[]` | no |
55+
| <a name="input_allowed_ssh_ipv4"></a> [allowed\_ssh\_ipv4](#input\_allowed\_ssh\_ipv4) | CIDR IPv4 Addresses allowed to to SSH into this site's GCP instance | `list(string)` | `[]` | no |
56+
| <a name="input_allowed_ssh_ipv6"></a> [allowed\_ssh\_ipv6](#input\_allowed\_ssh\_ipv6) | CIDR IPv6 Addresses allowed to SSH into this site's GCP instance | `list(string)` | `[]` | no |
5257
| <a name="input_disk_size_gb"></a> [disk\_size\_gb](#input\_disk\_size\_gb) | Data disk size in GB | `number` | `25` | no |
5358
| <a name="input_docker_compose_branch"></a> [docker\_compose\_branch](#input\_docker\_compose\_branch) | git branch to checkout for var.docker\_compose\_repo | `string` | `"main"` | no |
5459
| <a name="input_docker_compose_down"></a> [docker\_compose\_down](#input\_docker\_compose\_down) | Command to stop the docker compose project | `string` | `"docker compose down"` | no |
5560
| <a name="input_docker_compose_init"></a> [docker\_compose\_init](#input\_docker\_compose\_init) | After cloning the docker compose git repo, any initialization that needs to happen before the docker compose project can start | `string` | `""` | no |
56-
| <a name="input_docker_compose_repo"></a> [docker\_compose\_repo](#input\_docker\_compose\_repo) | git repo to checkout that contains a docker compose project | `string` | n/a | yes |
5761
| <a name="input_docker_compose_up"></a> [docker\_compose\_up](#input\_docker\_compose\_up) | Command to start the docker compose project | `string` | `"docker compose up --remove-orphans"` | no |
5862
| <a name="input_machine_type"></a> [machine\_type](#input\_machine\_type) | VM machine type | `string` | `"e2-medium"` | no |
59-
| <a name="input_name"></a> [name](#input\_name) | The site name | `string` | n/a | yes |
60-
| <a name="input_os"></a> [os](#input\_os) | The host OS to install on the GCP instance | `string` | `"cos-117-18613-439-28"` | no |
61-
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | libops project ID (logical identifier, not GCP project ID) | `string` | n/a | yes |
62-
| <a name="input_project_number"></a> [project\_number](#input\_project\_number) | The GCP project to use | `string` | n/a | yes |
63+
| <a name="input_os"></a> [os](#input\_os) | The host OS to install on the GCP instance | `string` | `"cos-125-19216-104-25"` | no |
6364
| <a name="input_region"></a> [region](#input\_region) | GCP region for resources | `string` | `"us-central1"` | no |
6465
| <a name="input_zone"></a> [zone](#input\_zone) | GCP zone for resources | `string` | `"us-central1-f"` | no |
6566

main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ terraform {
99
}
1010
}
1111

12-
provider "google" {}
12+
provider "google" {
13+
project = var.project_id
14+
region = var.region
15+
}
1316

1417
locals {
1518
rootFs = "${path.module}/rootfs"
@@ -127,7 +130,6 @@ resource "google_compute_instance" "cloud-compose" {
127130
GCP_INSTANCE_NAME = var.name
128131
GCP_REGION = var.region
129132
GCP_ZONE = var.zone
130-
LIBOPS_SITE = var.name
131133
DOCKER_COMPOSE_REPO = var.docker_compose_repo
132134
DOCKER_COMPOSE_BRANCH = var.docker_compose_branch
133135
DOCKER_COMPOSE_INIT_CMD = var.docker_compose_init
@@ -175,7 +177,6 @@ resource "google_project_iam_member" "gce-suspend" {
175177
member = "serviceAccount:${google_service_account.cloud-compose.email}"
176178
}
177179

178-
179180
# =============================================================================
180181
# CLOUD RUN INGRESS
181182
# =============================================================================
@@ -205,15 +206,15 @@ EOT
205206
name = var.name
206207
usePrivateIp = "true"
207208
}
208-
allowed_ips = [
209+
allowed_ips = tolist([
209210
"127.0.0.1/32",
210211
"10.0.0.0/8",
211212
"172.16.0.0/12",
212213
"192.168.0.0/16",
213-
]
214+
])
214215

215216
dynamic_properties = {
216-
allowedIps = merge(local.allowed_ips, var.allowed_ips)
217+
allowedIps = concat(local.allowed_ips, var.allowed_ips)
217218
machineMetadata = local.machine
218219
}
219220

rootfs/etc/libops/docker-compose.internal.yml renamed to rootfs/etc/libops/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ networks:
22
internal:
33
services:
44
libops-lightsout:
5-
image: ghcr.io/libops/lightsout:main@sha256:66b761007d196e05e7039eaa16da7a55388b8851065b256b020d5dce0df4ca3c
5+
image: ghcr.io/libops/lightsout:main@sha256:b61680d4c2ad03f9cfe1f47341eec128df8782a453bcfd708068a6d5c8877a02
66
ports:
77
- "8808:8808"
88
networks:
@@ -36,7 +36,7 @@ services:
3636
- /mnt/disks/data/docker/:/var/lib/docker:ro
3737
- /dev/disk/:/dev/disk:ro
3838
libops-cap:
39-
image: ghcr.io/libops/cap:main@sha256:d94b9524c2c9e75915a47fbcbce2dfc132816002cdb1fcf4c21b136c7dc3ddbb
39+
image: ghcr.io/libops/cap:main@sha256:e81950f30fd31dcbbe5ce024b87335aa6be4e24553df2744769267715e404364
4040
networks:
4141
- internal
4242
restart: unless-stopped

rootfs/etc/systemd/system/cloud-compose.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ StartLimitIntervalSec=120
66
StartLimitBurst=3
77

88
[Service]
9+
Environment="HOME=/home/cloud-compose"
910
WorkingDirectory=/mnt/disks/data/compose
10-
EnvironmentFile=/home/cloud-compose/env
1111
ExecStart=/mnt/disks/data/up
1212
ExecStop=/mnt/disks/data/down
1313
Restart=on-failure
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=cron
3+
After=internal-services.service
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/bin/bash /home/cloud-compose/cron.sh
8+
User=root
9+
Group=root
10+
SuccessExitStatus=0
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[Unit]
2-
Description=prune
2+
Description=cron
33

44
[Timer]
55
OnBootSec=10m
6-
OnUnitActiveSec=1h
6+
OnUnitInactiveSec=24h
7+
WakeSystem=true
78

89
[Install]
910
WantedBy=timers.target

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
[Unit]
2-
Description=Internal Services (Ping, SSH, Power Management)
2+
Description=Internal Services (Ping, Metrics, Power Management)
33
BindsTo=docker.service
44
After=cloud-compose.service
55
StartLimitIntervalSec=120
66
StartLimitBurst=3
77

88
[Service]
9-
EnvironmentFile=/home/cloud-compose/env
9+
Environment="HOME=/home/cloud-compose"
1010
WorkingDirectory=/etc/libops
11-
ExecStartPre=/usr/bin/docker compose -f docker-compose.internal.yml pull
12-
ExecStart=/usr/bin/docker compose -f docker-compose.internal.yml up
13-
ExecStop=/usr/bin/docker compose -f docker-compose.internal.yml down
11+
ExecStart=/usr/bin/docker compose up
12+
ExecStop=/usr/bin/docker compose down
1413
Restart=on-failure
1514
RestartSec=30s
1615

rootfs/etc/systemd/system/prune.service

Lines changed: 0 additions & 7 deletions
This file was deleted.

rootfs/etc/systemd/system/runner.service

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)