From: Alexander Goussas Date: Tue, 3 Feb 2026 02:38:33 +0000 (-0500) Subject: feat: configure docker deployment X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=4fe498c3e8bc36ddc886beda11e655decf3f7c4f;p=dns-phrasex.git feat: configure docker deployment --- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb7f2ae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM elixir:1.17.3 + +ENV MIX_ENV=prod +ENV APP_VERSION="0.1.0" + +RUN mix local.hex --force && \ + mix local.rebar --force && \ + mkdir /build + +WORKDIR /build +COPY ./mix.exs /build +COPY ./mix.lock /build +COPY ./config/runtime.exs /build/config/runtime.exs +RUN mix do deps.get, deps.compile + +COPY . /build +RUN mix release + +ENV PORT=53 +ENV PGHOST PGUSER PGPASSWORD PGDATABASE + +WORKDIR /app + +CMD /build/_build/prod/rel/dns_phrases/bin/dns_phrases start diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 0000000..76f71ca --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,8 @@ +import Config + +config :dns_phrasex, + port: + (case System.fetch_env!("PORT") |> Integer.parse() do + {port, _} -> port + :error -> 53 + end) diff --git a/docker-compose.yml b/docker-compose.yml index 31770c5..1102eab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,19 @@ services: + app: + image: aloussase69/dns-phrasex + restart: unless-stopped + build: + context: . + ports: + - "5353:53/udp" + environment: + PGHOST: db + PGDATABASE: postgres + PGUSER: postgres + PGPASSWORD: postgres + depends_on: + - db + db: image: postgres:17 restart: unless-stopped diff --git a/lib/dns_phrases/application.ex b/lib/dns_phrases/application.ex index 5b0c4ee..98293c6 100644 --- a/lib/dns_phrases/application.ex +++ b/lib/dns_phrases/application.ex @@ -7,12 +7,11 @@ defmodule DnsPhrases.Application do @impl true def start(_type, _args) do - opts = [port: :integer] - {parsed, _, _} = OptionParser.parse(System.argv(), strict: opts) + port = Application.fetch_env!(:dns_phrasex, :port) children = [ {Postgrex, [name: :db]}, - {DnsPhrases.Server, [listen_port: parsed[:port]]} + {DnsPhrases.Server, [listen_port: port]} ] opts = [strategy: :one_for_one, name: DnsPhrases.Supervisor]