Skip to content

Commit

Permalink
improvement: config and .iex.exs copy in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jul 10, 2024
1 parent 27b2e7e commit c29b13a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ COPY config/runtime.exs config/

COPY rel rel
RUN mix release
# iex helpers
COPY .iex.exs _build/${MIX_ENV}/rel/hello_api

###########################################################

Expand Down Expand Up @@ -94,6 +92,9 @@ COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/hello_api ./

USER nobody

# carry iex helpers to /app
COPY .iex.exs .

# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
Expand Down
8 changes: 4 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Config
config :hello_api,
build_mode: config_env(),
build_time: DateTime.utc_now(),
source_url: Mix.Project.config()[:source_url],
commit_id: System.get_env("GIT_COMMIT_ID", ""),
commit_time: System.get_env("GIT_COMMIT_TIME", ""),
source_url: Mix.Project.config()[:source_url]
commit_time: System.get_env("GIT_COMMIT_TIME", "")

if config_env() in [:dev] do
import_config("#{config_env()}.exs")
if config_env() == :dev do
import_config("git_ops.exs")
end
File renamed without changes.
29 changes: 21 additions & 8 deletions lib/hello_api.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
defmodule HelloApi do
@app :hello_api
# @app :hello_api
# def app, do: @app
def app, do: Application.get_application(__MODULE__)

def vsn, do: Application.spec(app(), :vsn) |> to_string()
def source_url, do: Application.get_env(app(), :source_url)
def build_mode, do: Application.get_env(app(), :build_mode)
def build_time, do: Application.get_env(app(), :build_time) |> to_string

def build_info do
%{
app: app(),
version: vsn(),
build_mode: Application.get_env(@app, :build_mode),
build_time: Application.get_env(@app, :build_time) |> to_string,
source_url: Application.get_env(@app, :source_url),
commit_id: Application.get_env(@app, :commit_id, "") |> String.trim(),
commit_time: Application.get_env(@app, :commit_time, "") |> parse_commit_time,
system: System.build_info()
source_url: source_url(),
build_mode: build_mode(),
build_time: build_time(),
system: System.build_info(),
commit: commit()
}
end

def vsn, do: Application.spec(@app, :vsn) |> to_string()
# put into standalone hex pkg?
def commit do
%{
commit_id: Application.get_env(app(), :commit_id, "") |> String.trim(),
commit_time: Application.get_env(app(), :commit_time, "") |> parse_commit_time
}
end

def parse_commit_time(""), do: nil

Expand Down

0 comments on commit c29b13a

Please sign in to comment.