Packages

helijia Skylab deployment package

Current section

Files

Jump to
helijia_skylab lib skylab config.ex
Raw

lib/skylab/config.ex

defmodule Skylab.Config do
@moduledoc """
Skylab 默认的环境配置
## Elixir 应用三挡
* cpu_request: 100m, cpu_limit: 2000m
* cpu_request: 300m, cpu_limit: 2000m
* cpu_request: 500m, cpu_limit: 2000m
"""
@base [
k8s_server: "https://stg-k8s-api.helijia.com",
k8s_namespace: "stg",
image_registry: "registry.cn-beijing.aliyuncs.com",
image_namespace: "hlj-web",
image_registry_user: System.get_env("ALIYUN_REGISTRY_USER"),
image_registry_password: System.get_env("ALIYUN_REGISTRY_PASSWORD"),
replicas: 1,
auto_min_replicas: 1,
auto_max_replicas: 2,
stateful: false,
cpu_request: "100m",
cpu_limit: "2000m",
mem_request: "256Mi",
mem_limit: "2048Mi",
readiness_url: "/heartbeat",
liveness_url: "/heartbeat",
app_run_env: "stg",
node_selector: [
pool: "skylab"
],
mounts: [],
volumes: []
]
@stg_envs 1..9 |> Enum.map(&:"stg#{&1}")
def deploy_config do
Mix.env()
|> deploy_config()
|> with_user_config()
end
def deploy_config(:release) do
@base
|> Keyword.merge(
k8s_server: "https://39.106.140.129:6443",
k8s_namespace: "pre",
image_registry: "registry.cn-beijing.aliyuncs.com",
image_pull_registry: "registry-vpc.cn-beijing.aliyuncs.com",
image_namespace: "hlj-web",
image_registry_user: System.get_env("ALIYUN_REGISTRY_USER"),
image_registry_password: System.get_env("ALIYUN_REGISTRY_PASSWORD"),
app_run_env: "release"
)
end
def deploy_config(:prod) do
:release
|> deploy_config()
|> Keyword.merge(
replicas: 2,
k8s_namespace: "pro",
app_run_env: "prod"
)
end
def deploy_config(env) when env in @stg_envs do
env = to_string(env)
deploy_config(:stg,
k8s_namespace: env,
app_run_env: env
)
end
def deploy_config(env) when is_atom(env) do
@base
end
def deploy_config(env, custom) do
env
|> deploy_config()
|> Keyword.merge(custom)
end
defp with_user_config(opts) do
opts
|> Keyword.merge(Application.get_env(:skylab, :deploy, []))
end
def all() do
[
deploy: deploy_config(),
gitlab_api_token: gitlab_api_token(),
secrets: secrets()
]
end
def gitlab_api_token do
Application.get_env(:skylab, :gitlab_api_token) ||
System.get_env("GITLAB_API_TOKEN")
end
def secrets do
Application.get_env(:skylab, :secrets, [])
end
end