web/src/utils/fetch-docker-instructions.ts
85 lines · 1871 bytes
1import { error } from './logger';
2
3export const fetchDockerData = async (
4 serviceName: string,
5): Promise<TemplateResponse | null> => {
6 const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`;
7 try {
8 const res = await fetch(endpoint);
9 if (!res.ok) {
10 error('Docker', `HTTP ${res.status} for ${serviceName} (${endpoint})`);
11 return null;
12 }
13 return await res.json();
14 } catch (err) {
15 error('Docker', `Network error for ${serviceName}: ${err}`);
16 return null;
17 }
18};
19
20interface DockerTemplatePort {
21 privatePort: number;
22 publicPort: number;
23 type: string; // Typically TCP/UDP
24}
25
26interface DockerTemplateEnvironmentVariable {
27 name: string;
28 label?: string;
29 default?: string;
30 description?: string;
31}
32
33interface DockerTemplateVolume {
34 bind: string;
35 container: string;
36 readonly?: boolean;
37}
38
39interface DockerTemplate {
40 name?: string;
41 title: string;
42 description?: string;
43 logo?: string;
44 image: string;
45 categories?: string[];
46 ports?: DockerTemplatePort[];
47 env?: DockerTemplateEnvironmentVariable[];
48 volumes?: DockerTemplateVolume[];
49 restart_policy?: string; // Typically "no", "always", "unless-stopped", "on-failure"
50}
51
52interface DockerHubData {
53 user: string;
54 name: string;
55 namespace: string;
56 repository_type: string;
57 status: number;
58 description: string;
59 is_private: boolean;
60 is_automated: boolean;
61 can_edit: boolean;
62 star_count: number;
63 pull_count: number;
64 last_updated: string;
65 date_registered: string;
66 build_status: string;
67 permissions: {
68 read: boolean;
69 write: boolean;
70 admin: boolean;
71 };
72}
73
74interface DockerUsage {
75 dockerRunCommand: string;
76 dockerComposeFile: string;
77}
78
79export interface TemplateResponse {
80 found: boolean;
81 error: string | null;
82 template?: DockerTemplate;
83 dockerHubData?: DockerHubData;
84 usage?: DockerUsage;
85}