Skip to content

Commit

Permalink
Merge pull request #140 from hopinc/deployment-groups
Browse files Browse the repository at this point in the history
feat: Deployment groups
  • Loading branch information
Phineas authored Oct 2, 2023
2 parents e31565f + e34ef06 commit 8686b64
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 6 deletions.
60 changes: 58 additions & 2 deletions src/rest/types/ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ export interface Deployment {
* Build settings for deployment
*/
build_settings?: BuildSettings;

/**
* The group the deployment belongs in
*/
group_id: Id<'deployment_group'> | null;
}

/**
Expand Down Expand Up @@ -546,6 +551,29 @@ export type HealthCheck = {
created_at: Timestamp;
};

export type Group = {
/**
* The ID of the group
*/
id: Id<'deployment_group'>;
/**
* The name of the group
*/
name: string;
/**
* The ID of the project the group belongs to
*/
project_id: Id<'project'>;
/**
* The position of the group in the list
*/
position: number;
/**
* The date the group was created
*/
created_at: Timestamp;
};

/**
* A deployment rollout
* @public
Expand Down Expand Up @@ -962,7 +990,11 @@ export interface DomainRedirect {
* @public
*/
export type IgniteEndpoints =
| Endpoint<'GET', '/v1/ignite/deployments', {deployments: Deployment[]}>
| Endpoint<
'GET',
'/v1/ignite/deployments',
{deployments: Deployment[]; groups: Group[]}
>
| Endpoint<
'GET',
'/v1/ignite/deployments/:deployment_id/containers',
Expand Down Expand Up @@ -1084,4 +1116,28 @@ export type IgniteEndpoints =
Partial<Omit<HealthCheck, 'id'>>
>
| Endpoint<'DELETE', '/v1/ignite/domains/:domain_id', Empty>
| Endpoint<'GET', '/v1/ignite/domains/:domain_id', {domain: Domain}>;
| Endpoint<'GET', '/v1/ignite/domains/:domain_id', {domain: Domain}>
| Endpoint<
'POST',
'/v1/ignite/groups',
{group: Group},
{
name: string;
deployment_ids: Id<'deployment'>[];
}
>
| Endpoint<
'PATCH',
'/v1/ignite/groups/:group_id',
{group: Group},
{
name?: string | undefined;
position?: number | undefined;
}
>
| Endpoint<
'PUT',
'/v1/ignite/groups/:group_id/deployments/:deployment_id',
{group: Group}
>
| Endpoint<'DELETE', '/v1/ignite/groups/:group_id', Empty>;
111 changes: 107 additions & 4 deletions src/sdks/ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type DeploymentConfig,
type DeploymentMetadata,
type Gateway,
type Group,
} from '../rest/types/ignite.ts';
import {parseSize, validateId} from '../util/index.ts';
import {sdk} from './create.ts';
Expand Down Expand Up @@ -255,7 +256,7 @@ export const ignite = sdk(client => {

const deploymentGateways = {
/**
* Fecthes all gateways attached to a deployment
* Fetches all gateways attached to a deployment
*
* @param deploymentId - The ID of the deployment to fetch gateways for
*/
Expand All @@ -272,7 +273,7 @@ export const ignite = sdk(client => {
* Creates and attaches a gateway to a deployment
*
* @param deployment - The deployment to create a gateway on
* @param type - The type of the gatway to create, either internal or external
* @param type - The type of the gateway to create, either internal or external
* @param protocol - The protocol that the gateway will listen for
* @param targetPort - The port to listen on
*/
Expand Down Expand Up @@ -315,7 +316,97 @@ export const ignite = sdk(client => {
},
};

const groups = {
async create(
name: string,
deploymentIds?: Id<'deployment'>[] | undefined,
projectId?: Id<'project'>,
) {
if (client.authType !== 'ptk' && !projectId) {
throw new Error(
'Project ID is required for Bearer or PAT authentication',
);
}

const {group} = await client.post(
'/v1/ignite/groups',
{
name,
deployment_ids: deploymentIds ?? [],
},
projectId ? {project: projectId} : {},
);

return group;
},

async edit(
groupId: Id<'deployment_group'>,
{
name,
position,
}: {name?: string | undefined; position?: number | undefined},
projectId?: Id<'project'>,
) {
if (client.authType !== 'ptk' && !projectId) {
throw new Error(
'Project ID is required for Bearer or PAT authentication',
);
}

const {group} = await client.patch(
'/v1/ignite/groups/:group_id',
{
name,
position,
},
{group_id: groupId, ...(projectId ? {project: projectId} : {})},
);

return group;
},

async move(
deploymentId: Id<'deployment'>,
groupId: Id<'deployment_group'>,
projectId?: Id<'project'>,
) {
if (client.authType !== 'ptk' && !projectId) {
throw new Error(
'Project ID is required for Bearer or PAT authentication',
);
}

const {group} = await client.put(
'/v1/ignite/groups/:group_id/deployments/:deployment_id',
undefined,
{
group_id: groupId,
deployment_id: deploymentId,
...(projectId ? {project: projectId} : {}),
},
);

return group;
},

async delete(groupId: Id<'deployment_group'>, projectId?: Id<'project'>) {
if (client.authType !== 'ptk' && !projectId) {
throw new Error(
'Project ID is required for Bearer or PAT authentication',
);
}

await client.delete('/v1/ignite/groups/:group_id', undefined, {
group_id: groupId,
...(projectId ? {project: projectId} : {}),
});
},
};

const igniteSDK = {
groups,

domains: {
delete: async (id: Id<'domain'>) => {
await client.delete('/v1/ignite/domains/:domain_id', undefined, {
Expand Down Expand Up @@ -456,12 +547,24 @@ export const ignite = sdk(client => {
);
}

const {deployments} = await client.get(
const {deployments, groups} = await client.get(
'/v1/ignite/deployments',
projectId ? {project: projectId} : {},
);

return deployments.map(Deployments.from);
const groupRecord = groups.reduce((acc, group) => {
acc[group.id] = group;
return acc;
}, {} as Record<Group['id'], Group>);

return deployments
.map(deployment => ({
...deployment,
group: deployment.group_id
? groupRecord[deployment.group_id]
: null,
}))
.map(Deployments.from);
},

/**
Expand Down
4 changes: 4 additions & 0 deletions src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export const ID_PREFIXES = [
prefix: 'webhook',
description: 'Webhook ID for webhooks on a project.',
},
{
prefix: 'deployment_group',
description: 'Group ID for Ignite deployments',
},
] as const;

/**
Expand Down

0 comments on commit 8686b64

Please sign in to comment.