neiam
/final_track
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Dockerfile: retry apt, hex/rebar, deps.get and assets downloads (flaky GitHub runner network, as angler)
950dedf · gmorell · 2026-11-19 05:01
Files changed
modified
Dockerfile
+29
−9
@@ -22,27 +22,40 @@ ARG DEBIAN_VERSION=bookworm-20261027-slim
| 22 | 22 | ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" |
| 23 | 23 | ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" |
| 24 | 24 | |
| 25 | −FROM ${BUILDER_IMAGE} as builder | |
| 25 | +FROM ${BUILDER_IMAGE} AS builder | |
| 26 | 26 | |
| 27 | 27 | # install build dependencies. No Node: tailwind + esbuild are installed via |
| 28 | 28 | # mix. git: heroicons, daisyUI and neiam_auth are git deps. |
| 29 | −RUN apt-get update -y \ | |
| 30 | − && apt-get install -y build-essential git ca-certificates \ | |
| 29 | +# | |
| 30 | +# Every network step below is retried with backoff (as angler's): the | |
| 31 | +# GitHub runners' routes to the Debian mirrors and to hex.pm are flaky — | |
| 32 | +# one run failed `apt-get update` (exit 100), the next timed out fetching | |
| 33 | +# rebar3 from builds.hex.pm right after installing hex from the same host. | |
| 34 | +RUN n=0; until apt-get update -y -o Acquire::Retries=3 \ | |
| 35 | + && apt-get install -y -o Acquire::Retries=3 build-essential git ca-certificates; do \ | |
| 36 | + n=$((n + 1)); [ "$n" -ge 5 ] && exit 1; \ | |
| 37 | + echo "apt failed; retry $n/4 in $((n * 10))s"; sleep $((n * 10)); \ | |
| 38 | + done \ | |
| 31 | 39 | && apt-get clean && rm -f /var/lib/apt/lists/*_* |
| 32 | 40 | |
| 33 | 41 | # prepare build dir |
| 34 | 42 | WORKDIR /app |
| 35 | 43 | |
| 36 | 44 | # install hex + rebar |
| 37 | −RUN mix local.hex --force && \ | |
| 38 | − mix local.rebar --force | |
| 45 | +RUN n=0; until mix local.hex --force && mix local.rebar --force; do \ | |
| 46 | + n=$((n + 1)); [ "$n" -ge 5 ] && exit 1; \ | |
| 47 | + echo "hex/rebar install failed; retry $n/4 in $((n * 10))s"; sleep $((n * 10)); \ | |
| 48 | + done | |
| 39 | 49 | |
| 40 | 50 | # set build ENV |
| 41 | 51 | ENV MIX_ENV="prod" |
| 42 | 52 | |
| 43 | 53 | # install mix dependencies |
| 44 | 54 | COPY mix.exs mix.lock ./ |
| 45 | −RUN mix deps.get --only $MIX_ENV | |
| 55 | +RUN n=0; until mix deps.get --only $MIX_ENV; do \ | |
| 56 | + n=$((n + 1)); [ "$n" -ge 5 ] && exit 1; \ | |
| 57 | + echo "deps.get failed; retry $n/4 in $((n * 10))s"; sleep $((n * 10)); \ | |
| 58 | + done | |
| 46 | 59 | RUN mkdir config |
| 47 | 60 | |
| 48 | 61 | # copy compile-time config files before we compile dependencies |
@@ -61,7 +74,11 @@ COPY assets assets
| 61 | 74 | # imported from js/app.js) exist on disk by the time esbuild runs. |
| 62 | 75 | RUN mix compile |
| 63 | 76 | |
| 64 | −RUN mix assets.deploy | |
| 77 | +# Downloads the tailwind and esbuild binaries on first run: retried too. | |
| 78 | +RUN n=0; until mix assets.deploy; do \ | |
| 79 | + n=$((n + 1)); [ "$n" -ge 5 ] && exit 1; \ | |
| 80 | + echo "assets.deploy failed; retry $n/4 in $((n * 10))s"; sleep $((n * 10)); \ | |
| 81 | + done | |
| 65 | 82 | |
| 66 | 83 | # Changes to config/runtime.exs don't require recompiling the code |
| 67 | 84 | COPY config/runtime.exs config/ |
@@ -78,8 +95,11 @@ RUN mix release
| 78 | 95 | # the compiled release and other runtime necessities |
| 79 | 96 | FROM ${RUNNER_IMAGE} |
| 80 | 97 | |
| 81 | −RUN apt-get update -y && \ | |
| 82 | − apt-get install -y libstdc++6 openssl libncurses6 locales ca-certificates tini \ | |
| 98 | +RUN n=0; until apt-get update -y -o Acquire::Retries=3 \ | |
| 99 | + && apt-get install -y -o Acquire::Retries=3 libstdc++6 openssl libncurses6 locales ca-certificates tini; do \ | |
| 100 | + n=$((n + 1)); [ "$n" -ge 5 ] && exit 1; \ | |
| 101 | + echo "apt failed; retry $n/4 in $((n * 10))s"; sleep $((n * 10)); \ | |
| 102 | + done \ | |
| 83 | 103 | && apt-get clean && rm -f /var/lib/apt/lists/*_* |
| 84 | 104 | |
| 85 | 105 | # Set the locale |
Parents: 5051b6e