Skip to content

Commit 720cfcd

Browse files
committed
Update OTP and elixir and use debian image
1 parent a97b101 commit 720cfcd

File tree

5 files changed

+96
-79
lines changed

5 files changed

+96
-79
lines changed

Dockerfile

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,85 @@
11
ARG ELIXIR_VERSION=1.17.2
22
ARG OTP_VERSION=27.0.1
3-
# ARG DEBIAN_VERSION=bookworm-20240701-slim
4-
ARG ALPINE_VERSION=3.18.7
3+
ARG DEBIAN_VERSION=bookworm-20240701-slim
54

6-
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine-${ALPINE_VERSION}"
7-
# ARG RUNNER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine-${ALPINE_VERSION}"
8-
ARG RUNNER_IMAGE="alpine:${ALPINE_VERSION}"
5+
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
6+
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
97

10-
11-
###
12-
### Fist Stage - Building the Release
13-
###
14-
FROM ${BUILDER_IMAGE} AS build
8+
FROM ${BUILDER_IMAGE} as builder
159

1610
# install build dependencies
17-
# git needed for getting ueberauth_steam
18-
RUN apk add --no-cache build-base git
11+
RUN apt-get update -y && apt-get install -y build-essential git \
12+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
1913

2014
# prepare build dir
2115
WORKDIR /app
2216

23-
# extend hex timeout
24-
ENV HEX_HTTP_TIMEOUT=20
25-
2617
# install hex + rebar
2718
RUN mix local.hex --force && \
2819
mix local.rebar --force
2920

30-
# set build ENV as prod
31-
ENV MIX_ENV=prod
32-
ENV SECRET_KEY_BASE=nokey
33-
ENV DATABASE_URL=$DATABASE_URL
21+
# set build ENV
22+
ENV MIX_ENV="prod"
3423

35-
# Copy over the mix.exs and mix.lock files to load the dependencies. If those
36-
# files don't change, then we don't keep re-fetching and rebuilding the deps.
24+
# install mix dependencies
3725
COPY mix.exs mix.lock ./
38-
COPY config config
26+
RUN mix deps.get --only $MIX_ENV
27+
RUN mkdir config
3928

40-
RUN mix deps.get --only prod && \
41-
mix deps.compile
29+
# copy compile-time config files before we compile dependencies
30+
# to ensure any relevant config change will trigger the dependencies
31+
# to be re-compiled.
32+
COPY config/config.exs config/${MIX_ENV}.exs config/
33+
RUN mix deps.compile
4234

4335
COPY priv priv
44-
COPY assets assets
4536

46-
# NOTE: If using TailwindCSS, it uses a special "purge" step and that requires
47-
# the code in `lib` to see what is being used. Uncomment that here before
48-
# running the npm deploy script if that's the case.
4937
COPY lib lib
5038

51-
# build assets
39+
COPY assets assets
40+
41+
# compile assets
5242
RUN mix assets.deploy
53-
RUN mix phx.digest
5443

55-
# copy source here if not using TailwindCSS
56-
COPY lib lib
44+
# Compile the release
45+
RUN mix compile
46+
47+
# Changes to config/runtime.exs don't require recompiling the code
48+
COPY config/runtime.exs config/
5749

58-
# compile and build release
5950
COPY rel rel
60-
RUN mix do compile, release
51+
RUN mix release
6152

62-
###
63-
### Second Stage - Setup the Runtime Environment
64-
###
53+
# start a new build stage so that the final image will only contain
54+
# the compiled release and other runtime necessities
55+
FROM ${RUNNER_IMAGE}
6556

66-
# prepare release docker image
67-
FROM ${RUNNER_IMAGE} AS app
68-
RUN apk add --no-cache libstdc++ openssl ncurses-libs
57+
RUN apt-get update -y && \
58+
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
59+
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
6960

70-
WORKDIR /app
61+
# Set the locale
62+
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
63+
64+
ENV LANG en_US.UTF-8
65+
ENV LANGUAGE en_US:en
66+
ENV LC_ALL en_US.UTF-8
67+
68+
WORKDIR "/app"
69+
RUN chown nobody /app
70+
71+
# set runner ENV
72+
ENV MIX_ENV="prod"
7173

