blob: a3837b7de59fd14caf579d08582fa78fe085a8f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "devcontainer_global.h"
#include "devcontainerconfig.h"
#include <QtTaskTree/QTaskTree>
#include <utils/environment.h>
#include <utils/filepath.h>
#include <utils/processinterface.h>
#include <utils/result.h>
#include <memory>
namespace DevContainer {
struct InstancePrivate;
struct DEVCONTAINER_EXPORT InstanceConfig
{
Utils::FilePath dockerCli;
Utils::FilePath workspaceFolder;
Utils::FilePath configFilePath;
bool runProcessesInTerminal = false;
std::vector<std::variant<Mount, QString>> mounts;
Utils::Environment localEnvironment = Utils::Environment::systemEnvironment();
using LogFunction = std::function<void(const QString &)>;
LogFunction logFunction = [](const QString &msg) { qDebug().noquote() << msg; };
QString jsonToString(const QJsonValue &value) const;
QString devContainerId() const;
};
struct DEVCONTAINER_EXPORT RunningInstanceData
{
Utils::OsType osType;
Utils::OsArch osArch;
Utils::Environment remoteEnvironment;
QString containerId;
};
using RunningInstance = std::shared_ptr<RunningInstanceData>;
class DEVCONTAINER_EXPORT Instance
{
public:
explicit Instance(Config config, InstanceConfig instanceConfig);
static Utils::Result<std::unique_ptr<Instance>> fromFile(InstanceConfig instanceConfig);
static std::unique_ptr<Instance> fromConfig(
const Config &config, InstanceConfig instanceConfig = {});
static Utils::Result<Config> configFromFile(InstanceConfig instanceConfig);
~Instance();
Utils::Result<> up(const RunningInstance &runningInstance); // Create and start the container
Utils::Result<> down(); // Stop and remove the container
Utils::ProcessInterface *createProcessInterface(const RunningInstance &runningInstance) const;
Utils::Result<QtTaskTree::Group> upRecipe(const RunningInstance &runningInstance) const;
Utils::Result<QtTaskTree::Group> downRecipe(bool forceDown) const;
const Config &config() const;
private:
std::unique_ptr<InstancePrivate> d;
};
struct UserFromPasswd
{
QString name;
QString uid;
QString gid;
QString home;
QString shell;
};
#ifdef WITH_TESTS
DEVCONTAINER_EXPORT Utils::Result<UserFromPasswd> parseUserFromPasswd(const QString &passwdLine);
#endif
} // namespace DevContainer
|