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;
|
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)
|
void DockerApi::checkCanConnect(bool async)
|
||||||
{
|
{
|
||||||
if (async) {
|
if (async) {
|
||||||
|
@@ -44,6 +44,7 @@ public:
|
|||||||
QFuture<Utils::Result<QList<Network>>> networks();
|
QFuture<Utils::Result<QList<Network>>> networks();
|
||||||
|
|
||||||
bool isContainerRunning(const QString &containerId);
|
bool isContainerRunning(const QString &containerId);
|
||||||
|
bool imageExists(const QString &imageId);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dockerDaemonAvailableChanged();
|
void dockerDaemonAvailableChanged();
|
||||||
|
@@ -247,6 +247,9 @@ public:
|
|||||||
if (DeviceFileAccess *fileAccess = m_fileAccess.readLocked()->get())
|
if (DeviceFileAccess *fileAccess = m_fileAccess.readLocked()->get())
|
||||||
return fileAccess;
|
return fileAccess;
|
||||||
|
|
||||||
|
if (!DockerApi::instance()->imageExists(q->repoAndTag()))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
SynchronizedValue<std::unique_ptr<DeviceFileAccess>>::unique_lock fileAccess
|
SynchronizedValue<std::unique_ptr<DeviceFileAccess>>::unique_lock fileAccess
|
||||||
= m_fileAccess.writeLocked();
|
= m_fileAccess.writeLocked();
|
||||||
if (*fileAccess)
|
if (*fileAccess)
|
||||||
@@ -1003,6 +1006,8 @@ Result<QString> DockerDevicePrivate::updateContainerAccess()
|
|||||||
return make_unexpected(Tr::tr("Device is shut down"));
|
return make_unexpected(Tr::tr("Device is shut down"));
|
||||||
if (DockerApi::isDockerDaemonAvailable(false).value_or(false) == false)
|
if (DockerApi::isDockerDaemonAvailable(false).value_or(false) == false)
|
||||||
return make_unexpected(Tr::tr("Docker system is not reachable"));
|
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();
|
auto lockedThread = m_deviceThread.writeLocked();
|
||||||
if (*lockedThread)
|
if (*lockedThread)
|
||||||
|
Reference in New Issue
Block a user