Skip to content

Commit d50094c

Browse files
committed
feat(cli): add production deploy workflow
1 parent 5140fd1 commit d50094c

11 files changed

Lines changed: 1051 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
*
3+
* @file DeployCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DEPLOY_COMMAND_HPP
14+
#define VIX_DEPLOY_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
/**
22+
* @brief Command entry point for production deployment.
23+
*/
24+
struct DeployCommand
25+
{
26+
/**
27+
* @brief Run the deploy command.
28+
*
29+
* Supported forms:
30+
*
31+
* `vix deploy`
32+
* `vix deploy --dry-run`
33+
* `vix deploy --verbose`
34+
* `vix deploy --no-pull`
35+
* `vix deploy --no-tests`
36+
*
37+
* @param args Command arguments after `deploy`.
38+
* @return Process exit code.
39+
*/
40+
static int run(const std::vector<std::string> &args);
41+
42+
/**
43+
* @brief Print deploy command help.
44+
*
45+
* @return Process exit code.
46+
*/
47+
static int help();
48+
};
49+
}
50+
51+
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
*
3+
* @file DeployConfig.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DEPLOY_CONFIG_HPP
14+
#define VIX_DEPLOY_CONFIG_HPP
15+
16+
#include <vix/cli/commands/deploy/DeployTypes.hpp>
17+
18+
#include <optional>
19+
#include <string>
20+
21+
namespace vix::commands::deploy
22+
{
23+
/**
24+
* @brief Read the current Vix project name.
25+
*
26+
* @return The detected project name, or std::nullopt if no name can be resolved.
27+
*/
28+
std::optional<std::string> read_project_name();
29+
30+
/**
31+
* @brief Load production deployment configuration from vix.json.
32+
*
33+
* The configuration is read from `production.deploy`.
34+
*
35+
* @return Loaded deployment configuration.
36+
*/
37+
DeployConfig load_deploy_config();
38+
39+
/**
40+
* @brief Apply command-line deploy options to the loaded config.
41+
*
42+
* @param cfg Loaded deployment configuration.
43+
* @param options Runtime deploy options.
44+
* @return Effective deployment configuration.
45+
*/
46+
DeployConfig apply_deploy_options(
47+
DeployConfig cfg,
48+
const DeployOptions &options);
49+
}
50+
51+
#endif
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
*
3+
* @file DeployOutput.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DEPLOY_OUTPUT_HPP
14+
#define VIX_DEPLOY_OUTPUT_HPP
15+
16+
#include <vix/cli/commands/deploy/DeployTypes.hpp>
17+
18+
#include <iosfwd>
19+
#include <string>
20+
21+
namespace vix::commands::deploy::output
22+
{
23+
/**
24+
* @brief Print the deployment configuration summary.
25+
*
26+
* @param out Output stream.
27+
* @param cfg Effective deployment configuration.
28+
* @param options Runtime deployment options.
29+
*/
30+
void print_summary(
31+
std::ostream &out,
32+
const DeployConfig &cfg,
33+
const DeployOptions &options);
34+
35+
/**
36+
* @brief Print the beginning of a deployment step.
37+
*
38+
* @param out Output stream.
39+
* @param label Step label.
40+
*/
41+
void step(
42+
std::ostream &out,
43+
const std::string &label);
44+
45+
/**
46+
* @brief Print the command that will be executed.
47+
*
48+
* @param out Output stream.
49+
* @param command Command text.
50+
*/
51+
void command(
52+
std::ostream &out,
53+
const std::string &command);
54+
55+
/**
56+
* @brief Print a successful deployment message.
57+
*
58+
* @param out Output stream.
59+
* @param message Message to print.
60+
*/
61+
void ok(
62+
std::ostream &out,
63+
const std::string &message);
64+
65+
/**
66+
* @brief Print a deployment warning message.
67+
*
68+
* @param out Output stream.
69+
* @param message Message to print.
70+
*/
71+
void warn(
72+
std::ostream &out,
73+
const std::string &message);
74+
75+
/**
76+
* @brief Print a deployment error message.
77+
*
78+
* @param out Output stream.
79+
* @param message Message to print.
80+
*/
81+
void error(
82+
std::ostream &out,
83+
const std::string &message);
84+
85+
/**
86+
* @brief Print a fix suggestion.
87+
*
88+
* @param out Output stream.
89+
* @param message Fix suggestion.
90+
*/
91+
void fix(
92+
std::ostream &out,
93+
const std::string &message);
94+
}
95+
96+
#endif
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
*
3+
* @file DeployRunner.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DEPLOY_RUNNER_HPP
14+
#define VIX_DEPLOY_RUNNER_HPP
15+
16+
#include <vix/cli/commands/deploy/DeployTypes.hpp>
17+
18+
namespace vix::commands::deploy::runner
19+
{
20+
/**
21+
* @brief Execute the production deployment workflow.
22+
*
23+
* @param cfg Effective deployment configuration.
24+
* @param options Runtime deployment options.
25+
* @return Process exit code.
26+
*/
27+
int run(
28+
const DeployConfig &cfg,
29+
const DeployOptions &options);
30+
}
31+
32+
#endif
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
*
3+
* @file DeployTypes.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DEPLOY_TYPES_HPP
14+
#define VIX_DEPLOY_TYPES_HPP
15+
16+
#include <string>
17+
18+
namespace vix::commands::deploy
19+
{
20+
/**
21+
* @struct DeployOptions
22+
* @brief Runtime options passed from the deploy command line.
23+
*/
24+
struct DeployOptions
25+
{
26+
/**
27+
* @brief Print commands without executing them.
28+
*/
29+
bool dryRun{false};
30+
31+
/**
32+
* @brief Print additional execution details.
33+
*/
34+
bool verbose{false};
35+
36+
/**
37+
* @brief Disable git pull even when enabled in configuration.
38+
*/
39+
bool noPull{false};
40+
41+
/**
42+
* @brief Disable tests even when enabled in configuration.
43+
*/
44+
bool noTests{false};
45+
};
46+
47+
/**
48+
* @struct DeployConfig
49+
* @brief Production deployment configuration.
50+
*/
51+
struct DeployConfig
52+
{
53+
/**
54+
* @brief Application name.
55+
*/
56+
std::string appName{"vix-app"};
57+
58+
/**
59+
* @brief Whether deploy should pull latest code before building.
60+
*/
61+
bool pull{false};
62+
63+
/**
64+
* @brief Git branch to pull.
65+
*/
66+
std::string branch{"main"};
67+
68+
/**
69+
* @brief Build command executed during deployment.
70+
*/
71+
std::string buildCommand{"vix build"};
72+
73+
/**
74+
* @brief Whether deploy should run tests after build.
75+
*/
76+
bool tests{false};
77+
78+
/**
79+
* @brief Test command executed when tests are enabled.
80+
*/
81+
std::string testCommand{"vix tests"};
82+
83+
/**
84+
* @brief systemd service name restarted after build.
85+
*/
86+
std::string serviceName{};
87+
88+
/**
89+
* @brief Whether deploy should run local health check.
90+
*/
91+
bool healthLocal{true};
92+
93+
/**
94+
* @brief Whether deploy should run public health check.
95+
*/
96+
bool healthPublic{false};
97+
98+
/**
99+
* @brief Whether deploy should print recent service logs on failure.
100+
*/
101+
bool logsOnFailure{true};
102+
103+
/**
104+
* @brief Number of journalctl log lines shown on failure.
105+
*/
106+
int logLines{80};
107+
};
108+
}
109+
110+
#endif

