1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

requested changes

This commit is contained in:
Bogdan Fazakas 2022-10-10 15:59:32 +03:00
parent 7eb3f2f479
commit 92aae397e6
5 changed files with 24 additions and 60 deletions

View File

@ -54,9 +54,9 @@
},
{
"name": "dockerImageCustom",
"label": "Docker Image URL",
"placeholder": "e.g. oceanprotocol/algo_dockers:node-vibrant or https://example.com/image_path:image_tag",
"help": "Provide the name and the tag of a public Docker hub image or the full URL if you have it hosted in a 3rd party repository",
"label": "Custom Docker Image",
"placeholder": "e.g. oceanprotocol/algo_dockers:node-vibrant or quay.io/startx/mariadb",
"help": "Provide the name and the tag of a public Docker hub image or the custom image if you have it hosted in a 3rd party repository",
"type": "container",
"required": true
},
@ -69,7 +69,7 @@
},
{
"name": "dockerImageCustomEntrypoint",
"label": "Docker Entrypoint",
"label": "Docker Image Entrypoint",
"placeholder": "e.g. python $ALGO",
"help": "Provide the entrypoint for your algorithm.",
"required": true

View File

@ -268,7 +268,7 @@ export async function getAlgorithmDatasetsForCompute(
const query = generateBaseQuery(baseQueryParams)
const computeDatasets = await queryMetadata(query, cancelToken)
if (computeDatasets.totalResults === 0) return []
if (computeDatasets?.totalResults === 0) return []
const datasets = await transformAssetToAssetSelection(
datasetProviderUri,

View File

@ -1,6 +1,5 @@
import { LoggerInstance } from '@oceanprotocol/lib'
import axios from 'axios'
import isUrl from 'is-url-superb'
import { toast } from 'react-toastify'
export interface dockerContainerInfo {
@ -8,7 +7,7 @@ export interface dockerContainerInfo {
checksum: string
}
async function getDockerHubImageChecksum(
export async function getContainerChecksum(
image: string,
tag: string
): Promise<dockerContainerInfo> {
@ -30,7 +29,7 @@ async function getDockerHubImageChecksum(
response.data.status !== 'success'
) {
toast.error(
'Could not fetch docker hub image info. Please check container image and tag and try again'
'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.'
)
return containerInfo
}
@ -40,44 +39,8 @@ async function getDockerHubImageChecksum(
} catch (error) {
LoggerInstance.error(error.message)
toast.error(
'Could not fetch docker hub image info. Please check container image and tag and try again'
'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.'
)
return containerInfo
}
}
async function validateContainerImageUrl(
imageURL: string
): Promise<dockerContainerInfo> {
const containerInfo: dockerContainerInfo = {
exists: false,
checksum: null
}
try {
const response = await axios.head(imageURL)
if (!response || response.status !== 200) {
toast.error(
'Could not fetch docker image info. Please check URL and try again'
)
return containerInfo
}
containerInfo.exists = true
return containerInfo
} catch (error) {
LoggerInstance.error(error.message)
toast.error(
'Could not fetch docker image info. Please check URL and try again'
)
return containerInfo
}
}
export async function getContainerChecksum(
dockerImage: string,
tag: string
): Promise<dockerContainerInfo> {
const isValid = isUrl(dockerImage)
? await validateContainerImageUrl(dockerImage)
: await getDockerHubImageChecksum(dockerImage, tag)
return isValid
}

View File

@ -1,5 +1,5 @@
import React, { ReactElement } from 'react'
import { filesize } from 'filesize'
import filesize from 'filesize'
import cleanupContentType from '@utils/cleanupContentType'
import styles from './index.module.css'
import Loader from '@shared/atoms/Loader'

View File

@ -24,22 +24,23 @@ export default function ContainerInput(props: InputProps): ReactElement {
try {
setIsLoading(true)
const parsedContainerValue = container?.split(':')
const imageNname = parsedContainerValue?.slice(0, -1).join(':')
const imageName =
parsedContainerValue?.length > 1
? parsedContainerValue?.slice(0, -1).join(':')
: parsedContainerValue[0]
const tag =
parsedContainerValue?.length > 1 ? parsedContainerValue?.at(-1) : ''
const containerInfo = await getContainerChecksum(imageNname, tag)
if (containerInfo.exists) {
setFieldValue('metadata.dockerImageCustom', imageNname)
setFieldValue('metadata.dockerImageCustomTag', tag)
setChecked(true)
if (containerInfo.checksum) {
setFieldValue(
'metadata.dockerImageCustomChecksum',
containerInfo.checksum
)
helpersChecksum.setTouched(false)
setIsValid(true)
}
const containerInfo = await getContainerChecksum(imageName, tag)
setFieldValue('metadata.dockerImageCustom', imageName)
setFieldValue('metadata.dockerImageCustomTag', tag)
setChecked(true)
if (containerInfo.checksum) {
setFieldValue(
'metadata.dockerImageCustomChecksum',
containerInfo.checksum
)
helpersChecksum.setTouched(false)
setIsValid(true)
}
} catch (error) {
setFieldError(`${field.name}[0].url`, error.message)