Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
erl_crash.dump

# Static artifacts - These should be fetched and built inside the Docker image
# https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Release.html#module-docker
/assets/node_modules/
/priv/static/assets/
/priv/static/cache_manifest.json
Expand All @@ -49,6 +50,3 @@ erl_crash.dump

*prod.yaml
*prod.yml

mosquitto/
cubdb/
2 changes: 1 addition & 1 deletion .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ docker-compose.prod.yml
# Certs for local testing, can be regenerated with `mix phx.gen.cert`
/priv/cert

cubdb/
.DS_Store
59 changes: 32 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
# https://hub.docker.com/r/hexpm/elixir/tags?name=ubuntu
# https://hub.docker.com/_/ubuntu/tags
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bookworm-20250203-slim - for the release image
# - https://hub.docker.com/_/debian/tags?name=trixie-20260202-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.18.2-erlang-27.2.2-debian-bookworm-20250203-slim
# - Ex: docker.io/hexpm/elixir:1.19.3-erlang-28.3-debian-trixie-20260202-slim
#
ARG ELIXIR_VERSION=1.18.2
ARG OTP_VERSION=27.2.2
ARG DEBIAN_VERSION=bookworm-20250203-slim
ARG ELIXIR_VERSION=1.19.3
ARG OTP_VERSION=28.3
ARG DEBIAN_VERSION=trixie-20260202-slim

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

FROM ${BUILDER_IMAGE} as builder
FROM ${BUILDER_IMAGE} AS builder

# Fix JIT issues under QEMU
ENV ERL_FLAGS="+JMsingle true"

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

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
RUN mix local.hex --force \
&& mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"
Expand All @@ -48,18 +49,20 @@ RUN mkdir config
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

RUN mix assets.setup

COPY priv priv

COPY lib lib

# Compile the release
RUN mix compile

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

Expand All @@ -68,18 +71,19 @@ RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
FROM ${RUNNER_IMAGE} AS final

RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update \
&& apt-get install -y --no-install-recommends libstdc++6 openssl libncurses6 locales ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
&& locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app
Expand All @@ -89,7 +93,6 @@ ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/dash ./

COPY --chown=nobody:root entrypoint.sh /app/bin/entrypoint.sh

USER nobody
Expand All @@ -98,7 +101,9 @@ USER nobody
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]

# Default:
# CMD ["/app/bin/server"]
# Entrypoint for running migrations before starting the server
# Entrypoint for running migrations before starting the server.
# In current implementation we don't even have any migrations, but I like to keep the script.
ENTRYPOINT [ "/app/bin/entrypoint.sh" ]
5 changes: 0 additions & 5 deletions lib/dash_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ defmodule DashWeb.Router do
scope "/", DashWeb do
pipe_through :browser

# get "/", HomeController, :home
# post "/timer", HomeController, :timer
# post "/security_state", HomeController, :security_state

live "/", HomeLive, :index
live "/timer/:id", TimerLive, :timer_live
live "/security", SecurityLive, :security_live
end

# Other scopes may use custom stacks.
Expand Down
30 changes: 15 additions & 15 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ defmodule Dash.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.7.19"},
{:phoenix_html, "~> 4.2"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 1.0.4", override: true},
{:floki, ">= 0.37.0", only: :test},
{:phoenix_live_dashboard, "~> 0.8.6"},
{:esbuild, "~> 0.9", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
{:phoenix, "~> 1.8"},
{:phoenix_html, "~> 4.3"},
{:phoenix_live_reload, "~> 1.6", only: :dev},
{:phoenix_live_view, "~> 1.1", override: true},
{:floki, "~> 0.38", only: :test},
{:phoenix_live_dashboard, "~> 0.8"},
{:esbuild, "~> 0.10", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.4", runtime: Mix.env() == :dev},
{:heroicons,
github: "tailwindlabs/heroicons",
tag: "v2.2.0",
sparse: "optimized",
app: false,
compile: false,
depth: 1},
{:swoosh, "~> 1.17.9"},
{:finch, "~> 0.19"},
{:swoosh, "~> 1.21"},
{:finch, "~> 0.21"},
{:telemetry_metrics, "~> 1.1"},
{:telemetry_poller, "~> 1.1"},
{:gettext, "~> 0.26"},
{:telemetry_poller, "~> 1.3"},
{:gettext, "~> 1.0"},
{:jason, "~> 1.4"},
{:dns_cluster, "~> 0.1.3"},
{:bandit, "~> 1.6"},
{:dns_cluster, "~> 0.2"},
{:bandit, "~> 1.10"},
{:sqids, "~> 0.2.0"},
# linters
{:sobelow, "~> 0.13", only: [:dev, :test], runtime: false},
{:sobelow, "~> 0.14", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end
Expand Down
Loading