Skip to content

Commit

Permalink
Adding create postgres implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne committed Apr 19, 2024
1 parent f24ef1f commit ced61b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
31 changes: 17 additions & 14 deletions create-postgres/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ inputs:
description: "Cluster id to attach postgres to"
required: true
default: ""
bucket-name:
description: "Name of the bucket to create"
required: true
default: ""
version:
description: "Postgres version to provision."
required: false
instance-type:
description: "Instance type to provision"
required: false
disk:
description: "Disk size in GiB"
required: false
timeout-minutes:
description: "Time to wait for the postgres to have a status of `ready`"
required: false
default: "20"
outputs:
addon-id: # id of the addon
description: "Contains the id of the addon."
bucket-name: # final name of the bucket
description: "Contains the final bucket name."
bucket-prefix: # prefix of the bucket
description: "Contains the prefix of the bucket."
service-account-name: # name of the service account
description: "Contains the name of the service account."
service-account-name-read-only: # name of the read only service account
description: "Contains the name of the read only service account."
service-account-namespace: # namespace of the service account
description: "Contains the namespace of the service account."
version: # Version of postgres
description: "Contains the provisioned postgres version."
instance-type: # Instance type of postgres
description: "Contains the instance type of postgres."
disk: # disk size of postgres
description: "Contains the disk size of postgres."
uri: # URI of the postgres to connect to
description: "Contains the URI of the postgres to connect to."
runs:
using: "node16"
main: "dist/index.js"
34 changes: 15 additions & 19 deletions create-postgres/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as core from "@actions/core";
import {
VendorPortalApi,
createAddonObjectStore,
createAddonPostgres,
pollForAddonStatus,
} from "replicated-lib";

async function run() {
try {
const apiToken = core.getInput("api-token");
const clusterId = core.getInput("cluster-id");
const bucketName = core.getInput("bucket-name");
const version = core.getInput("version");
const instanceType = core.getInput("instance-type");
const diskGib = +core.getInput("disk");
const timeoutMinutes: number = +(core.getInput("timeout-minutes") || 20);
const apiEndpoint = core.getInput("replicated-api-endpoint");

Expand All @@ -20,10 +22,14 @@ async function run() {
apiClient.endpoint = apiEndpoint;
}

let addon = await createAddonObjectStore(apiClient, clusterId, bucketName);
core.info(
`Created Object Store ${addon.id} - waiting for it to be ready...`
let addon = await createAddonPostgres(
apiClient,
clusterId,
version,
instanceType,
diskGib
);
core.info(`Created Postgres ${addon.id} - waiting for it to be ready...`);
core.setOutput("addon-id", addon.id);

addon = await pollForAddonStatus(
Expand All @@ -35,20 +41,10 @@ async function run() {
);

core.info(`Addon ${addon.id} is ready!`);
core.setOutput("bucket-name", addon.object_store?.bucket_name);
core.setOutput("bucket-prefix", addon.object_store?.bucket_prefix);
core.setOutput(
"service-account-name",
addon.object_store?.service_account_name
);
core.setOutput(
"service-account-name-read-only",
addon.object_store?.service_account_name_read_only
);
core.setOutput(
"service-account-namespace",
addon.object_store?.service_account_namespace
);
core.setOutput("version", addon.postgres?.version);
core.setOutput("instance-type", addon.postgres?.instance_type);
core.setOutput("disk", addon.postgres?.disk_gib);
core.setOutput("uri", addon.postgres?.uri);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit ced61b4

Please sign in to comment.