Skip to content

Commit

Permalink
Fix dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
simmsb committed Oct 10, 2023
1 parent 8b179e2 commit 408c26e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 60 deletions.
85 changes: 27 additions & 58 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,28 @@
ARG ELIXIR_VERSION=1.14.0
ARG OTP_VERSION=25.1
ARG DEBIAN_VERSION=bullseye-20220801-slim
ARG ELIXIR_VERSION=1.15.6
ARG OTP_VERSION=26.1
ARG DEBIAN_VERSION=bookworm-20230612-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM rust:1.73.0 as rust
# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

WORKDIR /app
COPY native/matrix ./
RUN cargo rustc --release

FROM ${BUILDER_IMAGE} as builder

RUN apt-get update -y && apt-get install -y --no-install-recommends build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*


# install rust (this is from rust:buster-slim)

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.64.0

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
libc6-dev \
wget \
; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='5cc9ffd1026e82e7fb2eec2121ad71f4b0f044e88bca39207b3f6b769aaa799c' ;; \
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='48c5ecfd1409da93164af20cf4ac2c6f00688b15eb6ba65047f654060c844d85' ;; \
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='e189948e396d47254103a49c987e7fb0e5dd8e34b200aa4481ecc4b8e41fb929' ;; \
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='0e0be29c560ad958ba52fcf06b3ea04435cb3cd674fbe11ce7d954093b9504fd' ;; \
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
esac; \
url="https://static.rust-lang.org/rustup/archive/1.25.1/${rustArch}/rustup-init"; \
wget "$url"; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version; \
apt-get remove -y --auto-remove \
wget \
; \
rm -rf /var/lib/apt/lists/*;


# install node
# https://github.com/nodejs/docker-node/blob/230b9852645e170167a2aac1cfa246d069c23cc3/20/bookworm-slim/Dockerfile

ENV NODE_VERSION 18.10.0
ENV NODE_VERSION 20.8.0

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& case "${dpkgArch##*-}" in \
Expand All @@ -71,18 +41,15 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
61FC681DFB92A079F1685E77973F295594EC4689 \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
B9E2F5981AA6E0CD28160D9FF13993A75599653C \
A363A499291CBBC940DD62E41F10027AF002F8B0 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
Expand All @@ -95,7 +62,7 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
&& apt-mark auto '.*' > /dev/null \
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
Expand Down Expand Up @@ -130,7 +97,7 @@ RUN set -ex \
&& apt-mark auto '.*' > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
Expand All @@ -140,7 +107,6 @@ RUN set -ex \
# smoke test
&& yarn --version


# The version of the application we are building (required)
ARG APP_VSN
# The environment to build with
Expand All @@ -163,7 +129,7 @@ WORKDIR /opt/app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
python \
python3 \
build-essential \
&& \
mix local.rebar --force && \
Expand All @@ -176,17 +142,20 @@ RUN apt-get update; \
&& update-ca-certificates

# This copies our app source code into the build container
COPY mix.exs mix.lock .

COPY --from=rust /app/target/release/libmatrix.so priv/native/libmatrix.so
RUN mix do deps.get, deps.compile

COPY assets/ assets/
COPY config/ config/
COPY lib/ lib/
COPY native/ native/
COPY rel/ rel/
COPY mix.exs mix.lock .

RUN mix do deps.get, deps.compile, compile

COPY lib/ lib/
COPY priv/ priv/

RUN mix compile

# This step builds assets for the Phoenix app (if there is one)
# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true`
# This is mostly here for demonstration purposes
Expand Down
5 changes: 5 additions & 0 deletions web/config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ config :infolab_light_games, InfolabLightGamesWeb.Endpoint,
# Do not print debug messages in production
config :logger, level: :info

config :infolab_light_games, NativeMatrix.NifBridge,
crate: :matrix,
skip_compilation?: true,
load_from: {:infolab_light_games, "priv/native/libmatrix"}

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
Expand Down
6 changes: 5 additions & 1 deletion web/lib/infolab_light_games/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule InfolabLightGames.Application do
# for more information on OTP Applications
@moduledoc false

require Logger

use Application

def start(_type, _args) do
Expand All @@ -29,14 +31,16 @@ defmodule InfolabLightGames.Application do
],
else: []

Logger.info("Starting up lights, is phoenix running? #{in_phoenix?()}")

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: InfolabLightGames.Supervisor]
Supervisor.start_link(children, opts)
end

defp in_phoenix?() do
Application.get_env(:phoenix, :serve_endpoints)
Phoenix.Endpoint.server?(:infolab_light_games, InfolabLightGamesWeb.Endpoint)
end

# Tell Phoenix to update the endpoint configuration
Expand Down
2 changes: 1 addition & 1 deletion web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule InfolabLightGames.MixProject do
{:typed_struct, "~> 0.3"},
{:qex, "~> 0.5"},
{:ok, "~> 2.3"},
{:rustler, "~> 0.27"},
{:rustler, "~> 0.29"},
{:remote_ip, "~> 1.0"},
{:tint, "~> 1.1"},
{:temp, "~> 0.4"},
Expand Down

0 comments on commit 408c26e

Please sign in to comment.