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:
parent
3edf45d87d
commit
fe4aa79ffb
@ -1,16 +1,18 @@
|
|||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import isUrl from 'is-url-superb'
|
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
async function isDockerHubImageValid(
|
export async function getContainerChecksum(
|
||||||
image: string,
|
image: string,
|
||||||
tag: string
|
tag: string
|
||||||
): Promise<boolean> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`https://dockerhub-proxy.oceanprotocol.com`,
|
`https://dockerhub-proxy.oceanprotocol.com`,
|
||||||
{ image, tag }
|
{
|
||||||
|
image,
|
||||||
|
tag
|
||||||
|
}
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
!response ||
|
!response ||
|
||||||
@ -18,46 +20,16 @@ async function isDockerHubImageValid(
|
|||||||
response.data.status !== 'success'
|
response.data.status !== 'success'
|
||||||
) {
|
) {
|
||||||
toast.error(
|
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 response.data.result.checksum
|
||||||
return true
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
toast.error(
|
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
|
|
||||||
}
|
|
||||||
|
@ -8,6 +8,7 @@ import { toast } from 'react-toastify'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import isUrl from 'is-url-superb'
|
import isUrl from 'is-url-superb'
|
||||||
import ImageInfo from './Info'
|
import ImageInfo from './Info'
|
||||||
|
import { getContainerChecksum } from '@utils/docker'
|
||||||
|
|
||||||
export default function ContainerInput(props: InputProps): ReactElement {
|
export default function ContainerInput(props: InputProps): ReactElement {
|
||||||
const [field, meta, helpers] = useField(props.name)
|
const [field, meta, helpers] = useField(props.name)
|
||||||
@ -16,38 +17,6 @@ export default function ContainerInput(props: InputProps): ReactElement {
|
|||||||
const { values, setFieldError, setFieldValue } =
|
const { values, setFieldError, setFieldValue } =
|
||||||
useFormikContext<FormPublishData>()
|
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) {
|
async function handleValidation(e: React.SyntheticEvent, container: string) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
try {
|
try {
|
||||||
|
@ -129,7 +129,7 @@ export default function MetadataFields(): ReactElement {
|
|||||||
)}
|
)}
|
||||||
component={Input}
|
component={Input}
|
||||||
name="metadata.dockerImageCustomChecksum"
|
name="metadata.dockerImageCustomChecksum"
|
||||||
disabled={values.metadata.dockerImageCustomChecksum !== null}
|
disabled
|
||||||
/>
|
/>
|
||||||
<Field
|
<Field
|
||||||
{...getFieldContent(
|
{...getFieldContent(
|
||||||
|
@ -96,17 +96,15 @@ export const initialValues: FormPublishData = {
|
|||||||
export const algorithmContainerPresets: MetadataAlgorithmContainer[] = [
|
export const algorithmContainerPresets: MetadataAlgorithmContainer[] = [
|
||||||
{
|
{
|
||||||
image: 'node',
|
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',
|
entrypoint: 'node $ALGO',
|
||||||
checksum:
|
checksum: ''
|
||||||
'sha256:c60726646352202d95de70d9e8393c15f382f8c6074afc5748b7e570ccd5995f'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
image: 'python',
|
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',
|
entrypoint: 'python $ALGO',
|
||||||
checksum:
|
checksum: ''
|
||||||
'sha256:607635763e54907fd75397fedfeb83890e62a0f9b54a1d99d27d748c5d269be4'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -26,20 +26,23 @@ import {
|
|||||||
publisherMarketFixedSwapFee
|
publisherMarketFixedSwapFee
|
||||||
} from '../../../app.config'
|
} from '../../../app.config'
|
||||||
import { sanitizeUrl } from '@utils/url'
|
import { sanitizeUrl } from '@utils/url'
|
||||||
|
import { getContainerChecksum } from '@utils/docker'
|
||||||
|
|
||||||
function getUrlFileExtension(fileUrl: string): string {
|
function getUrlFileExtension(fileUrl: string): string {
|
||||||
const splittedFileUrl = fileUrl.split('.')
|
const splittedFileUrl = fileUrl.split('.')
|
||||||
return splittedFileUrl[splittedFileUrl.length - 1]
|
return splittedFileUrl[splittedFileUrl.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAlgorithmContainerPreset(
|
async function getAlgorithmContainerPreset(
|
||||||
dockerImage: string
|
dockerImage: string
|
||||||
): MetadataAlgorithmContainer {
|
): Promise<MetadataAlgorithmContainer> {
|
||||||
if (dockerImage === '') return
|
if (dockerImage === '') return
|
||||||
|
|
||||||
const preset = algorithmContainerPresets.find(
|
const preset = algorithmContainerPresets.find(
|
||||||
(preset) => `${preset.image}:${preset.tag}` === dockerImage
|
(preset) => `${preset.image}:${preset.tag}` === dockerImage
|
||||||
)
|
)
|
||||||
|
preset.checksum = await getContainerChecksum(preset.image, preset.tag)
|
||||||
|
console.log('preset')
|
||||||
return preset
|
return preset
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,20 +114,19 @@ export async function transformPublishFormToDdo(
|
|||||||
entrypoint:
|
entrypoint:
|
||||||
dockerImage === 'custom'
|
dockerImage === 'custom'
|
||||||
? dockerImageCustomEntrypoint
|
? dockerImageCustomEntrypoint
|
||||||
: getAlgorithmContainerPreset(dockerImage).entrypoint,
|
: (await getAlgorithmContainerPreset(dockerImage)).entrypoint,
|
||||||
image:
|
image:
|
||||||
dockerImage === 'custom'
|
dockerImage === 'custom'
|
||||||
? dockerImageCustom
|
? dockerImageCustom
|
||||||
: getAlgorithmContainerPreset(dockerImage).image,
|
: (await getAlgorithmContainerPreset(dockerImage)).image,
|
||||||
tag:
|
tag:
|
||||||
dockerImage === 'custom'
|
dockerImage === 'custom'
|
||||||
? dockerImageCustomTag
|
? dockerImageCustomTag
|
||||||
: getAlgorithmContainerPreset(dockerImage).tag,
|
: (await getAlgorithmContainerPreset(dockerImage)).tag,
|
||||||
checksum:
|
checksum:
|
||||||
dockerImage === 'custom'
|
dockerImage === 'custom'
|
||||||
? // ? dockerImageCustomChecksum
|
? dockerImageCustomChecksum
|
||||||
''
|
: (await getAlgorithmContainerPreset(dockerImage)).checksum
|
||||||
: getAlgorithmContainerPreset(dockerImage).checksum
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user