Skip to content

Commit

Permalink
attempt to fix cloud-init
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 20, 2024
1 parent 2098a3b commit 5d9c827
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
45 changes: 24 additions & 21 deletions infra-do/droplet-executor.tf
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
resource "digitalocean_droplet" "executor" {
name = "vm-executor"
region = "sfo3"
image = "ubuntu-24-04-x64"
name = "vm-executor"
region = "sfo3"
image = "ubuntu-24-04-x64"
size = "s-1vcpu-2gb" # doctl compute size list
volume_ids = []
tags = []
vpc_uuid = digitalocean_vpc.default.id
vpc_uuid = digitalocean_vpc.default.id
ssh_keys = [digitalocean_ssh_key.default.fingerprint]
droplet_agent = true

user_data = <<-EOF
#cloud-config
package_update: true
package_upgrade: true
packages:
- curl
- micro
- bat
# From: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
runcmd:
- echo "hello from cloud-init!" >> ~/hello.txt
- sudo apt-get update
- sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# From: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
runcmd:
- echo "hello from cloud-init! started! pwd is: $(pwd)" >> /root/hello.txt
- sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- sudo apt-get update
- apt-cache policy docker-ce
- sudo apt install docker-ce
- sudo apt-get install -y docker-ce
- sudo systemctl status docker
- docker pull ghcr.io/bee-ci-system/bee-ci/executor:latest
# Postgres config
- echo "DB_HOST=${digitalocean_database_cluster.postgres.host}" >> .executor.env
- echo "DB_PORT=${digitalocean_database_cluster.postgres.port}" >> .executor.env
- echo "DB_PASSWORD=${digitalocean_database_cluster.postgres.password}" >> .executor.env
- echo "DB_NAME=${digitalocean_database_cluster.postgres.name}" >> .executor.env
- echo "DB_HOST=${digitalocean_database_cluster.postgres.host}" >> /root/.executor.env
- echo "DB_PORT=${digitalocean_database_cluster.postgres.port}" >> /root/.executor.env
- echo "DB_PASSWORD=${digitalocean_database_cluster.postgres.password}" >> /root/.executor.env
- echo "DB_NAME=${digitalocean_database_cluster.postgres.name}" >> /root/.executor.env
# Influx config
- echo "INFLUXDB_URL=http://${digitalocean_droplet.influxdb.ipv4_address_private}:8086" >> .executor.env
- echo "INFLUXDB_ORG=${var.influxdb_org}" >> .executor.env
- echo "INFLUXDB_BUCKET=${var.influxdb_bucket}" >> .executor.env
- echo "INFLUXDB_TOKEN=${var.influxdb_token}" >> .executor.env
- docker run --env-file .executor.env bee-ci-backend-executor:latest
EOF
- echo "INFLUXDB_URL=http://${digitalocean_droplet.influxdb.ipv4_address_private}:8086" >> /root/.executor.env
- echo "INFLUXDB_ORG=${var.influxdb_org}" >> /root/.executor.env
- echo "INFLUXDB_BUCKET=${var.influxdb_bucket}" >> /root/.executor.env
- echo "INFLUXDB_TOKEN=${var.influxdb_token}" >> /root/.executor.env
- docker run --env-file /root/.executor.env bee-ci-backend-executor:latest
- echo "hello from cloud-init! done!" >> /root/hello.txt
EOF
}

# To check if cloud-init completed successfully, see:
Expand Down
36 changes: 26 additions & 10 deletions infra-do/droplet-influx.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
resource "digitalocean_droplet" "influxdb" {
name = "vm-influx"
region = "sfo3"
image = "ubuntu-24-04-x64"
name = "vm-influx"
region = "sfo3"
image = "ubuntu-24-04-x64"
size = "s-1vcpu-512mb-10gb" # doctl compute size list
volume_ids = [digitalocean_volume.influxdb_volume.id]
tags = []
vpc_uuid = digitalocean_vpc.default.id
vpc_uuid = digitalocean_vpc.default.id
ssh_keys = [digitalocean_ssh_key.default.fingerprint]
droplet_agent = true

user_data = <<-EOF
#cloud-config
package_update: true
package_upgrade: true
packages:
- curl
- micro
- bat
# From: https://docs.influxdata.com/influxdb/v2/install/?t=Linux
runcmd:
- echo "hello from cloud-init!" >> ~/hello.txt
- curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
- echo "deb https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
# Ubuntu and Debian
# Add the InfluxData key to verify downloads and add the repository
# Install influxdb
# From: https://docs.influxdata.com/influxdb/v2/install
runcmd:
- echo "hello from cloud-init! started! pwd is: $(pwd)" >> /root/hello.txt
# Install InfluxDB
- curl --silent --location -O https://repos.influxdata.com/influxdata-archive.key
- echo "943666881a1b8d9b849b74caebf02d3465d6beb716510d86a39f6c8e8dac7515 influxdata-archive.key" | sha256sum --check - && cat influxdata-archive.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/influxdata-archive.gpg > /dev/null && echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' | tee /etc/apt/sources.list.d/influxdata.list
- sudo apt-get update && sudo apt-get install -y influxdb2
# Mount the volume to /var/lib/influxdb2
Expand All @@ -42,7 +57,8 @@ resource "digitalocean_droplet" "influxdb" {
# Restart InfluxDB to apply storage and initialization changes
- sudo systemctl enable influxdb
- sudo systemctl restart influxdb
EOF
- echo "hello from cloud-init! done!" >> /root/hello.txt
EOF
}

resource "digitalocean_volume" "influxdb_volume" {
Expand Down
8 changes: 5 additions & 3 deletions infra-do/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ provider "digitalocean" {
}

resource "digitalocean_project" "project" {
name = "bee-ci-proj-tf"
name = "bee-ci-project"
description = "A simple container-based CI system"
environment = "Development"
resources = [
Expand Down Expand Up @@ -49,7 +49,7 @@ resource "digitalocean_project" "project" {
resource "digitalocean_app" "app" {

spec {
name = "bee-ci-tf"
name = "bee-ci-app"
region = "sfo"

// Requires the following record to be set on domain "pacia.tech"
Expand Down Expand Up @@ -197,7 +197,8 @@ resource "digitalocean_app" "app" {
}
}


/*
Disabled: we deploy directly from GitHub
resource "digitalocean_container_registry" "default" {
name = "bee-ci-container-registry"
subscription_tier_slug = "basic" # $5/month
Expand All @@ -207,6 +208,7 @@ resource "digitalocean_container_registry" "default" {
resource "digitalocean_container_registry_docker_credentials" "default" {
registry_name = "bee-ci-container-registry"
}
*/

/*
resource "digitalocean_domain" "main" {
Expand Down

0 comments on commit 5d9c827

Please sign in to comment.