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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
// 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 <utils/result.h>
#include <map>
#include <optional>
#include <variant>
#include <vector>
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QString>
#include <QVariant>
namespace DevContainer {
// Forward declarations
struct BuildOptions;
struct Mount;
struct DevContainerCommon;
struct NonComposeBase;
struct DockerfileContainer;
struct ImageContainer;
struct ComposeContainer;
struct Config;
// Enums
enum class ShutdownAction { None, StopContainer, StopCompose };
enum class WaitFor {
InitializeCommand,
OnCreateCommand,
UpdateContentCommand,
PostCreateCommand,
PostStartCommand
};
enum class UserEnvProbe { None, LoginShell, LoginInteractiveShell, InteractiveShell };
enum class OnAutoForward { Notify, OpenBrowser, OpenBrowserOnce, OpenPreview, Silent, Ignore };
enum class MountType { Bind, Volume };
// Command can be string, array, or object of commands
using Command
= std::variant<QString, QStringList, std::map<QString, std::variant<QString, QStringList>>>;
// Port attributes structure
struct PortAttributes
{
OnAutoForward onAutoForward = OnAutoForward::Notify;
bool elevateIfNeeded = false;
QString label = "Application";
bool requireLocalPort = false;
std::optional<QString> protocol;
static Utils::Result<PortAttributes> fromJson(const QJsonObject &json);
};
// GPU requirements structure
struct DEVCONTAINER_EXPORT GpuRequirements
{
struct GpuDetailedRequirements
{
std::optional<int> cores;
std::optional<QString> memory;
static GpuDetailedRequirements fromJson(const QJsonObject &json);
};
std::variant<bool, QString, struct GpuDetailedRequirements> requirements;
static GpuRequirements fromJson(const QJsonValue &value);
};
// Host hardware requirements structure
struct DEVCONTAINER_EXPORT HostRequirements
{
std::optional<int> cpus;
std::optional<QString> memory;
std::optional<QString> storage;
std::optional<GpuRequirements> gpu;
static HostRequirements fromJson(const QJsonObject &json);
};
// Secret metadata structure
struct DEVCONTAINER_EXPORT SecretMetadata
{
std::optional<QString> description;
std::optional<QString> documentationUrl;
static SecretMetadata fromJson(const QJsonObject &json);
};
// Mount structure
struct DEVCONTAINER_EXPORT Mount
{
MountType type;
std::optional<QString> source;
QString target;
static Utils::Result<Mount> fromJson(const QJsonObject &json);
static Utils::Result<std::variant<Mount, QString>> fromJsonVariant(const QJsonValue &value);
};
// Build options structure
struct DEVCONTAINER_EXPORT BuildOptions
{
std::optional<QString> target;
std::map<QString, QString> args;
std::variant<std::monostate, QString, QStringList> cacheFrom;
QStringList options;
static BuildOptions fromJson(const QJsonObject &json);
};
// Non-compose base structure
struct DEVCONTAINER_EXPORT NonComposeBase
{
std::variant<std::monostate, int, QString, QVariantList> appPort;
std::optional<QStringList> runArgs;
ShutdownAction shutdownAction = ShutdownAction::StopContainer;
std::optional<bool> overrideCommand;
std::optional<QString> workspaceFolder;
std::optional<QString> workspaceMount;
Utils::Result<> fromJson(const QJsonObject &json);
};
// Dockerfile container structure
struct DEVCONTAINER_EXPORT DockerfileContainer : NonComposeBase
{
QString dockerfile;
std::optional<QString> context;
std::optional<BuildOptions> buildOptions;
static Utils::Result<DockerfileContainer> fromJson(const QJsonObject &json);
static bool isDockerfileContainer(const QJsonObject &json);
};
// Image container structure
struct DEVCONTAINER_EXPORT ImageContainer : NonComposeBase
{
QString image;
static Utils::Result<ImageContainer> fromJson(const QJsonObject &json);
static bool isImageContainer(const QJsonObject &json);
};
// Compose container structure
struct DEVCONTAINER_EXPORT ComposeContainer
{
std::variant<QString, QStringList> dockerComposeFile;
QString service;
std::optional<QStringList> runServices;
QString workspaceFolder;
ShutdownAction shutdownAction = ShutdownAction::StopCompose;
std::optional<bool> overrideCommand;
static Utils::Result<ComposeContainer> fromJson(const QJsonObject &json);
static bool isComposeContainer(const QJsonObject &json);
};
// Dev container common structure
struct DEVCONTAINER_EXPORT DevContainerCommon
{
std::optional<QString> schema;
std::optional<QString> name;
std::map<QString, QJsonValue> features;
std::optional<QStringList> overrideFeatureInstallOrder;
std::map<QString, SecretMetadata> secrets;
std::optional<QVariantList> forwardPorts;
std::map<QString, PortAttributes> portsAttributes;
std::optional<PortAttributes> otherPortsAttributes;
std::optional<bool> updateRemoteUserUID;
std::map<QString, QString> containerEnv;
std::optional<QString> containerUser;
std::vector<std::variant<Mount, QString>> mounts;
std::optional<bool> init;
std::optional<bool> privileged;
std::optional<QStringList> capAdd;
std::optional<QStringList> securityOpt;
std::map<QString, std::optional<QString>> remoteEnv;
std::optional<QString> remoteUser;
std::optional<Command> initializeCommand;
std::optional<Command> onCreateCommand;
std::optional<Command> updateContentCommand;
std::optional<Command> postCreateCommand;
std::optional<Command> postStartCommand;
std::optional<Command> postAttachCommand;
std::optional<WaitFor> waitFor;
std::optional<UserEnvProbe> userEnvProbe;
std::optional<HostRequirements> hostRequirements;
QJsonObject customizations;
QJsonObject additionalProperties;
static Utils::Result<DevContainerCommon> fromJson(const QJsonObject &json);
};
// Complete DevContainer Configuration
struct DEVCONTAINER_EXPORT Config
{
DevContainerCommon common;
std::variant<std::monostate, DockerfileContainer, ImageContainer, ComposeContainer>
containerConfig;
static Utils::Result<Config> fromJson(const QJsonObject &json);
static Utils::Result<Config> fromJson(const QByteArray &data);
};
// QDebug stream operators for all DevContainer structures
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::OnAutoForward &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::ShutdownAction &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::WaitFor &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::UserEnvProbe &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::MountType &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::PortAttributes &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::GpuRequirements::GpuDetailedRequirements &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::GpuRequirements &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::HostRequirements &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::SecretMetadata &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::Mount &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const std::variant<DevContainer::Mount, QString> &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::BuildOptions &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::DockerfileContainer &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::ImageContainer &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::ComposeContainer &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::NonComposeBase &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::Command &cmd);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::DevContainerCommon &value);
DEVCONTAINER_EXPORT QDebug operator<<(QDebug debug, const DevContainer::Config &value);
} // namespace DevContainer
|