From 657a4dfb6bb86692b6b240143f313894b0ced4da Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 02:20:17 -0400 Subject: [PATCH 01/10] Adds dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c09a66b..6517593 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ 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 +RUN ln -s /home/app/ezcontainer_railway/bin/ezcontainer_railway /home/app/bin # Specify the entry point ENTRYPOINT ["bin/my_app", "start"] From b8ecd1201e43371541e505310c2f1c21bf66f3f1 Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:30:29 -0400 Subject: [PATCH 02/10] Adds dockerfile --- Dockerfile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6517593..9f0dc56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,17 +25,16 @@ 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/package.json assets/pnpm-lock.yaml ./ +RUN npm install -g pnpm +RUN pnpm 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 @@ -60,8 +59,8 @@ 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/ezcontainer_railway /home/app/bin +COPY --from=app-build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./ +RUN ln -s /home/app/_build/prod/rel/ezcontainer_railway/bin/ezcontainer_railway /home/app/bin/app # Specify the entry point -ENTRYPOINT ["bin/my_app", "start"] +ENTRYPOINT ["bin/app", "start"] From 58dd7e4fe070d43640e0a75f6cd9c6f41fa8d9fb Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:49:10 -0400 Subject: [PATCH 03/10] Adds dockerfile --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f0dc56..fac4a40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,10 +48,10 @@ RUN mix do compile, phx.digest 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,7 +60,6 @@ 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 ./ -RUN ln -s /home/app/_build/prod/rel/ezcontainer_railway/bin/ezcontainer_railway /home/app/bin/app # Specify the entry point -ENTRYPOINT ["bin/app", "start"] +#ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"] From 8795c4d00f404ebe2b332ac118bc73dac9899e92 Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:50:06 -0400 Subject: [PATCH 04/10] fixes dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fac4a40..17e61e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,4 +62,4 @@ WORKDIR /home/app COPY --from=app-build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./ # Specify the entry point -#ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"] +ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"] From 49e5dfdc2fb68a2cc54e3fc1b36bef03b1575e65 Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:52:02 -0400 Subject: [PATCH 05/10] make phoenix happy with sqlite --- config/runtime.exs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index a74032d..80cfad6 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -21,20 +21,10 @@ if System.get_env("PHX_SERVER") do 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, - # 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 From 094ccf73b5e6f532d35f55297c72f6b9e417c222 Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:55:42 -0400 Subject: [PATCH 06/10] adds awful secret --- config/runtime.exs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 80cfad6..1852d30 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -32,11 +32,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") From a3d521b078a900b44c91adc79d867a696161690b Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 03:57:22 -0400 Subject: [PATCH 07/10] Adds magic server config --- config/runtime.exs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 1852d30..64df67c 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -16,9 +16,7 @@ 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 maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] From e8b528e5f0d05b2457b04bae91d9bd6810abca7e Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 10:07:36 -0400 Subject: [PATCH 08/10] creates database --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 17e61e8..6325cc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,8 @@ COPY assets/ ./ # Switch back to our Elixir image to continue building FROM build AS app-build WORKDIR /app +RUN mix ecto.create +RUN mix ecto.migrate RUN mix phx.digest # Copy our application source code From 5ef40852a62ef833ed554b0f33950a4c50f164eb Mon Sep 17 00:00:00 2001 From: benbot Date: Fri, 27 Oct 2023 10:14:51 -0400 Subject: [PATCH 09/10] creates database correctly --- Dockerfile | 12 +++++++----- config/dev.exs | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6325cc3..1c27914 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,26 +27,26 @@ ENV NODE_ENV=production # Use Node.js to install assets FROM node:20 AS node-build WORKDIR /app/assets -COPY assets/package.json assets/pnpm-lock.yaml ./ +COPY assets . RUN npm install -g pnpm RUN pnpm install -COPY assets/ ./ # Switch back to our Elixir image to continue building FROM build AS app-build WORKDIR /app -RUN mix ecto.create -RUN mix ecto.migrate 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 ---- @@ -62,6 +62,8 @@ 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 # Specify the entry point 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, From 3a1a329082b42496b4c218f14d0c0e6ab0bb5028 Mon Sep 17 00:00:00 2001 From: benbot Date: Mon, 8 Apr 2024 22:58:46 -0400 Subject: [PATCH 10/10] cleanup --- lib/ezcontainer_railway/graphql_client.ex | 1 - 1 file changed, 1 deletion(-) 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 = %{