Skip to content

Commit e7fcd3c

Browse files
authored
Merge pull request #158 from dgageot/fix-config-write
Fix config write
2 parents c6f76e8 + 2087cf6 commit e7fcd3c

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/extension/ui/src/Registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const getRegistry = async (client: v1.DockerDesktopClient) => {
1010
if (registry) {
1111
const value = parse(registry)['registry'] as { [key: string]: { ref: string, config: any } }
1212
if (!value) {
13-
client.desktopUI.toast.error('Failed to get parse registry.yaml.registry: ' + registry)
13+
client.desktopUI.toast.error('Failed to parse registry.yaml: ' + registry)
1414
}
1515
return value;
1616
}

src/extension/ui/src/queries/useCatalog.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v1 } from "@docker/extension-api-client-types";
22
import { CatalogItem, CatalogItemRichened, CatalogItemWithName } from '../types/catalog';
33
import { getRegistry, syncRegistryWithConfig } from '../Registry';
44
import Secrets from '../Secrets';
5-
import { parse } from 'yaml';
5+
import { parse, stringify } from "yaml";
66
import { CATALOG_URL, POLL_INTERVAL, UNASSIGNED_SECRET_PLACEHOLDER } from '../Constants';
77
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
88
import { getTemplateForItem } from './useConfig';
@@ -183,12 +183,14 @@ function useRegistry(client: v1.DockerDesktopClient) {
183183

184184
const mutateRegistry = useMutation({
185185
mutationFn: async (newRegistry: { [key: string]: { ref: string; config?: any } }) => {
186-
const payload = escapeJSONForPlatformShell(
187-
{ registry: newRegistry },
188-
client.host.platform
189-
);
186+
const payload = escapeJSONForPlatformShell({
187+
files: [{
188+
path: 'registry.yaml',
189+
content: stringify({ registry: newRegistry })
190+
}]
191+
}, client.host.platform);
190192

191-
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', 'registry.yaml', payload]);
193+
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', payload]);
192194

193195
return newRegistry;
194196
}
@@ -226,12 +228,14 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
226228
[item.name]: { ref: item.ref }
227229
};
228230

229-
const payload = escapeJSONForPlatformShell(
230-
{ registry: newRegistry },
231-
client.host.platform
232-
);
231+
const payload = escapeJSONForPlatformShell({
232+
files: [{
233+
path: "registry.yaml",
234+
content: stringify({ registry: newRegistry })
235+
}]
236+
}, client.host.platform);
233237

234-
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', 'registry.yaml', payload]);
238+
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', payload]);
235239

236240
if (showNotification) {
237241
client.desktopUI.toast.success(`${item.name} registered successfully.`);
@@ -271,12 +275,14 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
271275
delete currentRegistry[item.name];
272276
}
273277

274-
const payload = escapeJSONForPlatformShell(
275-
{ registry: currentRegistry },
276-
client.host.platform
277-
);
278+
const payload = escapeJSONForPlatformShell({
279+
files: [{
280+
path: "registry.yaml",
281+
content: stringify({ registry: currentRegistry })
282+
}]
283+
}, client.host.platform);
278284

279-
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', 'registry.yaml', payload]);
285+
await tryRunImageSync(client, ['--rm', '-v', 'docker-prompts:/docker-prompts', '--workdir', '/docker-prompts', 'vonwig/function_write_files:latest', payload]);
280286

281287
client.desktopUI.toast.success(`${item.name} unregistered successfully.`);
282288
return { success: true, newRegistry: currentRegistry };

0 commit comments

Comments
 (0)