72-
RUN chown nobody:nobody /app
74+
# Only copy the final release from the build stage
75+
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/get5_api ./
7376

74-
USER nobody:nobody
77+
USER nobody
7578

76-
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/get5_api ./
79+
# If using an environment that doesn't automatically reap zombie processes, it is
80+
# advised to add an init process such as tini via `apt-get install`
81+
# above and adding an entrypoint. See https://github.com/krallin/tini for details
82+
# ENTRYPOINT ["/tini", "--"]
7783

78-
ENV HOME=/app
79-
ENV MIX_ENV=prod
80-
ENV SECRET_KEY_BASE=nokey
81-
ENV PORT=4000
84+
CMD ["/app/bin/server"]
8285

83-
CMD ["bin/get5_api", "start"]

Dockerfile-dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM elixir:1.15.7
1+
FROM elixir:1.17.2
22

33
RUN apt-get update && \
44
apt-get install -y postgresql-client

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ in alignment with the projects plans. 😄
9494

9595
### All in docker
9696

97+
**NB: This section is outdated. Need to find a docker image for CS2. Any tips?**
98+
9799
Run both app and database (and csgo server) in docker.
98100

99101
1. Start the database and server with `docker-compose up`. This might take a while.
@@ -104,7 +106,7 @@ Enjoy some quiet time while downloading and compiling. 😄
104106

105107
If you also wish to run a CSGO server configured with Get5 you can uncomment
106108
the csgo service in `docker-compose.yml`. ***Note:** this image does not work on
107-
M1/Apple Silicon and the server needs to be serves somewhere else.*
109+
M1/Apple Silicon and the server needs to be served somewhere else.*
108110
Check out the repo for that image on more information about how it works: https://github.com/ringvold/csgo
109111

110112

@@ -145,12 +147,12 @@ source ~/.zshrc
145147
asdf plugin-add erlang
146148
asdf plugin-add elixir
147149
148-
asdf install elixir 1.14.2-otp-25
149-
asdf install erlang 25.1.2
150+
# install the versions specified in .tool-versions
151+
asdf install
150152
151-
# Set the installed versions av default
152-
asdf global erlang 25.1.2
153-
asdf global elixir 1.14.2-otp-25
153+
# Set the installed versions av default if you wish
154+
asdf global erlang erlang 27.0.1
155+
asdf global elixir elixir 1.17.2-otp-27
154156
155157
mix local.hex
156158
mix local.rebar

lib/get5_api_web/live/match_live/show.ex

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,79 @@ defmodule Get5ApiWeb.MatchLive.Show do
2424
match = socket.assigns.entity || Matches.get_match!(id)
2525
map_stats = Stats.get_by_match(id)
2626
player_stats = Stats.player_stats_by_match(id)
27+
game_server = socket.assigns.entity.game_server
2728

2829
{:noreply,
2930
socket
3031
|> assign(:page_title, page_title(socket.assigns.live_action))
3132
|> assign(:match, match)
3233
|> assign(:map_stats, map_stats)
3334
|> assign(:player_stats, player_stats)
34-
|> start_async(:get_status, fn -> Get5Client.status(socket.assigns.entity.game_server) end)}
35+
|> start_async(:get_status, fn -> Get5Client.status(game_server) end)}
3536
end
3637

3738
@impl true
3839
def handle_event("get_status", _params, socket) do
40+
game_server = socket.assigns.match.game_server
41+
3942
{:noreply,
4043
socket
4144
|> assign(status: AsyncResult.loading())
42-
|> start_async(:get_status, fn -> Get5Client.status(socket.assigns.match.game_server) end)}
45+
|> start_async(:get_status, fn -> Get5Client.status(game_server) end)}
4346
end
4447

