diff --git a/Dockerfile b/Dockerfile index c09a66b..1c27914 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,34 +25,35 @@ RUN mix do deps.get, deps.compile ENV NODE_ENV=production # Use Node.js to install assets -FROM node:14 AS node-build +FROM node:20 AS node-build WORKDIR /app/assets -COPY assets/package.json assets/package-lock.json ./ -RUN npm install -COPY assets/ ./ -RUN npm run deploy +COPY assets . +RUN npm install -g pnpm +RUN pnpm install # 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 +RUN mix do compile, phx.digest, assets.deploy, ecto.create, ecto.migrate # Create the release +RUN mix phx.gen.release + RUN mix release # ---- Application Stage ---- -FROM debian:buster-slim AS app +FROM elixir:1.15.6-slim AS app # Install runtime dependencies -RUN apt-get update && apt-get install -y openssl libsqlite3-0 && apt-get clean +RUN apt-get update && apt-get install -y openssl libssl-dev libsqlite3-0 && apt-get clean # Create and switch to the app user RUN useradd --create-home app @@ -60,8 +61,9 @@ USER app WORKDIR /home/app # Copy over the build artifact from the previous step and create a symlink -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 +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 # Specify the entry point -ENTRYPOINT ["bin/my_app", "start"] +ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"] diff --git a/config/dev.exs b/config/dev.exs index 91a6e89..82ac323 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -10,10 +10,11 @@ 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: {127, 0, 0, 1}, port: 4000], + http: [ip: {0, 0, 0, 0}, port: port], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/config/runtime.exs b/config/runtime.exs index a74032d..64df67c 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -16,25 +16,13 @@ import Config # # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` # script that automatically sets the env var above. -if System.get_env("PHX_SERVER") do - config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint, server: true -end +config :ezcontainer_railway, EzcontainerRailwayWeb.Endpoint, server: true 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, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - socket_options: maybe_ipv6 + database: "./db/db_prod.sqlite3" # 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 @@ -42,11 +30,7 @@ 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") || - raise """ - environment variable SECRET_KEY_BASE is missing. - You can generate one by calling: mix phx.gen.secret - """ + System.get_env("SECRET_KEY_BASE") || "secret shhh" 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 865cb4f..3062c20 100644 --- a/lib/ezcontainer_railway/graphql_client.ex +++ b/lib/ezcontainer_railway/graphql_client.ex @@ -1,6 +1,5 @@ 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 = %{