mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 05:23:31 -07:00
Disable update for docker containers (#715)
Also add docker info to about page and sentry context
This commit is contained in:
parent
6afece237c
commit
4be01a5a95
13 changed files with 101 additions and 30 deletions
|
@ -64,6 +64,7 @@ namespace Lidarr.Api.V1.System
|
|||
IsLinux = OsInfo.IsLinux,
|
||||
IsOsx = OsInfo.IsOsx,
|
||||
IsWindows = OsInfo.IsWindows,
|
||||
IsDocker = _osInfo.IsDocker,
|
||||
Mode = _runtimeInfo.Mode,
|
||||
Branch = _configFileProvider.Branch,
|
||||
Authentication = _configFileProvider.AuthenticationMethod,
|
||||
|
|
|
@ -14,7 +14,9 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||
public static bool IsLinux => Os == Os.Linux;
|
||||
public static bool IsOsx => Os == Os.Osx;
|
||||
public static bool IsWindows => Os == Os.Windows;
|
||||
public static bool IsDocker { get; }
|
||||
|
||||
// this needs to not be static so we can mock it
|
||||
public bool IsDocker { get; }
|
||||
|
||||
public string Version { get; }
|
||||
public string Name { get; }
|
||||
|
@ -45,10 +47,6 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||
else
|
||||
{
|
||||
Os = Os.Linux;
|
||||
if (File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("/docker/"))
|
||||
{
|
||||
IsDocker = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -88,8 +86,14 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||
FullName = Name;
|
||||
}
|
||||
|
||||
if (IsLinux && File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("/docker/"))
|
||||
{
|
||||
IsDocker = true;
|
||||
}
|
||||
|
||||
Environment.SetEnvironmentVariable("OS_NAME", Name);
|
||||
Environment.SetEnvironmentVariable("OS_VERSION", Version);
|
||||
Environment.SetEnvironmentVariable("OS_IS_DOCKER", IsDocker.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +102,8 @@ namespace NzbDrone.Common.EnvironmentInfo
|
|||
string Version { get; }
|
||||
string Name { get; }
|
||||
string FullName { get; }
|
||||
|
||||
bool IsDocker { get; }
|
||||
}
|
||||
|
||||
public enum Os
|
||||
|
|
|
@ -260,10 +260,12 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
|||
// populated these values yet
|
||||
var osName = Environment.GetEnvironmentVariable("OS_NAME");
|
||||
var osVersion = Environment.GetEnvironmentVariable("OS_VERSION");
|
||||
var isDocker = Environment.GetEnvironmentVariable("OS_IS_DOCKER");
|
||||
var runTimeVersion = Environment.GetEnvironmentVariable("RUNTIME_VERSION");
|
||||
|
||||
sentryEvent.SetTag("os_name", osName);
|
||||
sentryEvent.SetTag("os_version", $"{osName} {osVersion}");
|
||||
sentryEvent.SetTag("is_docker", isDocker);
|
||||
sentryEvent.SetTag("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}");
|
||||
sentryEvent.SetTag("sqlite_version", $"{DatabaseVersion}");
|
||||
sentryEvent.SetTag("database_migration", $"{DatabaseMigration}");
|
||||
|
|
|
@ -5,6 +5,7 @@ using Moq;
|
|||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.HealthCheck.Checks;
|
||||
|
@ -86,7 +87,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
|||
|
||||
private void GivenDocker()
|
||||
{
|
||||
//
|
||||
Mocker.GetMock<IOsInfo>()
|
||||
.Setup(x => x.IsDocker)
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -139,9 +142,10 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Explicit("Only works if running inside a docker container")]
|
||||
public void should_return_docker_path_mapping_error_if_on_docker_and_root_missing()
|
||||
{
|
||||
GivenDocker();
|
||||
|
||||
Subject.Check().ShouldBeError(wikiFragment: "docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
||||
|
@ -215,9 +219,10 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Explicit("Only works if running inside a docker container")]
|
||||
public void should_return_docker_mapping_error_on_track_import_failed_event_inside_docker_if_folder_does_not_exist()
|
||||
{
|
||||
GivenDocker();
|
||||
|
||||
clientStatus.IsLocalhost = false;
|
||||
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
|
||||
|
||||
|
|
|
@ -87,6 +87,16 @@ namespace NzbDrone.Core.Test.UpdateTests
|
|||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_if_inside_docker()
|
||||
{
|
||||
Mocker.GetMock<IOsInfo>().Setup(x => x.IsDocker).Returns(true);
|
||||
|
||||
Subject.Invoking(x => x.Execute(new ApplicationUpdateCommand()))
|
||||
.ShouldThrow<CommandFailedException>()
|
||||
.WithMessage("Updating is disabled inside a docker container. Please update the container image.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_sandbox_before_update_if_folder_exists()
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
|||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote download client {client.Definition.Name} places downloads in {folder.FullPath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#bad-remote-path-mapping");
|
||||
}
|
||||
else if (OsInfo.IsDocker)
|
||||
else if (_osInfo.IsDocker)
|
||||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} places downloads in {folder.FullPath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
|||
|
||||
if (!_diskProvider.FolderExists(folder.FullPath))
|
||||
{
|
||||
if (OsInfo.IsDocker)
|
||||
if (_osInfo.IsDocker)
|
||||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} places downloads in {folder.FullPath} but this directory does not appear to exist inside the container. Review your remote path mappings and container volume settings.", "#docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
|||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote download client {client.Definition.Name} reported files in {dlpath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#bad-remote-path-mapping");
|
||||
}
|
||||
else if (OsInfo.IsDocker)
|
||||
else if (_osInfo.IsDocker)
|
||||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} reported files in {dlpath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
|
|||
}
|
||||
|
||||
// if it's a remote client/docker, likely missing path mappings
|
||||
if (OsInfo.IsDocker)
|
||||
if (_osInfo.IsDocker)
|
||||
{
|
||||
return new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} reported files in {dlpath} but this directory does not appear to exist inside the container. Review your remote path mappings and container volume settings.", "#docker-bad-remote-path-mapping");
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace NzbDrone.Core.Update
|
|||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IRuntimeInfo _runtimeInfo;
|
||||
private readonly IBackupService _backupService;
|
||||
private readonly IOsInfo _osInfo;
|
||||
|
||||
|
||||
public InstallUpdateService(ICheckUpdateService checkUpdateService,
|
||||
|
@ -46,6 +47,7 @@ namespace NzbDrone.Core.Update
|
|||
IConfigFileProvider configFileProvider,
|
||||
IRuntimeInfo runtimeInfo,
|
||||
IBackupService backupService,
|
||||
IOsInfo osInfo,
|
||||
Logger logger)
|
||||
{
|
||||
if (configFileProvider == null)
|
||||
|
@ -64,6 +66,7 @@ namespace NzbDrone.Core.Update
|
|||
_configFileProvider = configFileProvider;
|
||||
_runtimeInfo = runtimeInfo;
|
||||
_backupService = backupService;
|
||||
_osInfo = osInfo;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -204,6 +207,11 @@ namespace NzbDrone.Core.Update
|
|||
return;
|
||||
}
|
||||
|
||||
if (_osInfo.IsDocker)
|
||||
{
|
||||
throw new CommandFailedException("Updating is disabled inside a docker container. Please update the container image.");
|
||||
}
|
||||
|
||||
if (OsInfo.IsNotWindows && !_configFileProvider.UpdateAutomatically && message.Trigger != CommandTrigger.Manual)
|
||||
{
|
||||
_logger.ProgressDebug("Auto-update not enabled, not installing available update");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue