Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
docker-app-manager: Allow host-specific parameters
Browse files Browse the repository at this point in the history
Docker Apps have the notion of a local paramters file that allows
you to render an app with host specific customizations. An example
of a parameters file is:

 https://github.com/docker/app/blob/master/examples/voting-app/voting-app.dockerapp/parameters/production.yml

Where its default parameters are:

 https://github.com/docker/app/blob/master/examples/voting-app/voting-app.dockerapp/parameters.yml

Signed-off-by: Andy Doan <[email protected]>
  • Loading branch information
doanac authored and pattivacek committed May 31, 2019
1 parent 54fb3c3 commit 5612a16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libaktualizr/package_manager/dockerappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ struct DockerApp {
DockerApp(const std::string app_name, const PackageConfig &config)
: name(std::move(app_name)),
app_root(std::move(config.docker_apps_root / app_name)),
app_params(std::move(config.docker_app_params)),
app_bin(std::move(config.docker_app_bin)),
compose_bin(std::move(config.docker_compose_bin)) {}

bool render(const std::string &app_content) {
auto bin = boost::filesystem::canonical(app_bin).string();
Utils::writeFile(app_root / (name + ".dockerapp"), app_content);
std::string cmd("cd " + app_root.string() + " && " + bin + " app render " + name);
if (!app_params.empty()) {
cmd += " -f " + app_params.string();
}
std::string yaml;
if (Utils::shell(cmd, &yaml, true) != 0) {
LOG_ERROR << "Unable to run " << cmd << " output:\n" << yaml;
Expand All @@ -37,6 +41,7 @@ struct DockerApp {

std::string name;
boost::filesystem::path app_root;
boost::filesystem::path app_params;
boost::filesystem::path app_bin;
boost::filesystem::path compose_bin;
};
Expand Down
2 changes: 2 additions & 0 deletions src/libaktualizr/package_manager/packagemanagerconfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void PackageConfig::updateFromPropertyTree(const boost::property_tree::ptree& pt
// token_compress_on allows lists like: "foo,bar", "foo, bar", or "foo bar"
boost::split(docker_apps, val, boost::is_any_of(", "), boost::token_compress_on);
CopyFromConfig(docker_apps_root, "docker_apps_root", pt);
CopyFromConfig(docker_app_params, "docker_app_params", pt);
CopyFromConfig(docker_app_bin, "docker_app_bin", pt);
CopyFromConfig(docker_compose_bin, "docker_compose_bin", pt);
}
Expand All @@ -56,6 +57,7 @@ void PackageConfig::writeToStream(std::ostream& out_stream) const {
#ifdef BUILD_DOCKERAPP
writeOption(out_stream, boost::algorithm::join(docker_apps, ","), "docker_apps");
writeOption(out_stream, docker_apps_root, "docker_apps_root");
writeOption(out_stream, docker_app_params, "docker_app_params");
writeOption(out_stream, docker_app_bin, "docker_app_bin");
writeOption(out_stream, docker_compose_bin, "docker_compose_bin");
#endif
Expand Down
1 change: 1 addition & 0 deletions src/libaktualizr/package_manager/packagemanagerconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct PackageConfig {
#ifdef BUILD_DOCKERAPP
std::vector<std::string> docker_apps;
boost::filesystem::path docker_apps_root;
boost::filesystem::path docker_app_params;
boost::filesystem::path docker_app_bin{"/usr/bin/docker-app"};
boost::filesystem::path docker_compose_bin{"/usr/bin/docker-compose"};
#endif
Expand Down

0 comments on commit 5612a16

Please sign in to comment.