-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from argon-chat/feature/environment
Feature/environment
- Loading branch information
Showing
6 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Argon.Api.Features.Env; | ||
|
||
using static File; | ||
|
||
public static class EnvironmentExtensions | ||
{ | ||
public static bool IsKube(this IHostEnvironment env) | ||
=> env.Determine() == ArgonEnvironmentKind.Kubernetes; | ||
|
||
public static bool IsDocker(this IHostEnvironment env) | ||
=> env.Determine() == ArgonEnvironmentKind.Docker; | ||
|
||
public static bool IsClassicHost(this IHostEnvironment env) | ||
=> env.Determine() == ArgonEnvironmentKind.HostMachine; | ||
|
||
public static bool IsManaged(this IHostEnvironment env) | ||
=> env.IsDocker() || env.IsKube(); | ||
|
||
public static ArgonEnvironmentKind Determine(this IHostEnvironment _) | ||
{ | ||
if (Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_HOST") != null) | ||
return ArgonEnvironmentKind.Kubernetes; | ||
if (Exists("/.dockerenv") || Directory.Exists("/proc/self/cgroup") && | ||
ReadAllText("/proc/self/cgroup").Contains("docker")) | ||
return ArgonEnvironmentKind.Docker; | ||
return ArgonEnvironmentKind.HostMachine; | ||
} | ||
} | ||
|
||
public enum ArgonEnvironmentKind | ||
{ | ||
HostMachine, | ||
Docker, | ||
Kubernetes, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters