Skip to content

Commit efc201d

Browse files
committed
fix dockerfile
1 parent 87dcbec commit efc201d

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

Dockerfile

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,55 @@ FROM elixir:1.18.3-otp-27-slim AS base
22

33
WORKDIR /code_comparison
44

5-
# Install system dependencies first!
65
RUN apt-get update && \
7-
apt-get install -y npm inotify-tools ca-certificates && \
6+
apt-get install -y npm inotify-tools ca-certificates curl bash git && \
87
apt-get clean && \
98
rm -rf /var/lib/apt/lists/*
109

11-
# Now it's safe to run mix commands
1210
RUN mix do local.hex --force, local.rebar --force
1311

14-
# Copy the entire application
15-
COPY . .
12+
# -----------------
13+
# BUILD
14+
# -----------------
15+
FROM base AS build
1616

17-
# Install Elixir dependencies
18-
RUN mix deps.get
17+
ARG MIX_ENV=prod
18+
ARG SECRET_KEY_BASE=dummy_secret
19+
ENV MIX_ENV=$MIX_ENV
20+
ENV SECRET_KEY_BASE=$SECRET_KEY_BASE
1921

20-
# Install npm dependencies
21-
RUN cd assets && npm install
22+
COPY . ./
23+
24+
# install application
25+
RUN mix do deps.get, compile
26+
27+
# -----------------
28+
# RELEASE
29+
# -----------------
30+
FROM build AS release
31+
32+
# Build static assets and digest them
33+
RUN npm install --prefix assets && npm run deploy --prefix assets && mix phx.digest
34+
35+
# generate release executable
36+
RUN mix release
37+
38+
# -----------------
39+
# PRODUCTION
40+
# -----------------
41+
FROM elixir:1.18.3-otp-27-slim AS production
42+
43+
WORKDIR /code_comparison
44+
45+
ARG MIX_ENV=prod
46+
47+
# install dependencies
48+
RUN apt-get update && \
49+
apt-get install -y ncurses-bin curl && \
50+
apt-get clean && \
51+
rm -rf /var/lib/apt/lists/*
52+
53+
COPY --from=release /code_comparison/_build/$MIX_ENV/rel/code_comparison ./
54+
COPY --from=build /code_comparison/topics ./topics
55+
56+
CMD ["bin/code_comparison", "start"]

config/prod.exs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@ use Mix.Config
1010
# which you should run after static files are built and
1111
# before starting your production server.
1212
config :code_comparison, CodeComparisonWeb.Endpoint,
13-
url: [host: "codecomparison.me", port: 80],
14-
cache_static_manifest: "priv/static/cache_manifest.json",
15-
check_origin: [
16-
"//codecomparison.me",
17-
"//www.codecomparison.me",
18-
"//dreary-sore-eland.gigalixirapp.com"
19-
],
20-
force_ssl: [rewrite_on: [:x_forwarded_proto]]
13+
server: true,
14+
cache_static_manifest: "priv/static/cache_manifest.json"
2115

2216
# Do not print debug messages in production
2317
config :logger, level: :info

config/prod.secret.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ secret_key_base =
1212
"""
1313

1414
config :code_comparison, CodeComparisonWeb.Endpoint,
15+
url: [host: System.get_env("RENDER_EXTERNAL_HOSTNAME") || "localhost", port: 80],
1516
http: [
17+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
1618
port: String.to_integer(System.get_env("PORT") || "4000"),
1719
transport_options: [socket_opts: [:inet6]]
1820
],
19-
secret_key_base: secret_key_base
21+
secret_key_base: secret_key_base,
22+
check_origin: [
23+
"//code-comparison.onrender.com",
24+
"https://code-comparison.onrender.com"
25+
]
2026

2127
# ## Using releases (Elixir v1.9+)
2228
#
2329
# If you are doing OTP releases, you need to instruct Phoenix
2430
# to start each relevant endpoint:
2531
#
26-
# config :code_comparison, CodeComparisonWeb.Endpoint, server: true
32+
config :code_comparison, CodeComparisonWeb.Endpoint, server: true
2733
#
2834
# Then you can assemble a release by calling `mix release`.
2935
# See `mix help release` for more information.

lib/code_comparison/languages.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule CodeComparison.Languages do
99
defp base_topics_path, do: Path.expand("topics", File.cwd!())
1010

1111
@spec get_languages_by_topic(String.t()) :: list(%Language{})
12+
def get_languages_by_topic(nil), do: []
1213
def get_languages_by_topic(topic) do
1314
topic_dir = Path.join(base_topics_path(), topic)
1415

0 commit comments

Comments
 (0)