mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
add Docker image presets, populate algo Docker field from them
This commit is contained in:
parent
7c98659c86
commit
3aa739fce0
@ -47,7 +47,9 @@
|
|||||||
"label": "Docker Image",
|
"label": "Docker Image",
|
||||||
"help": "Please select an image to run your algorithm.",
|
"help": "Please select an image to run your algorithm.",
|
||||||
"type": "boxSelection",
|
"type": "boxSelection",
|
||||||
"options": ["node:latest", "python:latest", "Custom"],
|
"options": [
|
||||||
|
"populated from algorithmContainerPresets in Publish/_constants"
|
||||||
|
],
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
14
src/@types/DDO/Metadata.d.ts
vendored
14
src/@types/DDO/Metadata.d.ts
vendored
@ -1,12 +1,14 @@
|
|||||||
|
interface MetadataAlgorithmContainer {
|
||||||
|
entrypoint: string
|
||||||
|
image: string
|
||||||
|
tag: string
|
||||||
|
checksum: string
|
||||||
|
}
|
||||||
|
|
||||||
interface MetadataAlgorithm {
|
interface MetadataAlgorithm {
|
||||||
language?: string
|
language?: string
|
||||||
version?: string
|
version?: string
|
||||||
container: {
|
container: MetadataAlgorithmContainer
|
||||||
entrypoint: string
|
|
||||||
image: string
|
|
||||||
tag: string
|
|
||||||
checksum: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Metadata {
|
interface Metadata {
|
||||||
|
@ -8,22 +8,13 @@ import { getFieldContent } from '../_utils'
|
|||||||
import IconDataset from '@images/dataset.svg'
|
import IconDataset from '@images/dataset.svg'
|
||||||
import IconAlgorithm from '@images/algorithm.svg'
|
import IconAlgorithm from '@images/algorithm.svg'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
|
import { algorithmContainerPresets } from '../_constants'
|
||||||
|
|
||||||
const assetTypeOptionsTitles = getFieldContent(
|
const assetTypeOptionsTitles = getFieldContent(
|
||||||
'type',
|
'type',
|
||||||
content.metadata.fields
|
content.metadata.fields
|
||||||
).options
|
).options
|
||||||
|
|
||||||
const dockerImageOptionsTitles = getFieldContent(
|
|
||||||
'dockerImage',
|
|
||||||
content.metadata.fields
|
|
||||||
).options
|
|
||||||
|
|
||||||
const dockerImageOptions = dockerImageOptionsTitles.map((title) => ({
|
|
||||||
name: title.toLowerCase(),
|
|
||||||
title
|
|
||||||
}))
|
|
||||||
|
|
||||||
export default function MetadataFields(): ReactElement {
|
export default function MetadataFields(): ReactElement {
|
||||||
// connect with Form state, use for conditional field rendering
|
// connect with Form state, use for conditional field rendering
|
||||||
const { values } = useFormikContext<FormPublishData>()
|
const { values } = useFormikContext<FormPublishData>()
|
||||||
@ -45,6 +36,17 @@ export default function MetadataFields(): ReactElement {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Populate the Docker image field with our presets in _constants,
|
||||||
|
// transformPublishFormToDdo will do the rest.
|
||||||
|
const dockerImageOptions: BoxSelectionOption[] =
|
||||||
|
algorithmContainerPresets.map((preset) => ({
|
||||||
|
name: `${preset.image}:${preset.tag}`,
|
||||||
|
title: `${preset.image}:${preset.tag}`,
|
||||||
|
checked: values.metadata.dockerImage === `${preset.image}:${preset.tag}`
|
||||||
|
}))
|
||||||
|
|
||||||
|
dockerImageOptions.push({ name: 'custom', title: 'Custom', checked: false })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Field
|
<Field
|
||||||
|
@ -84,22 +84,17 @@ export const initialValues: FormPublishData = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const initialValuesAlgo: Partial<MetadataPublishFormAlgorithm> = {
|
export const algorithmContainerPresets: MetadataAlgorithmContainer[] = [
|
||||||
// name: '',
|
{
|
||||||
// author: '',
|
image: 'node',
|
||||||
// dataTokenOptions: {
|
tag: 'latest',
|
||||||
// name: '',
|
entrypoint: 'node $ALGO',
|
||||||
// symbol: ''
|
checksum: '' // TODO: how to get?
|
||||||
// },
|
},
|
||||||
// dockerImage: 'node:latest',
|
{
|
||||||
// image: 'node',
|
image: 'python',
|
||||||
// containerTag: 'latest',
|
tag: 'latest',
|
||||||
// entrypoint: 'node $ALGO',
|
entrypoint: 'python $ALGO',
|
||||||
// files: '',
|
checksum: ''
|
||||||
// description: '',
|
}
|
||||||
// algorithmPrivacy: false,
|
]
|
||||||
// termsAndConditions: false,
|
|
||||||
// tags: '',
|
|
||||||
// timeout: 'Forever',
|
|
||||||
// providerUri: ''
|
|
||||||
// }
|
|
||||||
|
@ -37,6 +37,7 @@ export interface FormPublishData {
|
|||||||
dockerImageCustom?: string
|
dockerImageCustom?: string
|
||||||
dockerImageCustomTag?: string
|
dockerImageCustomTag?: string
|
||||||
dockerImageCustomEntrypoint?: string
|
dockerImageCustomEntrypoint?: string
|
||||||
|
dockerImageCustomChecksum?: string
|
||||||
}
|
}
|
||||||
services: FormPublishService[]
|
services: FormPublishService[]
|
||||||
pricing: PriceOptions
|
pricing: PriceOptions
|
||||||
|
@ -2,6 +2,7 @@ import { mapTimeoutStringToSeconds } from '@utils/ddo'
|
|||||||
import { getEncryptedFileUrls } from '@utils/provider'
|
import { getEncryptedFileUrls } from '@utils/provider'
|
||||||
import { sha256 } from 'js-sha256'
|
import { sha256 } from 'js-sha256'
|
||||||
import slugify from 'slugify'
|
import slugify from 'slugify'
|
||||||
|
import { algorithmContainerPresets } from './_constants'
|
||||||
import { FormPublishData } from './_types'
|
import { FormPublishData } from './_types'
|
||||||
|
|
||||||
export function getFieldContent(
|
export function getFieldContent(
|
||||||
@ -16,6 +17,17 @@ function getUrlFileExtension(fileUrl: string): string {
|
|||||||
return splittedFileUrl[splittedFileUrl.length - 1]
|
return splittedFileUrl[splittedFileUrl.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAlgorithmContainerPreset(
|
||||||
|
dockerImage: string
|
||||||
|
): MetadataAlgorithmContainer {
|
||||||
|
if (dockerImage === '') return
|
||||||
|
|
||||||
|
const preset = algorithmContainerPresets.find(
|
||||||
|
(preset) => `${preset.image}:${preset.tag}` === dockerImage
|
||||||
|
)
|
||||||
|
return preset
|
||||||
|
}
|
||||||
|
|
||||||
function dateToStringNoMS(date: Date): string {
|
function dateToStringNoMS(date: Date): string {
|
||||||
return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z')
|
return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z')
|
||||||
}
|
}
|
||||||
@ -42,9 +54,11 @@ export async function transformPublishFormToDdo(
|
|||||||
tags,
|
tags,
|
||||||
author,
|
author,
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
|
dockerImage,
|
||||||
dockerImageCustom,
|
dockerImageCustom,
|
||||||
dockerImageCustomTag,
|
dockerImageCustomTag,
|
||||||
dockerImageCustomEntrypoint
|
dockerImageCustomEntrypoint,
|
||||||
|
dockerImageCustomChecksum
|
||||||
} = metadata
|
} = metadata
|
||||||
const { access, files, links, providerUrl, timeout } = services[0]
|
const { access, files, links, providerUrl, timeout } = services[0]
|
||||||
|
|
||||||
@ -68,20 +82,33 @@ export async function transformPublishFormToDdo(
|
|||||||
additionalInformation: {
|
additionalInformation: {
|
||||||
termsAndConditions
|
termsAndConditions
|
||||||
},
|
},
|
||||||
...(type === 'algorithm' && {
|
...(type === 'algorithm' &&
|
||||||
// TODO: This needs some set of predefined values for `container`,
|
dockerImage !== '' && {
|
||||||
// depending on user selection in the form.
|
algorithm: {
|
||||||
algorithm: {
|
language: filesTransformed?.length
|
||||||
language: files?.length ? getUrlFileExtension(filesTransformed[0]) : '',
|
? getUrlFileExtension(filesTransformed[0])
|
||||||
version: '0.1',
|
: '',
|
||||||
container: {
|
version: '0.1',
|
||||||
entrypoint: dockerImageCustomEntrypoint,
|
container: {
|
||||||
image: dockerImageCustom,
|
entrypoint:
|
||||||
tag: dockerImageCustomTag,
|
dockerImage === 'custom'
|
||||||
checksum: '' // TODO: how to get? Is it user input?
|
? dockerImageCustomEntrypoint
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).entrypoint,
|
||||||
|
image:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustom
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).image,
|
||||||
|
tag:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustomTag
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).tag,
|
||||||
|
checksum:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustomChecksum
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).checksum
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypt just created string[] of urls
|
// Encrypt just created string[] of urls
|
||||||
|
Loading…
Reference in New Issue
Block a user