src/CLI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <vix/cli/commands/ServiceCommand.hpp>
5353
#include <vix/cli/commands/ProxyCommand.hpp>
5454
#include <vix/cli/commands/HealthCommand.hpp>
55+
#include <vix/cli/commands/DeployCommand.hpp>
5556
#include <vix/cli/commands/AgentCommand.hpp>
5657
#include <vix/cli/commands/GameExportCommand.hpp>
5758
#include <vix/utils/Env.hpp>
@@ -293,6 +294,8 @@ namespace vix
293294
{ return commands::ProxyCommand::run(args); };
294295
commands_["health"] = [](auto args)
295296
{ return commands::HealthCommand::run(args); };
297+
commands_["deploy"] = [](auto args)
298+
{ return commands::DeployCommand::run(args); };
296299
commands_["agent"] = [](auto args)
297300
{ return commands::AgentCommand::run(args); };
298301
commands_["game"] = [](auto args)
@@ -525,6 +528,8 @@ namespace vix
525528
return commands::ProxyCommand::help();
526529
if (cmd == "health")
527530
return commands::HealthCommand::help();
531+
if (cmd == "deploy")
532+
return commands::DeployCommand::help();
528533
if (cmd == "modules")
529534
return commands::ModulesCommand::help();
530535
if (cmd == "game")
@@ -650,6 +655,7 @@ namespace vix
650655
out << indent(3) << "service Install and manage a production systemd service\n";
651656
out << indent(3) << "proxy Generate and validate reverse proxy configs\n";
652657
out << indent(3) << "health Check local, public and WebSocket app health\n";
658+
out << indent(3) << "deploy Run the production deployment workflow\n";
653659
out << indent(3) << "modules Manage optional project modules\n\n";
654660

655661
out << indent(2) << "Registry and dependencies:\n";

0 commit comments

Comments
 (0)