forked from qt-creator/qt-creator
Docker: Check image exists first before trying to launch it
Otherwise we will trigger a bunch of expensive calls that are not necessary. Change-Id: I9763b251e828f9f3683f120ee473ce6ad7ca84eb Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
@@ -75,6 +75,23 @@ bool DockerApi::isContainerRunning(const QString &containerId)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DockerApi::imageExists(const QString &imageId)
|
||||
{
|
||||
Process process;
|
||||
FilePath dockerExe = dockerClient();
|
||||
if (dockerExe.isEmpty() || !dockerExe.isExecutableFile())
|
||||
return false;
|
||||
|
||||
process.setCommand(
|
||||
CommandLine(dockerExe, QStringList{"image", "inspect", imageId, "--format", "{{.Id}}"}));
|
||||
process.runBlocking();
|
||||
|
||||
if (process.exitCode() == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DockerApi::checkCanConnect(bool async)
|
||||
{
|
||||
if (async) {
|
||||
|
@@ -44,6 +44,7 @@ public:
|
||||
QFuture<Utils::Result<QList<Network>>> networks();
|
||||
|
||||
bool isContainerRunning(const QString &containerId);
|
||||
bool imageExists(const QString &imageId);
|
||||
|
||||
signals:
|
||||
void dockerDaemonAvailableChanged();
|
||||
|
@@ -247,6 +247,9 @@ public:
|
||||
if (DeviceFileAccess *fileAccess = m_fileAccess.readLocked()->get())
|
||||
return fileAccess;
|
||||
|
||||
if (!DockerApi::instance()->imageExists(q->repoAndTag()))
|
||||
return nullptr;
|
||||
|
||||
SynchronizedValue<std::unique_ptr<DeviceFileAccess>>::unique_lock fileAccess
|
||||
= m_fileAccess.writeLocked();
|
||||
if (*fileAccess)
|
||||
@@ -1003,6 +1006,8 @@ Result<QString> DockerDevicePrivate::updateContainerAccess()
|
||||
return make_unexpected(Tr::tr("Device is shut down"));
|
||||
if (DockerApi::isDockerDaemonAvailable(false).value_or(false) == false)
|
||||
return make_unexpected(Tr::tr("Docker system is not reachable"));
|
||||
if (!DockerApi::instance()->imageExists(q->repoAndTag()))
|
||||
return make_unexpected(Tr::tr("Docker image \"%1\" not found.").arg(q->repoAndTag()));
|
||||
|
||||
auto lockedThread = m_deviceThread.writeLocked();
|
||||
if (*lockedThread)
|
||||
|
Reference in New Issue
Block a user