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

fix default images

This commit is contained in:
Bogdan Fazakas 2022-09-20 11:30:11 +03:00
parent 3edf45d87d
commit fe4aa79ffb
5 changed files with 27 additions and 86 deletions

View File

@ -1,16 +1,18 @@
import { LoggerInstance } from '@oceanprotocol/lib'
import axios from 'axios'
import isUrl from 'is-url-superb'
import { toast } from 'react-toastify'
async function isDockerHubImageValid(
export async function getContainerChecksum(
image: string,
tag: string
): Promise<boolean> {
): Promise<string> {
try {
const response = await axios.post(
`https://dockerhub-proxy.oceanprotocol.com`,
{ image, tag }
{
image,
tag
}
)
if (
!response ||
@ -18,46 +20,16 @@ async function isDockerHubImageValid(
response.data.status !== 'success'
) {
toast.error(
'Could not fetch docker hub image info. Please check image name and tag and try again'
'Could not fetch docker hub image info. Please input the container checksum manually'
)
return false
return null
}
return true
return response.data.result.checksum
} catch (error) {
LoggerInstance.error(error.message)
toast.error(
'Could not fetch docker hub image info. Please check image name and tag and try again'
'Could not fetch docker hub image info. Please input the container checksum manually'
)
return false
return null
}
}
async function is3rdPartyImageValid(imageURL: string): Promise<boolean> {
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 false
}
return true
} catch (error) {
LoggerInstance.error(error.message)
toast.error(
'Could not fetch docker image info. Please check URL and try again'
)
return false
}
}
export async function validateDockerImage(
dockerImage: string,
tag: string
): Promise<boolean> {
const isValid = isUrl(dockerImage)
? await is3rdPartyImageValid(dockerImage)
: await isDockerHubImageValid(dockerImage, tag)
return isValid
}

View File

@ -8,6 +8,7 @@ import { toast } from 'react-toastify'
import axios from 'axios'
import isUrl from 'is-url-superb'
import ImageInfo from './Info'
import { getContainerChecksum } from '@utils/docker'
export default function ContainerInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name)
@ -16,38 +17,6 @@ export default function ContainerInput(props: InputProps): ReactElement {
const { values, setFieldError, setFieldValue } =
useFormikContext<FormPublishData>()
async function getContainerChecksum(
image: string,
tag: string
): Promise<string> {
try {
const response = await axios.post(
`https://dockerhub-proxy.oceanprotocol.com`,
{
image,
tag
}
)
if (
!response ||
response.status !== 200 ||
response.data.status !== 'success'
) {
toast.error(
'Could not fetch docker hub image info. Please input the container checksum manually'
)
return null
}
return response.data.result.checksum
} catch (error) {
LoggerInstance.error(error.message)
toast.error(
'Could not fetch docker hub image info. Please input the container checksum manually'
)
return null
}
}
async function handleValidation(e: React.SyntheticEvent, container: string) {
e.preventDefault()
try {

View File

@ -129,7 +129,7 @@ export default function MetadataFields(): ReactElement {
)}
component={Input}
name="metadata.dockerImageCustomChecksum"
disabled={values.metadata.dockerImageCustomChecksum !== null}
disabled
/>
<Field
{...getFieldContent(

View File

@ -96,17 +96,15 @@ export const initialValues: FormPublishData = {
export const algorithmContainerPresets: MetadataAlgorithmContainer[] = [
{
image: 'node',
tag: '18.6.0', // TODO: Put this back to latest once merging the PR that fetches the container digest from docker hub via dockerhub-proxy
tag: 'latest',
entrypoint: 'node $ALGO',
checksum:
'sha256:c60726646352202d95de70d9e8393c15f382f8c6074afc5748b7e570ccd5995f'
checksum: ''
},
{
image: 'python',
tag: '3.10.5', // TODO: Put this back to latest once merging the PR that fetches the container digest from docker hub via dockerhub-proxy
tag: 'latest',
entrypoint: 'python $ALGO',
checksum:
'sha256:607635763e54907fd75397fedfeb83890e62a0f9b54a1d99d27d748c5d269be4'
checksum: ''
}
]

View File

@ -26,20 +26,23 @@ import {
publisherMarketFixedSwapFee
} from '../../../app.config'
import { sanitizeUrl } from '@utils/url'
import { getContainerChecksum } from '@utils/docker'
function getUrlFileExtension(fileUrl: string): string {
const splittedFileUrl = fileUrl.split('.')
return splittedFileUrl[splittedFileUrl.length - 1]
}
function getAlgorithmContainerPreset(
async function getAlgorithmContainerPreset(
dockerImage: string
): MetadataAlgorithmContainer {
): Promise<MetadataAlgorithmContainer> {
if (dockerImage === '') return
const preset = algorithmContainerPresets.find(
(preset) => `${preset.image}:${preset.tag}` === dockerImage
)
preset.checksum = await getContainerChecksum(preset.image, preset.tag)
console.log('preset')
return preset
}
@ -111,20 +114,19 @@ export async function transformPublishFormToDdo(
entrypoint:
dockerImage === 'custom'
? dockerImageCustomEntrypoint
: getAlgorithmContainerPreset(dockerImage).entrypoint,
: (await getAlgorithmContainerPreset(dockerImage)).entrypoint,
image:
dockerImage === 'custom'
? dockerImageCustom
: getAlgorithmContainerPreset(dockerImage).image,
: (await getAlgorithmContainerPreset(dockerImage)).image,
tag:
dockerImage === 'custom'
? dockerImageCustomTag
: getAlgorithmContainerPreset(dockerImage).tag,
: (await getAlgorithmContainerPreset(dockerImage)).tag,
checksum:
dockerImage === 'custom'
? // ? dockerImageCustomChecksum
''
: getAlgorithmContainerPreset(dockerImage).checksum
? dockerImageCustomChecksum
: (await getAlgorithmContainerPreset(dockerImage)).checksum
}
}
})