-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
424 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
export * from './hop.js'; | ||
export * from './permissions.js'; | ||
export * from './rest/index.js'; | ||
// Commonly used in the API, so nice to export in two place | ||
export {type APIAuthentication} from './rest/index.js'; | ||
export {ChannelType} from './rest/types/channels.js'; | ||
export { | ||
BuildMethod, | ||
BuildState, | ||
ContainerState, | ||
DomainState, | ||
RestartPolicy, | ||
RolloutState, | ||
RuntimeType, | ||
BuildState, | ||
DomainState, | ||
BuildMethod, | ||
VolumeFormat, | ||
type BuildEnvironment, | ||
} from './rest/types/ignite.js'; | ||
export * from './util/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import {z} from 'zod'; | ||
import { | ||
ContainerStrategy, | ||
RestartPolicy, | ||
RuntimeType, | ||
VolumeFormat, | ||
} from '../../rest/types/ignite.js'; | ||
import {byteUnits, parseSize, isValidByteString} from '../../util/size.js'; | ||
|
||
export const deploymentMetaDataSchema = z.object({ | ||
preset: z.string().optional(), | ||
next_steps_dismissed: z.boolean().optional(), | ||
container_port_mappings: z.record(z.string(), z.set(z.string())).optional(), | ||
created_first_gateway: z.boolean().optional(), | ||
ignored_boarding: z.boolean().optional(), | ||
max_container_storage: z.string().optional(), | ||
}); | ||
|
||
const UNIX_DIR_REGEX = /^\/([a-zA-Z0-9_\-]+\/)*([a-zA-Z0-9_\-]+)$/g; | ||
|
||
const MIN_VOLUME_SIZE_BYTES = 1073741824; // 1gb | ||
const MIN_RAM_SIZE_BYTES = 134217728; | ||
|
||
export const volumeFormatSchema = z.nativeEnum(VolumeFormat); | ||
|
||
export const volumeSchema = z | ||
.object({ | ||
fs: volumeFormatSchema, | ||
size: z | ||
.string() | ||
.transform(value => value.toUpperCase()) | ||
.refine( | ||
isValidByteString, | ||
`Must be a valid byte string, e.g. 1gb. Supported units are ${byteUnits.join( | ||
', ', | ||
)}`, | ||
) | ||
.refine(v => { | ||
try { | ||
const size = parseSize(v); | ||
|
||
return size >= MIN_VOLUME_SIZE_BYTES; | ||
} catch (err) { | ||
return false; | ||
} | ||
}, `Volume size must be at least 1gb`) | ||
.transform(v => v.toLowerCase()), | ||
mountpath: z | ||
.string() | ||
.regex( | ||
UNIX_DIR_REGEX, | ||
"Must be a valid unix directory path, e.g. '/data'", | ||
), | ||
}) | ||
.required(); | ||
|
||
export const buildSettingsSchema = z.object({ | ||
root_directory: z | ||
.string() | ||
.regex(UNIX_DIR_REGEX, "Must be a valid unix directory path, e.g. '/data'") | ||
.or( | ||
z | ||
.string() | ||
.refine(v => v === '' || v === '/') | ||
.transform(() => '/'), | ||
), | ||
}); | ||
|
||
export const deploymentRuntimeTypeSchema = z.nativeEnum(RuntimeType); | ||
|
||
export const containerResourcesSchema = z.object({ | ||
vcpu: z.number().min(0.5).max(16).optional(), | ||
cpu: z.number().min(0.5).max(16).optional(), | ||
ram: z | ||
.string() | ||
.transform(value => value.toUpperCase()) | ||
.refine(isValidByteString) | ||
.refine(v => { | ||
const size = parseSize(v); | ||
return size >= MIN_RAM_SIZE_BYTES; | ||
}) | ||
.transform(v => v.toLowerCase()), | ||
}); | ||
|
||
export const deploymentEnvSchema = z | ||
.record(z.string().min(1).max(128), z.string()) | ||
.optional(); | ||
|
||
export const containerStrategySchema = z.nativeEnum(ContainerStrategy); | ||
|
||
export const deploymentNameSchema = z | ||
.string() | ||
.regex(/^[a-zA-Z0-9-]*$/g, "Must be alphanumeric and can include '-'"); | ||
|
||
export const restartPolicySchema = z.nativeEnum(RestartPolicy); | ||
|
||
export const deploymentConfigSchema = z.object({ | ||
version: z.string().default('2022-12-28'), | ||
restart_policy: restartPolicySchema | ||
.optional() | ||
.default(RestartPolicy.ON_FAILURE), | ||
type: deploymentRuntimeTypeSchema, | ||
cmd: z.array(z.string()).optional(), | ||
image: z.union([ | ||
z.object({ | ||
name: z.string(), | ||
auth: z | ||
.object({ | ||
username: z.string(), | ||
password: z.string(), | ||
}) | ||
.nullable() | ||
.optional(), | ||
}), | ||
z.object({ | ||
name: z.string().optional(), | ||
gh_repo: z.object({ | ||
repo_id: z.number(), | ||
full_name: z.string(), | ||
branch: z.string(), | ||
}), | ||
auth: z.null().optional(), | ||
}), | ||
]), | ||
volume: volumeSchema.optional(), | ||
env: deploymentEnvSchema, | ||
entrypoint: z | ||
.array(z.string()) | ||
.optional() | ||
.transform(v => (!v?.length ? null : v)) | ||
.nullable(), | ||
container_strategy: containerStrategySchema | ||
.optional() | ||
.default(ContainerStrategy.MANUAL), | ||
resources: containerResourcesSchema, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ids.js'; | ||
export * from './presets.js'; | ||
export * from './ignite.js'; |
Oops, something went wrong.
4fc901b
There was a problem hiding this comment.
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-git-master-onehop.vercel.app
js.hop.io
hop-js.vercel.app
hop-js-onehop.vercel.app