( compose: Compose, serviceName: string, )
| 750 | }; |
| 751 | |
| 752 | export const getComposeContainer = async ( |
| 753 | compose: Compose, |
| 754 | serviceName: string, |
| 755 | ) => { |
| 756 | try { |
| 757 | const { appName, composeType, serverId } = compose; |
| 758 | // 1. Determine the correct labels based on composeType |
| 759 | const labels: string[] = []; |
| 760 | if (composeType === "stack") { |
| 761 | // Labels for Docker Swarm stack services |
| 762 | labels.push(`com.docker.stack.namespace=${appName}`); |
| 763 | labels.push(`com.docker.swarm.service.name=${appName}_${serviceName}`); |
| 764 | } else { |
| 765 | // Labels for Docker Compose projects (default) |
| 766 | labels.push(`com.docker.compose.project=${appName}`); |
| 767 | labels.push(`com.docker.compose.service=${serviceName}`); |
| 768 | } |
| 769 | const filter = { |
| 770 | status: ["running"], |
| 771 | label: labels, |
| 772 | }; |
| 773 | |
| 774 | const remoteDocker = await getRemoteDocker(serverId); |
| 775 | const containers = await remoteDocker.listContainers({ |
| 776 | filters: JSON.stringify(filter), |
| 777 | limit: 1, |
| 778 | }); |
| 779 | |
| 780 | if (containers.length === 0 || !containers[0]) { |
| 781 | return null; |
| 782 | } |
| 783 | |
| 784 | const container = containers[0]; |
| 785 | return container; |
| 786 | } catch (error) { |
| 787 | throw error; |
| 788 | } |
| 789 | }; |
| 790 | |
| 791 | type ServiceHealthStatus = { |
| 792 | status: "healthy" | "unhealthy"; |
no test coverage detected