Skip to content

Commit

Permalink
Merge pull request #21 from hopinc/feat/create-deployment-volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
alii authored Sep 21, 2022
2 parents c88a413 + a8a82bd commit e5be9ad
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-toys-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@onehop/js': patch
---

Added volume config to creating a deployment
40 changes: 37 additions & 3 deletions src/rest/types/ignite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ByteString} from '../../util/index.js';
import {ByteSizeString} from '../../util/index.js';
import {Endpoint} from '../endpoints.js';
import {
Empty,
Expand Down Expand Up @@ -83,6 +83,28 @@ export enum VgpuType {
A400 = 'a400',
}

export enum VolumeFormat {
EXT4 = 'ext4',
XFS = 'xfs',
}

export interface VolumeDefinition {
/**
* The format of the volume
*/
fs: VolumeFormat;

/**
* The size of the volume in bytes
*/
size: ByteSizeString;

/**
* The mount point of the volume
*/
mount_path: string;
}

export interface Container {
/**
* The ID of the container
Expand Down Expand Up @@ -124,6 +146,11 @@ export interface Container {
*/
type: RuntimeType;

/**
* The volume definition for this container
*/
volume: VolumeDefinition | null;

/**
* The internal IP of the container
*/
Expand Down Expand Up @@ -164,7 +191,7 @@ export interface Deployment {
/**
* The config for this deployment
*/
config: DeploymentConfig;
config: Omit<DeploymentConfig, 'volume' | 'name'>;
}

// This is a type not an interface so we can make a union
Expand Down Expand Up @@ -213,6 +240,13 @@ export type DeploymentConfig = {
* Restart policy for this deployment
*/
restart_policy: RestartPolicy;

/**
* The volume definition for this deployment
*
* This can only be used when .type is 'stateful'
*/
volume?: VolumeDefinition;
};

/**
Expand Down Expand Up @@ -277,7 +311,7 @@ export interface Resources {
* Amount of memory to allocate in a readible format
* You can use the `parseSize` function to convert this to bytes.
*/
ram: ByteString;
ram: ByteSizeString;

/**
* vGPUs to allocate
Expand Down
13 changes: 12 additions & 1 deletion src/sdks/ignite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {create, Infer} from '@onehop/json-methods';
import {API, assertId, Id} from '../rest/index.js';
import {Deployment, Gateway, GatewayType} from '../rest/types/ignite.js';
import {
Deployment,
Gateway,
GatewayType,
RuntimeType,
} from '../rest/types/ignite.js';
import {parseSize, validateId} from '../util/index.js';
import {sdk} from './create.js';

Expand Down Expand Up @@ -106,6 +111,12 @@ export const ignite = sdk(client => {
);
}

if (config.volume && config.type !== RuntimeType.STATEFUL) {
throw new Error(
'Cannot create a deployment with a volume that is not stateful.',
);
}

const {deployment} = await client.post('/v1/ignite/deployments', config, {
project,
});
Expand Down
7 changes: 5 additions & 2 deletions src/util/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ export type ByteUnit =
| typeof byteUnits[number]
| Uppercase<typeof byteUnits[number]>;

export type ByteString = `${number}${ByteUnit}`;
export type ByteSizeString = `${number}${ByteUnit}`;

export function isValidByteString(value: string): value is ByteString {
/** @deprecated */
export type ByteString = ByteSizeString;

export function isValidByteString(value: string): value is ByteSizeString {
return byteUnits.some(unit => {
if (!value.endsWith(unit)) {
return false;
Expand Down

1 comment on commit e5be9ad

@vercel
Copy link

@vercel vercel bot commented on e5be9ad Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hop-js – ./

hop-js.vercel.app
hop-js-git-master-onehop.vercel.app
hop-js-onehop.vercel.app
js.hop.io

Please sign in to comment.