mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
added support for custom docker images
This commit is contained in:
parent
ee25e29de0
commit
707045071a
@ -33,9 +33,30 @@
|
|||||||
"placeholder": "e.g. python3.7",
|
"placeholder": "e.g. python3.7",
|
||||||
"help": "Please select a predefined image to run your algorithm.",
|
"help": "Please select a predefined image to run your algorithm.",
|
||||||
"type": "select",
|
"type": "select",
|
||||||
"options": ["NodeJS", "Python 3.7"],
|
"options": ["node:pre-defined", "python:pre-defined", "custom image"],
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "image",
|
||||||
|
"label": "Image URL",
|
||||||
|
"placeholder": "e.g. node or https://hub.docker.com/_/node ",
|
||||||
|
"help": "Provide the name of a docker image or the full url if you have it hosted in a 3rd party repo",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "version",
|
||||||
|
"label": "Version",
|
||||||
|
"placeholder": "e.g. 10",
|
||||||
|
"help": "Provide the version for your image.",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "entrypoint",
|
||||||
|
"label": "Entrypoint",
|
||||||
|
"placeholder": "e.g. python $ALGO",
|
||||||
|
"help": "Provide the entrypoint for your algorithm.",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "algorithmPrivacy",
|
"name": "algorithmPrivacy",
|
||||||
"label": "Algorithm Privacy",
|
"label": "Algorithm Privacy",
|
||||||
|
3
src/@types/MetaData.d.ts
vendored
3
src/@types/MetaData.d.ts
vendored
@ -49,6 +49,9 @@ export interface AlgorithmPublishForm {
|
|||||||
algorithmPrivacy: boolean
|
algorithmPrivacy: boolean
|
||||||
termsAndConditions: boolean
|
termsAndConditions: boolean
|
||||||
// ---- optional fields ----
|
// ---- optional fields ----
|
||||||
|
image: string
|
||||||
|
version: string
|
||||||
|
entrypoint: string
|
||||||
tags?: string
|
tags?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--spacer);
|
gap: var(--spacer);
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
margin-bottom: var(--spacer/2);
|
margin-bottom: var(--spacer);
|
||||||
}
|
}
|
||||||
|
|
||||||
.previewTitle {
|
.previewTitle {
|
||||||
|
@ -33,17 +33,49 @@ export default function FormPublish({
|
|||||||
// setSubmitting(false)
|
// setSubmitting(false)
|
||||||
}, [setErrors, setTouched])
|
}, [setErrors, setTouched])
|
||||||
|
|
||||||
|
function handleImageSelectChange(imageSelected: string) {
|
||||||
|
switch (imageSelected) {
|
||||||
|
case 'node:pre-defined': {
|
||||||
|
setFieldValue('dockerImage', imageSelected)
|
||||||
|
setFieldValue('image', 'node')
|
||||||
|
setFieldValue('version', '10')
|
||||||
|
setFieldValue('entrypoint', 'node $ALGO')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'python:pre-defined': {
|
||||||
|
setFieldValue('dockerImage', imageSelected)
|
||||||
|
setFieldValue('image', 'oceanprotocol/algo_dockers')
|
||||||
|
setFieldValue('version', 'python-panda')
|
||||||
|
setFieldValue('entrypoint', 'python $ALGO')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
setFieldValue('dockerImage', imageSelected)
|
||||||
|
setFieldValue('image', '')
|
||||||
|
setFieldValue('version', '')
|
||||||
|
setFieldValue('entrypoint', '')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Manually handle change events instead of using `handleChange` from Formik.
|
// Manually handle change events instead of using `handleChange` from Formik.
|
||||||
// Workaround for default `validateOnChange` not kicking in
|
// Workaround for default `validateOnChange` not kicking in
|
||||||
function handleFieldChange(
|
function handleFieldChange(
|
||||||
e: ChangeEvent<HTMLInputElement>,
|
e: ChangeEvent<HTMLInputElement>,
|
||||||
field: FormFieldProps
|
field: FormFieldProps
|
||||||
) {
|
) {
|
||||||
|
console.log(field)
|
||||||
const value =
|
const value =
|
||||||
field.type === 'checkbox' ? !JSON.parse(e.target.value) : e.target.value
|
field.type === 'checkbox' ? !JSON.parse(e.target.value) : e.target.value
|
||||||
|
if (field.name === 'dockerImage') {
|
||||||
|
validateField(field.name)
|
||||||
|
handleImageSelectChange(e.target.value)
|
||||||
|
} else {
|
||||||
validateField(field.name)
|
validateField(field.name)
|
||||||
setFieldValue(field.name, value)
|
setFieldValue(field.name, value)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const resetFormAndClearStorage = (e: FormEvent<Element>) => {
|
const resetFormAndClearStorage = (e: FormEvent<Element>) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@ -11,8 +11,13 @@ export const validationSchema: Yup.SchemaOf<AlgorithmPublishForm> = Yup.object()
|
|||||||
description: Yup.string().min(10).required('Required'),
|
description: Yup.string().min(10).required('Required'),
|
||||||
files: Yup.array<FileMetadata>().required('Required').nullable(),
|
files: Yup.array<FileMetadata>().required('Required').nullable(),
|
||||||
dockerImage: Yup.string()
|
dockerImage: Yup.string()
|
||||||
.matches(/NodeJS|Python 3.7/g, { excludeEmptyString: true })
|
.matches(/node:pre-defined|python:pre-defined|custom image/g, {
|
||||||
|
excludeEmptyString: true
|
||||||
|
})
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
|
image: Yup.string().required('Required'),
|
||||||
|
version: Yup.string().required('Required'),
|
||||||
|
entrypoint: Yup.string().required('Required'),
|
||||||
author: Yup.string().required('Required'),
|
author: Yup.string().required('Required'),
|
||||||
termsAndConditions: Yup.boolean().required('Required'),
|
termsAndConditions: Yup.boolean().required('Required'),
|
||||||
// ---- optional fields ----
|
// ---- optional fields ----
|
||||||
@ -26,6 +31,9 @@ export const initialValues: Partial<AlgorithmPublishForm> = {
|
|||||||
name: '',
|
name: '',
|
||||||
author: '',
|
author: '',
|
||||||
dockerImage: '',
|
dockerImage: '',
|
||||||
|
image: '',
|
||||||
|
version: '',
|
||||||
|
entrypoint: '',
|
||||||
files: '',
|
files: '',
|
||||||
description: '',
|
description: '',
|
||||||
algorithmPrivacy: false,
|
algorithmPrivacy: false,
|
||||||
|
@ -70,21 +70,29 @@ export function checkIfTimeoutInPredefinedValues(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAlgoithComponent(selectedAlgorithm: string): MetadataAlgorithm {
|
function getAlgoithComponent(
|
||||||
|
image: string,
|
||||||
|
version: string,
|
||||||
|
entrypoint: string,
|
||||||
|
algorithmLanguace: string
|
||||||
|
): MetadataAlgorithm {
|
||||||
return {
|
return {
|
||||||
language: selectedAlgorithm === 'NodeJS' ? 'js' : 'py',
|
language: algorithmLanguace,
|
||||||
format: 'docker-image',
|
format: 'docker-image',
|
||||||
version: '0.1',
|
version: '0.1',
|
||||||
container: {
|
container: {
|
||||||
entrypoint:
|
entrypoint: entrypoint,
|
||||||
selectedAlgorithm === 'NodeJS' ? 'node $ALGO' : 'python $ALGO',
|
image: image,
|
||||||
image:
|
tag: version
|
||||||
selectedAlgorithm === 'NodeJS' ? 'node' : 'oceanprotocol/algo_dockers',
|
|
||||||
tag: selectedAlgorithm === 'NodeJS' ? '10' : 'python-panda'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAlgoithFileExtension(fileUrl: string): string {
|
||||||
|
const splitedFileUrl = fileUrl.split('.')
|
||||||
|
return splitedFileUrl[splitedFileUrl.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
export function transformPublishFormToMetadata(
|
export function transformPublishFormToMetadata(
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
@ -127,13 +135,23 @@ export function transformPublishAlgorithmFormToMetadata(
|
|||||||
description,
|
description,
|
||||||
tags,
|
tags,
|
||||||
dockerImage,
|
dockerImage,
|
||||||
|
image,
|
||||||
|
version,
|
||||||
|
entrypoint,
|
||||||
termsAndConditions,
|
termsAndConditions,
|
||||||
files
|
files
|
||||||
}: Partial<AlgorithmPublishForm>,
|
}: Partial<AlgorithmPublishForm>,
|
||||||
ddo?: DDO
|
ddo?: DDO
|
||||||
): MetadataMarket {
|
): MetadataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
const algorithm = getAlgoithComponent(dockerImage)
|
const fileUrl = typeof files !== 'string' && files[0].url
|
||||||
|
const algorithmLanguace = getAlgoithFileExtension(fileUrl)
|
||||||
|
const algorithm = getAlgoithComponent(
|
||||||
|
image,
|
||||||
|
version,
|
||||||
|
entrypoint,
|
||||||
|
algorithmLanguace
|
||||||
|
)
|
||||||
const metadata: MetadataMarket = {
|
const metadata: MetadataMarket = {
|
||||||
main: {
|
main: {
|
||||||
...AssetModel.main,
|
...AssetModel.main,
|
||||||
|
Loading…
Reference in New Issue
Block a user