View Source Antikythera.Env (antikythera v0.5.0)

Module to provide helpers to access environment variables defined by antikythera.

Environments and deployments

Antikythera instances and gears may run in the following two modes:

  • As a mix project, when invoked by running iex or mix command-line tool.
  • As an OTP release, which is generated by e.g. antikythera_core.generate_release task.

In general there are multiple deployments per antikythera instance. To distingish the target deployment from code, antikythera defines the following environment variables:

  • At compile time (for metaprogramming): ANTIKYTHERA_COMPILE_ENV must be appropriately set; the value can be retrieved by compile_env/0.
  • At runtime: ANTIKYTHERA_RUNTIME_ENV must be appropriately set; the value can be retrieved by runtime_env/0.

It is the responsibility of antikythera instance administrators to correctly set these environment variables when compiling/running antikythera and gears. Possible values returned by compile_env/0 and runtime_env/0 are:

  • names of deployments given by :deployments application config
  • :local (running an OTP release at local machine for testing purpose)
  • :undefined

As an example, if you set :dev and :prod in :deployments, then you get:

|                           | Mix.env() at compile-time              | Mix.env() at runtime    | compile_env(), runtime_env() |
|---------------------------+----------------------------------------+-------------------------+------------------------------|
| $ iex -S mix              | :dev  (toplevel), :prod (dependencies) | :dev                    | :undefined                   |
| $ mix test                | :test (toplevel), :prod (dependencies) | :test                   | :undefined                   |
| $ mix antikythera_local.* | :prod                                  | (:mix is not available) | :local                       |
| :dev deployment           | :prod                                  | (:mix is not available) | :dev                         |
| :prod deployment          | :prod                                  | (:mix is not available) | :prod                        |

You can use these values to distinguish the current context from your code.

Summary

Types

@type t() :: :dev | :prod | :local | :undefined

Functions

Link to this function

antikythera_instance_name()

View Source
@spec antikythera_instance_name() :: atom()
Link to this function

asset_base_url(gear_name)

View Source
@spec base_url(Antikythera.Conn.t()) :: Antikythera.Url.t()

Return the base URL which based on the Host HTTP header of the request.

This function is useful if you use a custom domain. Whether the scheme of the URL is https or http depends on whether Antikythera.Env.Mapping.cloud?/1 returns true or false.

@spec compile_env() :: t()
@spec compiling_for_cloud?() :: boolean()
Link to this function

compiling_for_mix_task?()

View Source
@spec compiling_for_mix_task?() :: boolean()
Link to this function

compiling_for_release?()

View Source
@spec compiling_for_release?() :: boolean()
Link to this function

default_base_url(gear_name, env \\ :undefined)

View Source
@spec default_base_url(
  Antikythera.GearName.t() | Antikythera.GearNameStr.t(),
  t()
) :: Antikythera.Url.t()

Return the base URL of the gear.

If the gear name is my_gear and the Antikythera is deployed at antikythera.example.com, this function returns https://my-gear.antikythera.example.com.

@spec gear_action_timeout() :: pos_integer()

Default timeout (in milli-seconds) for gear actions.

This can be configurable by specifying "GEAR_ACTION_TIMEOUT" environment variable when compiling antikythera. Defaults to 10000.

@spec new(any()) :: Croma.Result.t(t())
@spec new!(any()) :: t()
@spec no_listen?() :: boolean()
@spec port_to_listen() :: non_neg_integer()

TCP port to listen to for incoming web requests.

The port can be specified by "PORT" runtime environment variable. Defaults to 8081 during mix test, and 8080 otherwise (thus one can run both iex -S mix and mix test at the same time).

@spec running_in_cloud?() :: boolean()
@spec running_on_mix_task?() :: boolean()
@spec running_with_release?() :: boolean()
@spec runtime_env() :: t()
@spec valid?(any()) :: boolean()