Skip to content

Commit

Permalink
feat(clusters): add pegboard pool (#1153)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Oct 9, 2024
1 parent b4a1d16 commit bffa76f
Show file tree
Hide file tree
Showing 60 changed files with 1,240 additions and 278 deletions.
57 changes: 57 additions & 0 deletions infra/tf/infra_artifacts/container_runner.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
locals {
container_runner_src_dir = "${path.module}/../../../lib/container-runner"

container_runner_src_files = flatten([
["${local.container_runner_src_dir}/Cargo.toml", "${local.container_runner_src_dir}/Cargo.lock"],
[for f in fileset("${local.container_runner_src_dir}/src/", "**/*"): "${local.container_runner_src_dir}/src/${f}"],
])
container_runner_src_hash = md5(join("", [
for f in local.container_runner_src_files: filemd5(f)
]))
container_runner_dst_binary_path = "/tmp/container-runner-${local.container_runner_src_hash}"
}

resource "null_resource" "container_runner_build" {
triggers = {
container_runner_src_hash = local.container_runner_src_hash
container_runner_dst_binary_path = local.container_runner_dst_binary_path
}

provisioner "local-exec" {
command = <<-EOT
#!/bin/bash
set -euf
# Variables
IMAGE_NAME="container-runner:${local.container_runner_src_hash}"
CONTAINER_NAME="temp-container-runner-${local.container_runner_src_hash}"
BINARY_PATH_IN_CONTAINER="/app/target/x86_64-unknown-linux-musl/release/container-runner"
DST_BINARY_PATH="${local.container_runner_dst_binary_path}"
# Build the Docker image
docker build --platform linux/amd64 -t $IMAGE_NAME '${local.container_runner_src_dir}'
# Create a temporary container
docker create --name $CONTAINER_NAME $IMAGE_NAME
# Copy the binary from the container to the host
docker cp $CONTAINER_NAME:$BINARY_PATH_IN_CONTAINER $DST_BINARY_PATH
# Remove the temporary container
docker rm $CONTAINER_NAME
EOT
}
}

resource "aws_s3_object" "container_runner_binary_upload" {
depends_on = [null_resource.container_runner_build]

lifecycle {
prevent_destroy = true
}

bucket = "${var.namespace}-bucket-infra-artifacts"
key = "container-runner/${local.container_runner_src_hash}/container-runner"
source = local.container_runner_dst_binary_path
}

7 changes: 7 additions & 0 deletions infra/tf/infra_artifacts/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ output "job_runner_binary_key" {
value = aws_s3_object.job_runner_binary_upload.key
}

output "container_runner_binary_key" {
value = aws_s3_object.container_runner_binary_upload.key
}

output "pegboard_manager_binary_key" {
value = aws_s3_object.pegboard_manager_binary_upload.key
}
57 changes: 57 additions & 0 deletions infra/tf/infra_artifacts/pegboard_manager.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
locals {
pegboard_manager_src_dir = "${path.module}/../../../lib/pegboard-manager"

pegboard_manager_src_files = flatten([
["${local.pegboard_manager_src_dir}/Cargo.toml", "${local.pegboard_manager_src_dir}/Cargo.lock"],
[for f in fileset("${local.pegboard_manager_src_dir}/src/", "**/*"): "${local.pegboard_manager_src_dir}/src/${f}"],
])
pegboard_manager_src_hash = md5(join("", [
for f in local.pegboard_manager_src_files: filemd5(f)
]))
pegboard_manager_dst_binary_path = "/tmp/pegboard-manager-${local.pegboard_manager_src_hash}"
}

resource "null_resource" "pegboard_manager_build" {
triggers = {
pegboard_manager_src_hash = local.pegboard_manager_src_hash
pegboard_manager_dst_binary_path = local.pegboard_manager_dst_binary_path
}

provisioner "local-exec" {
command = <<-EOT
#!/bin/bash
set -euf
# Variables
IMAGE_NAME="pegboard-manager:${local.pegboard_manager_src_hash}"
CONTAINER_NAME="temp-pegboard-manager-${local.pegboard_manager_src_hash}"
BINARY_PATH_IN_CONTAINER="/app/target/x86_64-unknown-linux-musl/release/pegboard-manager"
DST_BINARY_PATH="${local.pegboard_manager_dst_binary_path}"
# Build the Docker image
docker build --platform linux/amd64 -t $IMAGE_NAME '${local.pegboard_manager_src_dir}'
# Create a temporary container
docker create --name $CONTAINER_NAME $IMAGE_NAME
# Copy the binary from the container to the host
docker cp $CONTAINER_NAME:$BINARY_PATH_IN_CONTAINER $DST_BINARY_PATH
# Remove the temporary container
docker rm $CONTAINER_NAME
EOT
}
}

resource "aws_s3_object" "pegboard_manager_binary_upload" {
depends_on = [null_resource.pegboard_manager_build]

lifecycle {
prevent_destroy = true
}

bucket = "${var.namespace}-bucket-infra-artifacts"
key = "pegboard-manager/${local.pegboard_manager_src_hash}/pegboard-manager"
source = local.pegboard_manager_dst_binary_path
}

59 changes: 5 additions & 54 deletions lib/bolt/cli/src/commands/cluster/datacenter.rs
Original file line number Diff line number Diff line change
@@ -1,58 +1,9 @@
use anyhow::*;
use bolt_core::context::ProjectContext;
use clap::{Parser, ValueEnum};
use clap::Parser;
use rivet_api::{apis::*, models};

#[derive(ValueEnum, Clone)]
pub enum DatacenterProvider {
Linode,
}

impl From<DatacenterProvider> for models::AdminClustersProvider {
fn from(provider: DatacenterProvider) -> Self {
match provider {
DatacenterProvider::Linode => models::AdminClustersProvider::Linode,
}
}
}

#[derive(ValueEnum, Clone)]
pub enum DatacenterBuildDeliveryMethod {
TrafficServer,
S3Direct,
}

impl From<DatacenterBuildDeliveryMethod> for models::AdminClustersBuildDeliveryMethod {
fn from(method: DatacenterBuildDeliveryMethod) -> Self {
match method {
DatacenterBuildDeliveryMethod::TrafficServer => {
models::AdminClustersBuildDeliveryMethod::TrafficServer
}
DatacenterBuildDeliveryMethod::S3Direct => {
models::AdminClustersBuildDeliveryMethod::S3Direct
}
}
}
}

#[derive(ValueEnum, Clone)]
pub enum DatacenterPoolType {
Job,
Gg,
Ats,
Pegboard,
}

impl From<DatacenterPoolType> for models::AdminClustersPoolType {
fn from(pool_type: DatacenterPoolType) -> Self {
match pool_type {
DatacenterPoolType::Job => models::AdminClustersPoolType::Job,
DatacenterPoolType::Gg => models::AdminClustersPoolType::Gg,
DatacenterPoolType::Ats => models::AdminClustersPoolType::Ats,
DatacenterPoolType::Pegboard => models::AdminClustersPoolType::Pegboard,
}
}
}
use super::{BuildDeliveryMethod, PoolType, Provider};

#[derive(Parser)]
pub enum SubCommand {
Expand All @@ -69,13 +20,13 @@ pub enum SubCommand {
display_name: String,
/// The provider of the datacenter
#[clap(long)]
provider: DatacenterProvider,
provider: Provider,
/// The provider datacenter ID
#[clap(long)]
provider_datacenter_id: String,
/// The build delivery method
#[clap(long)]
build_delivery_method: DatacenterBuildDeliveryMethod,
build_delivery_method: BuildDeliveryMethod,
/// Whether or not prebakes are enabled
#[clap(long)]
prebakes_enabled: bool,
Expand All @@ -96,7 +47,7 @@ pub enum SubCommand {
name_id: String,
/// The pool type
#[clap(index = 3)]
pool: DatacenterPoolType,
pool: PoolType,
/// The hardware types
#[clap(long)]
hardware: Vec<String>,
Expand Down
52 changes: 51 additions & 1 deletion lib/bolt/cli/src/commands/cluster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
use anyhow::*;
use bolt_core::context::ProjectContext;
use clap::Parser;
use clap::{Parser, ValueEnum};
use rivet_api::{apis::*, models};
use uuid::Uuid;

mod datacenter;
mod server;

#[derive(ValueEnum, Clone)]
pub enum Provider {
Linode,
}

impl From<Provider> for models::AdminClustersProvider {
fn from(provider: Provider) -> Self {
match provider {
Provider::Linode => models::AdminClustersProvider::Linode,
}
}
}

#[derive(ValueEnum, Clone)]
pub enum BuildDeliveryMethod {
TrafficServer,
S3Direct,
}

impl From<BuildDeliveryMethod> for models::AdminClustersBuildDeliveryMethod {
fn from(method: BuildDeliveryMethod) -> Self {
match method {
BuildDeliveryMethod::TrafficServer => {
models::AdminClustersBuildDeliveryMethod::TrafficServer
}
BuildDeliveryMethod::S3Direct => models::AdminClustersBuildDeliveryMethod::S3Direct,
}
}
}

#[derive(ValueEnum, Clone)]
pub enum PoolType {
Job,
Gg,
Ats,
Pegboard,
Pb,
}

impl From<PoolType> for models::AdminClustersPoolType {
fn from(pool_type: PoolType) -> Self {
match pool_type {
PoolType::Job => models::AdminClustersPoolType::Job,
PoolType::Gg => models::AdminClustersPoolType::Gg,
PoolType::Ats => models::AdminClustersPoolType::Ats,
PoolType::Pegboard | PoolType::Pb => models::AdminClustersPoolType::Pegboard,
}
}
}

#[derive(Parser)]
pub enum SubCommand {
/// Creates a new cluster
Expand Down
Loading

0 comments on commit bffa76f

Please sign in to comment.