Skip to content

Commit

Permalink
Added concurrency support to other commands and fixed tofu outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidthor committed Dec 19, 2023
1 parent a74ee1a commit 07f9e35
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/datacenters/local/datacenter.arc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ environment {
port = 5432
username = "postgres"
password = "password"
database = module.postgres.name
url = "postgresql://postgres:[email protected]:5432/${module.postgres.name}"
database = module.database.name
url = "postgresql://postgres:[email protected]:5432/${module.database.name}"
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/datacenters/local/postgres-db/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM alpine:3

# Needed for terraform modules that include a remote source
RUN apk add --no-cache git
RUN apk add --no-cache git jq

RUN wget https://github.com/opentofu/opentofu/releases/download/v1.6.0-beta3/tofu_1.6.0-beta3_amd64.apk
RUN apk add --allow-untrusted tofu_1.6.0-beta3_amd64.apk
Expand Down
8 changes: 6 additions & 2 deletions examples/datacenters/local/postgres-db/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ variable "username" {

variable "password" {}

locals {
name = replace(var.name, "/", "_")
}

provider "postgresql" {
host = var.host
port = var.port
Expand All @@ -38,10 +42,10 @@ provider "postgresql" {
}

resource "postgresql_database" "my_db" {
name = var.name
name = local.name
}

output "name" {
description = "Name of the database that was created"
value = var.name
value = local.name
}
2 changes: 1 addition & 1 deletion examples/datacenters/local/postgres-db/module.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
init: tofu init
plan: tofu plan -input=false -state=$STATE_FILE -detailed-exitcode
outputs: tofu output -state=$STATE_FILE -json
outputs: tofu output -state=$STATE_FILE -json | jq 'map_values(.value)' > $OUTPUT_FILE
apply: VARS=$(echo $INPUTS | jq -r "to_entries | map(\"-var \" + .key + \"=\" + (.value | tostring)) | join(\" \")") && tofu apply -state=$STATE_FILE -auto-approve $VARS
destroy: VARS=$(echo $INPUTS | jq -r "to_entries | map(\"-var \" + .key + \"=\" + (.value | tostring)) | join(\" \")") && tofu destroy -state=$STATE_FILE -auto-approve $VARS
2 changes: 1 addition & 1 deletion examples/datacenters/local/secret/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM alpine:3

# Needed for terraform modules that include a remote source
RUN apk add --no-cache git
RUN apk add --no-cache git jq

RUN wget https://github.com/opentofu/opentofu/releases/download/v1.6.0-beta3/tofu_1.6.0-beta3_amd64.apk
RUN apk add --allow-untrusted tofu_1.6.0-beta3_amd64.apk
Expand Down
2 changes: 1 addition & 1 deletion examples/datacenters/local/secret/module.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
init: tofu init
plan: tofu plan -input=false -state=$STATE_FILE -detailed-exitcode
outputs: tofu output -state=$STATE_FILE -json
outputs: tofu output -state=$STATE_FILE -json | jq 'map_values(.value)' > $OUTPUT_FILE
apply: VARS=$(echo $INPUTS | jq -r "to_entries | map(\"-var \" + .key + \"=\" + (.value | tostring)) | join(\" \")") && tofu apply -state=$STATE_FILE -auto-approve $VARS
destroy: VARS=$(echo $INPUTS | jq -r "to_entries | map(\"-var \" + .key + \"=\" + (.value | tostring)) | join(\" \")") && tofu destroy -state=$STATE_FILE -auto-approve $VARS
2 changes: 1 addition & 1 deletion src/commands/destroy/datacenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DestroyDatacenterCommand = BaseCommand()
'Destroy the datacenter store record, even if destruction of the datacenter fails',
{ default: false },
)
.option('-c, --concurrency <concurrency:number>', 'Maximum number of nodes to apply concurrently', { default: 1 })
.option('-c, --concurrency <concurrency:number>', 'Maximum number of nodes to apply concurrently', { default: 10 })
.arguments('[name:string]')
.action(destroy_datacenter_action);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/destroy/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ export default BaseCommand()
.description('Destroy all the resources in the specified environment')
.option('-v, --verbose [verbose:boolean]', 'Turn on verbose logs', { default: false })
.option('--auto-approve [autoApprove:boolean]', 'Skip all prompts and start the requested action', { default: false })
.option('-c, --concurrency <concurrency:number>', 'Maximum number of nodes to apply concurrently', { default: 1 })
.option('-c, --concurrency <concurrency:number>', 'Maximum number of nodes to apply concurrently', { default: 10 })
.arguments('<name:string>')
.action(destroyEnvironment);
4 changes: 3 additions & 1 deletion src/commands/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type RemoveOptions = {
verbose: boolean;
autoApprove: boolean;
refresh: boolean;
concurrency: number;
} & GlobalOptions;

const RemoveCommand = BaseCommand()
Expand All @@ -21,6 +22,7 @@ const RemoveCommand = BaseCommand()
})
.option('-v, --verbose [verbose:boolean]', 'Turn on verbose logs', { default: false })
.option('-r, --refresh [refresh:boolean]', 'Force update all resources', { default: false })
.option('-c, --concurrency <concurrency:number>', 'Maximum number of nodes to apply concurrently', { default: 10 })
.option('--auto-approve [autoApprove:boolean]', 'Skip all prompts and start the requested action', { default: false })
.action(remove_action);

Expand Down Expand Up @@ -89,7 +91,7 @@ async function remove_action(options: RemoveOptions, name: string): Promise<void
}

await pipeline
.apply({ logger })
.apply({ logger, concurrency: options.concurrency })
.toPromise()
.then(async () => {
await command_helper.environmentUtils.saveEnvironment(
Expand Down
2 changes: 1 addition & 1 deletion src/graphs/infra/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class InfraGraphNode extends GraphNode<Record<string, unknown> | string>
mount_path: '/module',
});

const flags = ['run', '--rm'];
const flags = ['run'];
Object.values(volume_mounts).forEach((value) => {
flags.push('-v', `${value.host_path}:${value.mount_path}`);
});
Expand Down
9 changes: 8 additions & 1 deletion src/utils/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ export const getImageLabels = async (tag_or_digest: string): Promise<Record<stri
throw new Error(stderr);
}

const results = JSON.parse(stdout);
let results = [];
try {
results = JSON.parse(stdout);
} catch (err) {
console.log(stdout);
throw err;
}

if (results.length === 0) {
throw new Error(`No image found for ${tag_or_digest}`);
}
Expand Down

0 comments on commit 07f9e35

Please sign in to comment.