diff --git a/Dockerfile b/Dockerfile index 1c27914..c09a66b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,35 +25,34 @@ RUN mix do deps.get, deps.compile ENV NODE_ENV=production # Use Node.js to install assets -FROM node:20 AS node-build +FROM node:14 AS node-build WORKDIR /app/assets -COPY assets . -RUN npm install -g pnpm -RUN pnpm install +COPY assets/package.json assets/package-lock.json ./ +RUN npm install +COPY assets/ ./ +RUN npm run deploy # Switch back to our Elixir image to continue building FROM build AS app-build WORKDIR /app +COPY --from=node-build /app/assets/build ./priv/static RUN mix phx.digest # Copy our application source code -COPY --from=node-build /app/assets assets COPY lib lib COPY priv priv # Compile and build the application -RUN mix do compile, phx.digest, assets.deploy, ecto.create, ecto.migrate +RUN mix do compile, phx.digest # Create the release -RUN mix phx.gen.release - RUN mix release # ---- Application Stage ---- -FROM elixir:1.15.6-slim AS app +FROM debian:buster-slim AS app # Install runtime dependencies -RUN apt-get update && apt-get install -y openssl libssl-dev libsqlite3-0 && apt-get clean +RUN apt-get update && apt-get install -y openssl libsqlite3-0 && apt-get clean # Create and switch to the app user RUN useradd --create-home app @@ -61,9 +60,8 @@ USER app WORKDIR /home/app # Copy over the build artifact from the previous step and create a symlink -COPY --from=app-build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./ -COPY --from=app-build --chown=app:app /app/_build/prod/lib/ezcontainer_railway/priv/static priv/static -COPY --from=app-build --chown=app:app /app/db ./db +COPY --from=build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./ +RUN ln -s /home/app/ezcontainer_railway/bin/my_app /home/app/bin # Specify the entry point -ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"] +ENTRYPOINT ["bin/my_app", "start"] diff --git a/config/dev.exs b/config/dev.exs index 82ac323..91a6e89 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -10,11 +10,10 @@ config :ezcontainer_railway, EzcontainerRailway.Repo, # The watchers configuration can be used to run external # watchers to your application. For example, we can use it # to bundle .js and .css sources. -port = String.to_integer(System.get_env("PORT") || "4000") config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {0, 0, 0, 0}, port: port], + http: [ip: {127, 0, 0, 1}, port: 4000], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/config/runtime.exs b/config/runtime.exs index 64df67c..a74032d 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -16,13 +16,25 @@ import Config # # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` # script that automatically sets the env var above. -config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint, server: true +if System.get_env("PHX_SERVER") do + config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint, server: true +end if config_env() == :prod do + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] config :ezcontainer_railway, EzcontainerRailway.Repo, - database: "./db/db_prod.sqlite3" + # ssl: true, + url: database_url, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + socket_options: maybe_ipv6 # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you @@ -30,7 +42,11 @@ if config_env() == :prod do # to check this value into version control, so we use an environment # variable instead. secret_key_base = - System.get_env("SECRET_KEY_BASE") || "secret shhh" + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ host = System.get_env("PHX_HOST") || "example.com" port = String.to_integer(System.get_env("PORT") || "4000") diff --git a/lib/ezcontainer_railway/graphql_client.ex b/lib/ezcontainer_railway/graphql_client.ex index 3062c20..865cb4f 100644 --- a/lib/ezcontainer_railway/graphql_client.ex +++ b/lib/ezcontainer_railway/graphql_client.ex @@ -1,5 +1,6 @@ defmodule EzcontainerRailway.GraphqlClient do @graphql_url "https://backboard.railway.app/graphql/v2" + @token "98237cc5-d503-4514-bb59-984d3403afe6" def query(query, opts) when is_binary(query) and is_list(opts) do body = %{