MCPcopy
hub / github.com/subquery/subql / updateDockerCompose

Function updateDockerCompose

packages/cli/src/controller/add-chain-controller.ts:213–263  ·  view source on GitHub ↗
(projectDir: string, chainManifestPath: string)

Source from the content-addressed store, hash-verified

211}
212
213export async function updateDockerCompose(projectDir: string, chainManifestPath: string): Promise<void> {
214 const serviceName = `subquery-node-${path.basename(chainManifestPath, '.yaml')}`;
215 const dockerComposePath = path.join(projectDir, 'docker-compose.yml');
216 const dockerCompose = loadDockerComposeFile(dockerComposePath);
217 if (!dockerCompose) {
218 throw new Error(`Docker Compose file does not exist at the specified location: ${dockerComposePath}`);
219 }
220
221 console.log(`Updating Docker Compose for chain manifest: ${chainManifestPath}`);
222
223 //check if service already exists
224 const services = dockerCompose.get('services');
225 if (services && services instanceof YAMLMap) {
226 const existingService = services.items.find((item) => {
227 const image = item.value.toJSON().image;
228 if (!image || !image.startsWith('onfinality/subql-node')) {
229 return false;
230 }
231 const commands: string[] = item.value.toJSON().command;
232 return commands?.includes(`-f=app/${path.basename(chainManifestPath)}`);
233 });
234
235 if (existingService) {
236 console.log(
237 `Service for ${path.basename(chainManifestPath)} already exists in Docker Compose, skipping addition`
238 );
239 return;
240 }
241 }
242
243 let subqlNodeService = getSubqlNodeService(dockerCompose);
244 if (subqlNodeService) {
245 // If the service already exists, update its configuration
246 subqlNodeService.command = subqlNodeService.command?.filter((cmd) => !cmd.startsWith('-f=')) ?? [];
247 subqlNodeService.command.push(`-f=app/${path.basename(chainManifestPath)}`);
248
249 if (subqlNodeService.healthcheck) {
250 subqlNodeService.healthcheck.test = ['CMD', 'curl', '-f', `http://${serviceName}:3000/ready`];
251 }
252 } else {
253 // Otherwise, create a new service configuration
254 subqlNodeService = await getDefaultServiceConfiguration(chainManifestPath, serviceName);
255 }
256 console.log(`Created new service configuration: ${serviceName}`);
257
258 (services as YAMLMap).add({key: serviceName, value: subqlNodeService});
259
260 // Save the updated Docker Compose file
261 fs.writeFileSync(dockerComposePath, dockerCompose.toString());
262 console.log(`Docker Compose file updated successfully at: ${dockerComposePath}`);
263}
264
265function isMultiChainProject(content: string): boolean {
266 return Array.isArray((loadFromJsonOrYaml(content) as MultichainProjectManifest).projects);

Callers 1

addChainFunction · 0.85

Calls 8

loadDockerComposeFileFunction · 0.85
getSubqlNodeServiceFunction · 0.85
toJSONMethod · 0.80
addMethod · 0.80
getMethod · 0.65
findMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected