tao

tao

I’m deploying a Phoenix app with Elixir releases and Docker. The Phoenix docs have an example dockerfile you can use – mine is based on that one.

I’ve set up the file so that dependency downloads and compilation should be cached by Docker, but this isn’t happening. This is slowing down deploys a bit. Can anyone spot why Docker isn’t caching dependencies? Even when mix.exs is unchanged, it redownloads and rebuilds them.

FROM elixir:1.9.0-alpine as build

# install build dependencies
RUN apk add --update git build-base

# prepare build dir
RUN mkdir /app
WORKDIR /app

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

# set build ENV
ENV MIX_ENV=prod

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get
RUN mix deps.compile
COPY config config

# build assets
# COPY assets assets
# RUN cd assets && npm install && npm run deploy
# RUN mix phx.digest

# build project
COPY priv priv
COPY lib lib
RUN mix compile

# build release
COPY rel rel
RUN mix release

Showing Posts 1 to 10

NobbZ

NobbZ

Do you touch the mix.lock or mix.exs between builds?

From a theoretical point of view, your file should work.

tao

tao OP

Interesting. Nope, the dependencies get redownloaded and rebuilt even when I haven’t touched those files – that’s why I’m confused and why I opened this thread!

The Phoenix docs actually have a slightly different order:

COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get
RUN mix deps.compile

I moved this around since I didn’t want to redownload deps after changing configuration, but now I’m starting to wonder if there’s a reason to their ordering?

NobbZ

NobbZ

Oh, yes. Config needs to be available, as it might affect how dependencies are built.

cnck1387

cnck1387

Can you give an example where a config’s value would determine how dependencies are built?

I know you can choose to install packages based on the environment with mix but isn’t that controlled by the mix command itself with --only prod along with mix.exs?

NobbZ

NobbZ

Compile time configuration is the magic word.

tao

tao OP

Okay, I’ll try going back to the original config from the docs!

I’m not sure I understand how this could make Docker not cache things, though. All that Docker knows is that nothing has changed in mix.exs and mix.lock, yet it still re-runs the dependency steps instead of using the cached versions.

NobbZ

NobbZ

Yeah, I do not understand that as well… Weird.

jola

jola

As an example, Logger lets you remove log calls from modules at compile time, even in dependencies, through the config option :compile_time_purge_matching.

cnck1387

cnck1387

Thanks, but would this change which dependencies get mix installed?

jola

jola

Oh, sorry, I was just respond to your comment “determine how dependencies are built” and giving an example of the compile time configuration @NobbZ mentioned. Not sure how config would affect which dependencies get installed though, since that’s the job of the mix.exs and mix.lock.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews