Skip to content

Commit

Permalink
apps: Use composectl to get running apps status
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Sul <mike.sul@foundries.io>
  • Loading branch information
mike-sul committed May 9, 2024
1 parent c0d447a commit 94300be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/composeapp/appengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ bool AppEngine::isRunning(const App& app) const {
return res;
}

Json::Value AppEngine::getRunningAppsInfo() const {
Json::Value app_statuses;
try {
std::future<std::string> output;
exec(boost::format{"%s --store %s ps --format json"} % composectl_cmd_ % storeRoot(), "",
boost::process::std_out > output);
const auto output_str{output.get()};
app_statuses = Utils::parseJSON(output_str);
} catch (const std::exception& exc) {
LOG_WARNING << "Failed to get an info about running containers: " << exc.what();
}

return app_statuses;
}

bool AppEngine::isAppFetched(const App& app) const {
bool res{false};
try {
Expand Down
1 change: 1 addition & 0 deletions src/composeapp/appengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppEngine : public Docker::RestorableAppEngine {

Result fetch(const App& app) override;
bool isRunning(const App& app) const override;
Json::Value getRunningAppsInfo() const override;

private:
bool isAppFetched(const App& app) const override;
Expand Down
1 change: 1 addition & 0 deletions tests/docker-compose_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def find_existing_container(config_hash):
" since the networking is down")
container = {"Labels": {}}
container["Labels"]["com.docker.compose.project"] = app_name
container["Labels"]["com.docker.compose.project.working_dir"] = os.getcwd()
container["Labels"]["com.docker.compose.service"] = service
container["Labels"]["io.compose-spec.config-hash"] = compose["services"][service]["labels"][
"io.compose-spec.config-hash"]
Expand Down

0 comments on commit 94300be

Please sign in to comment.