2021-12-10 12:33:47 +01:00
|
|
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
2021-10-28 11:38:40 +02:00
|
|
|
import axios from 'axios'
|
|
|
|
import { toast } from 'react-toastify'
|
|
|
|
|
2022-09-28 14:47:43 +02:00
|
|
|
export interface dockerContainerInfo {
|
|
|
|
exists: boolean
|
|
|
|
checksum: string
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:59:32 +02:00
|
|
|
export async function getContainerChecksum(
|
2021-10-28 11:38:40 +02:00
|
|
|
image: string,
|
|
|
|
tag: string
|
2022-09-28 14:47:43 +02:00
|
|
|
): Promise<dockerContainerInfo> {
|
|
|
|
const containerInfo: dockerContainerInfo = {
|
|
|
|
exists: false,
|
|
|
|
checksum: null
|
|
|
|
}
|
2021-10-28 11:38:40 +02:00
|
|
|
try {
|
|
|
|
const response = await axios.post(
|
|
|
|
`https://dockerhub-proxy.oceanprotocol.com`,
|
2022-09-20 10:30:11 +02:00
|
|
|
{
|
|
|
|
image,
|
|
|
|
tag
|
|
|
|
}
|
2021-10-28 11:38:40 +02:00
|
|
|
)
|
|
|
|
if (
|
|
|
|
!response ||
|
|
|
|
response.status !== 200 ||
|
|
|
|
response.data.status !== 'success'
|
|
|
|
) {
|
|
|
|
toast.error(
|
2022-10-10 14:59:32 +02:00
|
|
|
'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.'
|
2022-09-28 14:47:43 +02:00
|
|
|
)
|
|
|
|
return containerInfo
|
|
|
|
}
|
|
|
|
containerInfo.exists = true
|
|
|
|
containerInfo.checksum = response.data.result.checksum
|
|
|
|
return containerInfo
|
|
|
|
} catch (error) {
|
|
|
|
LoggerInstance.error(error.message)
|
|
|
|
toast.error(
|
2022-10-10 14:59:32 +02:00
|
|
|
'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.'
|
2021-10-28 11:38:40 +02:00
|
|
|
)
|
2022-09-28 14:47:43 +02:00
|
|
|
return containerInfo
|
2021-10-28 11:38:40 +02:00
|
|
|
}
|
|
|
|
}
|