4548
@impl true
4649
def handle_event("start_match", _params, socket) do
4750
if socket.assigns.match.user_id == socket.assigns.current_user.id do
51+
match = socket.assigns.match
52+
4853
{:noreply,
4954
socket
50-
|> start_async(:start_match, fn -> Get5Client.start_match(socket.assigns.match) end)}
55+
|> start_async(:start_match, fn -> Get5Client.start_match(match) end)}
5156
else
5257
{:noreply,
5358
socket
5459
|> put_flash(:error, gettext("You are not allowed to start this match"))}
5560
end
5661
end
5762

63+
@impl true
64+
def handle_event("end_match", _params, socket) do
65+
if socket.assigns.match.user_id == socket.assigns.current_user.id do
66+
match = socket.assigns.match
67+
68+
{:noreply,
69+
socket
70+
|> start_async(:end_match, fn -> Get5Client.end_match(match) end)}
71+
else
72+
{:noreply,
73+
socket
74+
|> put_flash(:error, gettext("You are not allowed to end this match"))}
75+
end
76+
end
77+
5878
@impl true
5979
def handle_async(:start_match, {:ok, {:ok, _resp}}, socket) do
80+
game_server = socket.assigns.match.game_server
81+
6082
{:noreply,
6183
socket
6284
|> start_async(:get_status, fn ->
63-
Get5Client.status(socket.assigns.match.game_server)
85+
Get5Client.status(game_server)
6486
end)
6587
|> put_flash(:info, gettext("Match sendt to server"))}
6688
end
6789

6890
@impl true
6991
def handle_async(:start_match, {:ok, {:error, error}}, socket) do
92+
game_server = socket.assigns.match.game_server
93+
7094
case error do
7195
:nxdomain ->
7296
{:noreply,
7397
socket
7498
|> start_async(:get_status, fn ->
75-
Get5Client.status(socket.assigns.match.game_server)
99+
Get5Client.status(game_server)
76100
end)
77101
|> put_flash(
78102
:error,
@@ -85,42 +109,31 @@ defmodule Get5ApiWeb.MatchLive.Show do
85109
{:noreply,
86110
socket
87111
|> start_async(:get_status, fn ->
88-
Get5Client.status(socket.assigns.match.game_server)
112+
Get5Client.status(game_server)
89113
end)
90114
|> put_flash(
91115
:error,
92116
gettext("A match is already loaded on the server")
93117
)}
94118

95-
err ->
119+
_err ->
96120
{:noreply,
97121
socket
98122
|> start_async(:get_status, fn ->
99-
Get5Client.status(socket.assigns.match.game_server)
123+
Get5Client.status(game_server)
100124
end)
101125
|> put_flash(:error, gettext("Failed to start match"))}
102126
end
103127
end
104128

105129
@impl true
106-
def handle_event("end_match", _params, socket) do
107-
if socket.assigns.match.user_id == socket.assigns.current_user.id do
108-
{:noreply,
109-
socket
110-
|> start_async(:end_match, fn -> Get5Client.end_match(socket.assigns.match) end)}
111-
else
112-
{:noreply,
113-
socket
114-
|> put_flash(:error, gettext("You are not allowed to end this match"))}
115-
end
116-
end
130+
def handle_async(:end_match, {:ok, {:ok, _msg}}, socket) do
131+
game_server = socket.assigns.match.game_server
117132

118-
@impl true
119-
def handle_async(:end_match, {:ok, {:ok, msg}}, socket) do
120133
{:noreply,
121134
socket
122135
|> start_async(:get_status, fn ->
123-
Get5Client.status(socket.assigns.match.game_server)
136+
Get5Client.status(game_server)
124137
end)
125138
|> put_flash(:info, gettext("Match ended"))}
126139
end

lib/get5_api_web/live/user_login_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule Get5ApiWeb.UserLoginLive do
3636
end
3737

3838
def mount(_params, _session, socket) do
39-
email = live_flash(socket.assigns.flash, :email)
39+
email = Phoenix.Flash.get(socket.assigns.flash, :email)
4040
form = to_form(%{"email" => email}, as: "user")
4141
{:ok, assign(socket, form: form), temporary_assigns: [form: form]}
4242
end

0 commit comments

Comments
 (0)