forked from qt-creator/qt-creator
docker: Add dockercli setting
Change-Id: I46fada555d697007042d823ef1cad0658be98e22 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -106,18 +106,20 @@ static Q_LOGGING_CATEGORY(dockerDeviceLog, "qtc.docker.device", QtWarningMsg);
|
||||
class ContainerShell : public Utils::DeviceShell
|
||||
{
|
||||
public:
|
||||
ContainerShell(const QString &containerId)
|
||||
: m_containerId(containerId)
|
||||
ContainerShell(QSharedPointer<DockerSettings> settings, const QString &containerId)
|
||||
: m_settings(settings)
|
||||
, m_containerId(containerId)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
void setupShellProcess(QtcProcess *shellProcess) final
|
||||
{
|
||||
shellProcess->setCommand({"docker", {"container", "start", "-i", "-a", m_containerId}});
|
||||
shellProcess->setCommand({m_settings->dockerBinaryPath.filePath(), {"container", "start", "-i", "-a", m_containerId}});
|
||||
}
|
||||
|
||||
private:
|
||||
QSharedPointer<DockerSettings> m_settings;
|
||||
QString m_containerId;
|
||||
};
|
||||
|
||||
@@ -126,8 +128,9 @@ class DockerDevicePrivate : public QObject
|
||||
Q_DECLARE_TR_FUNCTIONS(Docker::Internal::DockerDevice)
|
||||
|
||||
public:
|
||||
DockerDevicePrivate(DockerDevice *parent)
|
||||
DockerDevicePrivate(DockerDevice *parent, QSharedPointer<DockerSettings> settings)
|
||||
: q(parent)
|
||||
, m_settings(settings)
|
||||
{}
|
||||
|
||||
~DockerDevicePrivate() { stopCurrentContainer(); }
|
||||
@@ -144,6 +147,7 @@ public:
|
||||
|
||||
DockerDevice *q;
|
||||
DockerDeviceData m_data;
|
||||
QSharedPointer<DockerSettings> m_settings;
|
||||
|
||||
// For local file access
|
||||
|
||||
@@ -316,8 +320,8 @@ QString DockerDeviceData::repoAndTag() const
|
||||
|
||||
// DockerDevice
|
||||
|
||||
DockerDevice::DockerDevice(const DockerDeviceData &data)
|
||||
: d(new DockerDevicePrivate(this))
|
||||
DockerDevice::DockerDevice(QSharedPointer<DockerSettings> settings, const DockerDeviceData &data)
|
||||
: d(new DockerDevicePrivate(this, settings))
|
||||
{
|
||||
d->m_data = data;
|
||||
|
||||
@@ -327,7 +331,7 @@ DockerDevice::DockerDevice(const DockerDeviceData &data)
|
||||
setDisplayName(tr("Docker Image \"%1\" (%2)").arg(data.repoAndTag()).arg(data.imageId));
|
||||
setAllowEmptyCommand(true);
|
||||
|
||||
setOpenTerminal([this](const Environment &env, const FilePath &workingDir) {
|
||||
setOpenTerminal([this, settings](const Environment &env, const FilePath &workingDir) {
|
||||
Q_UNUSED(env); // TODO: That's the runnable's environment in general. Use it via -e below.
|
||||
updateContainerAccess();
|
||||
if (d->m_container.isEmpty()) {
|
||||
@@ -345,7 +349,7 @@ DockerDevice::DockerDevice(const DockerDeviceData &data)
|
||||
});
|
||||
|
||||
const QString wd = workingDir.isEmpty() ? "/" : workingDir.path();
|
||||
proc->setCommand({"docker", {"exec", "-it", "-w", wd, d->m_container, "/bin/sh"}});
|
||||
proc->setCommand({settings->dockerBinaryPath.filePath(), {"exec", "-it", "-w", wd, d->m_container, "/bin/sh"}});
|
||||
proc->setEnvironment(Environment::systemEnvironment()); // The host system env. Intentional.
|
||||
proc->start();
|
||||
});
|
||||
@@ -385,7 +389,7 @@ void DockerDevicePrivate::stopCurrentContainer()
|
||||
m_shell.reset();
|
||||
|
||||
QtcProcess proc;
|
||||
proc.setCommand({"docker", {"container", "stop", m_container}});
|
||||
proc.setCommand({m_settings->dockerBinaryPath.filePath(), {"container", "stop", m_container}});
|
||||
|
||||
m_container.clear();
|
||||
|
||||
@@ -410,7 +414,7 @@ void DockerDevicePrivate::startContainer()
|
||||
{
|
||||
const QString display = HostOsInfo::isLinuxHost() ? QString(":0")
|
||||
: QString(getLocalIPv4Address() + ":0.0");
|
||||
CommandLine dockerCreate{"docker", {"create",
|
||||
CommandLine dockerCreate{m_settings->dockerBinaryPath.filePath(), {"create",
|
||||
"-i",
|
||||
"--rm",
|
||||
"-e", QString("DISPLAY=%1").arg(display),
|
||||
@@ -448,7 +452,7 @@ void DockerDevicePrivate::startContainer()
|
||||
return;
|
||||
LOG("Container via process: " << m_container);
|
||||
|
||||
m_shell = std::make_unique<ContainerShell>(m_container);
|
||||
m_shell = std::make_unique<ContainerShell>(m_settings, m_container);
|
||||
connect(m_shell.get(), &DeviceShell::done, this, [this] (const ProcessResultData &resultData) {
|
||||
if (resultData.m_error != QProcess::UnknownError)
|
||||
return;
|
||||
@@ -497,7 +501,7 @@ CommandLine DockerDevice::withDockerExecCmd(const Utils::CommandLine &cmd, bool
|
||||
args << "-i";
|
||||
args << d->m_container;
|
||||
|
||||
CommandLine dcmd{"docker", args};
|
||||
CommandLine dcmd{d->m_settings->dockerBinaryPath.filePath(), args};
|
||||
dcmd.addCommandLineAsArgs(cmd);
|
||||
return dcmd;
|
||||
}
|
||||
@@ -1001,7 +1005,7 @@ bool DockerDevicePrivate::runInContainer(const CommandLine &cmd) const
|
||||
{
|
||||
if (!DockerApi::isDockerDaemonAvailable(false).value_or(false))
|
||||
return false;
|
||||
CommandLine dcmd{"docker", {"exec", m_container}};
|
||||
CommandLine dcmd{m_settings->dockerBinaryPath.filePath(), {"exec", m_container}};
|
||||
dcmd.addCommandLineAsArgs(cmd);
|
||||
|
||||
QtcProcess proc;
|
||||
@@ -1062,8 +1066,9 @@ public:
|
||||
class DockerDeviceSetupWizard final : public QDialog
|
||||
{
|
||||
public:
|
||||
DockerDeviceSetupWizard()
|
||||
DockerDeviceSetupWizard(QSharedPointer<DockerSettings> settings)
|
||||
: QDialog(ICore::dialogParent())
|
||||
, m_settings(settings)
|
||||
{
|
||||
setWindowTitle(DockerDevice::tr("Docker Image Selection"));
|
||||
resize(800, 600);
|
||||
@@ -1100,7 +1105,7 @@ public:
|
||||
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
CommandLine cmd{"docker", {"images", "--format", "{{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.Size}}"}};
|
||||
CommandLine cmd{m_settings->dockerBinaryPath.filePath(), {"images", "--format", "{{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.Size}}"}};
|
||||
m_log->append(DockerDevice::tr("Running \"%1\"\n").arg(cmd.toUserOutput()));
|
||||
|
||||
m_process = new QtcProcess(this);
|
||||
@@ -1150,7 +1155,7 @@ public:
|
||||
DockerImageItem *item = m_model.itemForIndex(selectedRows.front());
|
||||
QTC_ASSERT(item, return {});
|
||||
|
||||
auto device = DockerDevice::create(*item);
|
||||
auto device = DockerDevice::create(m_settings, *item);
|
||||
device->setupId(IDevice::ManuallyAdded);
|
||||
device->setType(Constants::DOCKER_DEVICE_TYPE);
|
||||
device->setMachineType(IDevice::Hardware);
|
||||
@@ -1163,6 +1168,7 @@ public:
|
||||
TreeView *m_view = nullptr;
|
||||
QTextBrowser *m_log = nullptr;
|
||||
QDialogButtonBox *m_buttons;
|
||||
QSharedPointer<DockerSettings> m_settings;
|
||||
|
||||
QtcProcess *m_process = nullptr;
|
||||
QString m_selectedId;
|
||||
@@ -1170,18 +1176,18 @@ public:
|
||||
|
||||
// Factory
|
||||
|
||||
DockerDeviceFactory::DockerDeviceFactory()
|
||||
DockerDeviceFactory::DockerDeviceFactory(QSharedPointer<DockerSettings> settings)
|
||||
: IDeviceFactory(Constants::DOCKER_DEVICE_TYPE)
|
||||
{
|
||||
setDisplayName(DockerDevice::tr("Docker Device"));
|
||||
setIcon(QIcon());
|
||||
setCreator([] {
|
||||
DockerDeviceSetupWizard wizard;
|
||||
setCreator([settings] {
|
||||
DockerDeviceSetupWizard wizard(settings);
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
setConstructionFunction([] { return DockerDevice::create({}); });
|
||||
setConstructionFunction([settings] { return DockerDevice::create(settings, {}); });
|
||||
}
|
||||
|
||||
} // Internal
|
||||
|
||||
Reference in New Issue
Block a user