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
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
10
src/@types/DDO/Metadata.d.ts
vendored
10
src/@types/DDO/Metadata.d.ts
vendored
@ -1,12 +1,14 @@
|
|||||||
interface MetadataAlgorithm {
|
interface MetadataAlgorithmContainer {
|
||||||
language?: string
|
|
||||||
version?: string
|
|
||||||
container: {
|
|
||||||
entrypoint: string
|
entrypoint: string
|
||||||
image: string
|
image: string
|
||||||
tag: string
|
tag: string
|
||||||
checksum: string
|
checksum: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MetadataAlgorithm {
|
||||||
|
language?: string
|
||||||
|
version?: string
|
||||||
|
container: MetadataAlgorithmContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
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,17 +82,30 @@ 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: files?.length ? getUrlFileExtension(filesTransformed[0]) : '',
|
language: filesTransformed?.length
|
||||||
|
? getUrlFileExtension(filesTransformed[0])
|
||||||
|
: '',
|
||||||
version: '0.1',
|
version: '0.1',
|
||||||
container: {
|
container: {
|
||||||
entrypoint: dockerImageCustomEntrypoint,
|
entrypoint:
|
||||||
image: dockerImageCustom,
|
dockerImage === 'custom'
|
||||||
tag: dockerImageCustomTag,
|
? dockerImageCustomEntrypoint
|
||||||
checksum: '' // TODO: how to get? Is it user input?
|
: getAlgorithmContainerPreset(dockerImage).entrypoint,
|
||||||
|
image:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustom
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).image,
|
||||||
|
tag:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustomTag
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).tag,
|
||||||
|
checksum:
|
||||||
|
dockerImage === 'custom'
|
||||||
|
? dockerImageCustomChecksum
|
||||||
|
: getAlgorithmContainerPreset(dockerImage).checksum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user