From da7c015900abcd4886bdb032da58d4a8fe3afa39 Mon Sep 17 00:00:00 2001 From: Adrian Kumpf <8999358+adriankumpf@users.noreply.github.com> Date: Sun, 31 Jan 2021 16:31:13 +0100 Subject: [PATCH] Use Debian as base iamge Elixir 1.11-alpine is based on Alpine 3.13 which upgraded musl to 1.2. On ARMhf, ARMv7 or x86 platforms, musl 1.2 changed the definition of time_t to 64-bits. That seems to be incompatible with OTP. --- Dockerfile | 40 +++++++++++++++++++++++++--------------- entrypoint.sh | 16 +++++----------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index c1a0d876..0c5b3a32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ -FROM elixir:1.11.3-alpine AS builder +FROM elixir:1.11.3 AS builder -RUN apk add --update --no-cache nodejs npm git build-base && \ - mix local.rebar --force && \ +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + apt-get update && apt-get install -y --no-install-recommends nodejs + +RUN mix local.rebar --force && \ mix local.hex --force ENV MIX_ENV=prod - WORKDIR /opt/app COPY mix.exs mix.lock ./ @@ -22,35 +23,44 @@ COPY assets assets RUN npm run deploy --prefix ./assets RUN mix phx.digest -COPY config/runtime.exs config/runtime.exs COPY lib lib COPY priv/repo/migrations priv/repo/migrations COPY priv/gettext priv/gettext COPY grafana/dashboards grafana/dashboards COPY VERSION VERSION +RUN mix compile -RUN mkdir -p /opt/built && \ - mix "do" compile, release --path /opt/built +COPY config/runtime.exs config/runtime.exs +RUN mix release --path /opt/built ######################################################################## -FROM alpine:3.12 AS app +FROM debian:buster-slim AS app ENV LANG=C.UTF-8 \ SRTM_CACHE=/opt/app/.srtm_cache \ HOME=/opt/app -RUN apk add --no-cache ncurses-libs openssl tini tzdata +RUN apt-get update && apt-get install -y --no-install-recommends \ + libodbc1 \ + libsctp1 \ + libssl1.1 \ + netcat \ + tini \ + tzdata + +RUN addgroup --gid 10001 --system nonroot && \ + adduser --uid 10000 --system --ingroup nonroot --home /home/nonroot nonroot WORKDIR $HOME -RUN chown -R nobody:nobody . -USER nobody:nobody +RUN chown -R nonroot:nonroot . +USER nonroot:nonroot -COPY --chown=nobody:nobody entrypoint.sh / -COPY --from=builder --chown=nobody:nobody /opt/built . -RUN mkdir .srtm_cache +COPY --chown=nonroot:nonroot entrypoint.sh / +COPY --from=builder --chown=nonroot:nonroot /opt/built . +RUN mkdir $SRTM_CACHE EXPOSE 4000 -ENTRYPOINT ["/sbin/tini", "--", "/bin/sh", "/entrypoint.sh"] +ENTRYPOINT ["tini", "--", "/bin/sh", "/entrypoint.sh"] CMD ["bin/teslamate", "start"] diff --git a/entrypoint.sh b/entrypoint.sh index 4b5af4f6..cf8b4934 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,19 +1,13 @@ -#!/bin/sh +#!/usr/bin/env sh set -e : "${DATABASE_HOST:="127.0.0.1"}" : "${DATABASE_PORT:=5432}" -# wait until the postgres port opens -sleep 1s -p=1 -while : ; do - set +e - if (nc -z ${DATABASE_HOST} ${DATABASE_PORT}) >/dev/null 2>&1; then set -e; break; fi - set -e - p=$((p + p)) - echo waiting for postgres at ${DATABASE_HOST}:${DATABASE_PORT} \("$p"sec\) - sleep "${p}"s +# wait until Postgres is ready +while ! nc -z ${DATABASE_HOST} ${DATABASE_PORT} 2>/dev/null; do + echo waiting for postgres at ${DATABASE_HOST}:${DATABASE_PORT} + sleep 1s done # apply migrations