Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the default Dockerfile, mix assets.deploy downloads tailwind & esbuild every time assets change #5833

Open
jyc opened this issue Jun 5, 2024 · 2 comments

Comments

@jyc
Copy link
Contributor

jyc commented Jun 5, 2024

Thanks for making Phoenix! I noticed that in the default Dockerfile mix assets.deploy downloads tailwind & esbuild every time assets change:

RUN mix deps.compile
COPY priv priv
COPY lib lib
<%= if assets_dir_exists? do %>
COPY assets assets
# compile assets
RUN mix assets.deploy

Do you think the default could be changed to run

mix tailwind.install
mix esbuild.install

... after mix deps.compile and before mix assets.deploy? This should make most Docker image builds faster because they won't have to download tailwind/esbuild every time anything in priv, lib, or assets changes.

I'd be happy to open a small PR to do this if it's alright with you!

The only challenge is that it'd have to handle --no-tailwind and --no-esbuild. Happy to take a stab at handling that too with some pointers; a cursory search for no-tailwind didn't turn up anything: https://github.com/search?q=repo%3Aphoenixframework%2Fphoenix+no-tailwind&type=code

@SteffenDE
Copy link
Contributor

@jyc I think it should be possible to add mix assets.setup instead of adding the tailwind and esbuild installs separately. We'd only need to check if the assets.setup task is actually available when generating the Dockerfile:

RUN mix deps.compile
<%= if @assets_setup_available? do %>mix assets.setup<% end %>

and adding the binding here:

Keyword.merge(binding,
debian: @debian,
debian_vsn: debian_vsn,
elixir_vsn: elixir_vsn,
otp_vsn: otp_vsn

            elixir_vsn: elixir_vsn,
+           otp_vsn: otp_vsn,
+           assets_setup_available?: Keyword.has_key?(Mix.Project.config()[:aliases], :"assets.setup")

If you want to give it a go and send a PR, I'll be happy to review it.

@rhcarvalho
Copy link
Contributor

I do an explicit mix assets.setup after mix deps.compile in a Dockerfile, can confirm it leads to better caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants