Optimize dockerfile

This commit is contained in:
Alex
2024-04-14 01:01:23 +02:00
parent a3092a147d
commit 81db07628b
7 changed files with 695 additions and 638 deletions

View File

@@ -12,30 +12,31 @@
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.13.2-erlang-24.2.1-debian-bullseye-20210902-slim
#
ARG BUILDER_IMAGE="hexpm/elixir:1.16.0-erlang-26.2.1-debian-bullseye-20231009-slim"
ARG RUNNER_IMAGE="debian:bullseye-20231009-slim"
ARG BUILDER_IMAGE="hexpm/elixir:1.16.0-erlang-26.2.1-alpine-3.18.4"
ARG RUNNER_IMAGE="alpine:3.18.4"
FROM ${BUILDER_IMAGE} as builder
# install build dependencies
RUN apt-get update -y && apt-get install -y curl build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# RUN apt-get update -y && apt-get install -y curl build-essential git \
# && apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apk add --no-cache -U build-base git curl bash ca-certificates nodejs npm openssl ncurses
ENV NODE_VERSION 16.20.0
ENV PRESENTATION_STORAGE_DIR /app/uploads
# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash \
&& . $HOME/.nvm/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
# && . $HOME/.nvm/nvm.sh \
# && nvm install $NODE_VERSION \
# && nvm alias default $NODE_VERSION \
# && nvm use default
ENV NODE_PATH $HOME/.nvm/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $HOME/.nvm/versions/node/v$NODE_VERSION/bin:$PATH
# ENV NODE_PATH $HOME/.nvm/versions/node/v$NODE_VERSION/lib/node_modules
# ENV PATH $HOME/.nvm/versions/node/v$NODE_VERSION/bin:$PATH
RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/npm /usr/bin/npm
RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/node /usr/bin/node
# RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/npm /usr/bin/npm
# RUN ln -sf $HOME/.nvm/versions/node/v$NODE_VERSION/bin/node /usr/bin/node
# prepare build dir
WORKDIR /app
@@ -71,8 +72,12 @@ COPY lib lib
RUN mix compile
RUN npm install -g sass
RUN cd assets && npm i && \
sass --no-source-map --style=compressed css/custom.scss ../priv/static/assets/custom.css
# compile assets
RUN mix assets.deploy
RUN mix assets.deploy.nosass
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
@@ -84,34 +89,32 @@ RUN mix release
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && apt-get install -y curl libstdc++6 openssl libncurses5 locales ghostscript default-jre libreoffice-java-common \
&& apt-get install -y libreoffice --no-install-recommends && apt-get clean && rm -f /var/lib/apt/lists/*_*
# RUN apt-get update -y && apt-get install -y curl libstdc++6 openssl libncurses5 locales ghostscript default-jre libreoffice-java-common \
# && apt-get install -y libreoffice --no-install-recommends && apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apk add --no-cache curl libstdc++6 openssl ncurses ghostscript openjdk11-jre
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
# Install LibreOffice & Common Fonts
RUN apk --no-cache add bash libreoffice util-linux libreoffice-common \
font-droid-nonlatin font-droid ttf-dejavu ttf-freefont ttf-liberation && \
rm -rf /var/cache/apk/*
# Install Microsoft Core Fonts
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f && \
rm -rf /var/cache/apk/*
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV HOME "/home/nobody"
ENV MIX_ENV="prod"
RUN mkdir /home/nobody && chown nobody /home/nobody
WORKDIR "/app"
RUN mkdir /app/uploads
RUN chown -R nobody /app
# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/prod/rel/claper ./
RUN chmod +x /app/bin/*
USER nobody
COPY --from=builder --chmod=a+rX /app/_build/prod/rel/claper /app
RUN mkdir /app/uploads && chmod -R 777 /app/uploads
EXPOSE 4000
WORKDIR "/app"
USER root
CMD ["sh", "-c", "/app/bin/claper eval Claper.Release.migrate && /app/bin/claper start"]
# Appended by flyctl
#ENV ECTO_IPV6 true
#ENV ERL_AFLAGS "-proto_dist inet6_tcp"

1238
assets/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,10 +3,10 @@
"deploy": "NODE_ENV=production tailwindcss --postcss --minify --input=css/app.css --output=../priv/static/assets/app.css"
},
"devDependencies": {
"alpinejs": "^3.13.1",
"autoprefixer": "^10.4.15",
"esbuild": "^0.14.54",
"postcss": "^8.4.29",
"alpinejs": "^3.13.8",
"autoprefixer": "^10.4.19",
"esbuild": "^0.20.2",
"postcss": "^8.4.38",
"postcss-import": "^15.1.0",
"tailwindcss": "^3.3.3"
},
@@ -24,4 +24,4 @@
"split.js": "^1.6.5",
"tiny-slider": "^2.9.4"
}
}
}

View File

@@ -21,7 +21,7 @@ config :claper, ClaperWeb.Gettext,
locales: ~w(fr en de)
config :dart_sass,
version: "1.58.0",
version: "1.61.0",
default: [
args: ~w(css/custom.scss ../priv/static/assets/custom.css),
cd: Path.expand("../assets", __DIR__)

View File

@@ -24,7 +24,6 @@ services:
- claper-net
app:
image: ghcr.io/claperco/claper:latest # or build: .
user: 0:0
ports:
- 4000:4000
volumes:
@@ -32,7 +31,7 @@ services:
healthcheck:
test: curl --fail http://localhost:4000 || exit 1
retries: 3
start_period: 10s
start_period: 20s
timeout: 5s
env_file: .env
depends_on:

View File

@@ -102,7 +102,7 @@ defmodule Claper.MixProject do
{:floki, ">= 0.36.1", only: :test},
{:phoenix_live_dashboard, "~> 0.8"},
{:esbuild, "~> 0.2", runtime: Mix.env() == :dev},
{:dart_sass, "~> 0.5", runtime: Mix.env() == :dev},
{:dart_sass, "~> 0.7", runtime: Mix.env() == :dev},
{:swoosh, "~> 1.12"},
{:finch, "~> 0.16"},
{:telemetry_metrics, "~> 0.6"},
@@ -139,6 +139,11 @@ defmodule Claper.MixProject do
"esbuild default --minify",
"sass default --no-source-map --style=compressed",
"phx.digest"
],
"assets.deploy.nosass": [
"cmd --cd assets npm install && npm run deploy",
"esbuild default --minify",
"phx.digest"
]
]
end

View File

@@ -10,7 +10,7 @@
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
"csv": {:hex, :csv, "3.0.5", "3c1455127e92de8845806db89554ad7d45e0212974be41dd9c38a5c881861713", [:mix], [], "hexpm", "cbbe5455c93df5f3f2943e995e28b7a8808361ba34cf3e44267d77a01eaf1609"},
"dart_sass": {:hex, :dart_sass, "0.6.0", "1fe560c3ed5c577b6b9cf97134a0e05c82b69645d313b1ef0ffb4d659c3d0300", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "41f7bb065b5c30c3ea05e8b41aa3f9b5c62817079b94f70e2a22d133828475bb"},
"dart_sass": {:hex, :dart_sass, "0.7.0", "7979e056cb74fd6843e1c72db763cffc7726a9192a657735b7d24c0d9c26a1ce", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "4a8e70bca41aa00846398abdf5ad8a64d7907a0f7bf40145cd2e40d5971629f2"},
"db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},