mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
feat(editor): provide yaml validation for docker compose in the portainer web editor [BE-11697] (#526)
This commit is contained in:
parent
0ebfe047d1
commit
81c5f4acc3
27 changed files with 2046 additions and 36 deletions
|
@ -0,0 +1,37 @@
|
|||
import { JSONSchema7 } from 'json-schema';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import axios from 'axios';
|
||||
|
||||
import { dockerComposeSchema } from './docker-compose-schema';
|
||||
|
||||
const COMPOSE_SCHEMA_URL =
|
||||
'https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json';
|
||||
|
||||
export function useDockerComposeSchema() {
|
||||
return useQuery<JSONSchema7>(
|
||||
['docker-compose-schema'],
|
||||
getDockerComposeSchema,
|
||||
{
|
||||
staleTime: 24 * 60 * 60 * 1000, // 24 hours
|
||||
cacheTime: 30 * 24 * 60 * 60 * 1000, // 30 days
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false,
|
||||
// Start with local schema while fetching
|
||||
initialData: dockerComposeSchema as JSONSchema7,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getDockerComposeSchema() {
|
||||
try {
|
||||
const response = await axios.get<JSONSchema7>(COMPOSE_SCHEMA_URL);
|
||||
// just in case a non-object is returned from a proxy
|
||||
if (typeof response.data !== 'object') {
|
||||
return dockerComposeSchema as JSONSchema7;
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
// Return the local schema as fallback for airgapped environments
|
||||
return dockerComposeSchema as JSONSchema7;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue