arton

arton

I recently came across this due to our yarn install failing with network issues during the CI/CD process. I’m wondering is mix has anything like yarn’s offline mirror or if there has been discussion around it at all. I like the assurances of having the dependencies committed without all the noise of individual dependency files in the repo.

First 10 of 13 Posts Switch mode

aaronrenner

aaronrenner

Phoenix Core Team

I know if the deps are already downloaded in deps/ and then you run mix deps.get while offline, mix will attempt to contact hex.pm and then fall back to what is downloaded locally. So if it’s possible to cache deps/. in ci, that might help.

I’m curious if there’s a way to have mix skip attempting to contact hex.pm if it already has everything downloaded that it needs. :thinking: That would save me a couple seconds each CI run.

mpope

mpope

Deps have the option to have a path, like:

deps() do
   [
       {:local_dependency, path: "path/to/local_dependency"}
   ]
end

Link to the docs, although I am not sure it accepts an actual package. The repo would have to be cloned?

One thing I was considering setting up was a MiniRepo Docker image pre-loaded with the hex deps the project needed. The build happens in a docker-compose so it makes sense in my case but maybe not all cases.

arton

arton OP

I use that sometimes for development work, but I don’t want the manual process of keeping something like that up to date. The nice thing about how yarn does it, is it saves the tarballs locally and the checksum for them in the lock file. That way you’re getting the exact same thing npm would be giving you, and you only have to track a smaller list of files. They could even be stored in git LFS.

arton

arton OP

I don’t like to store the reps folder in the repo because it’s so many files that can change a lot during updates. I do like having the assurance of the exact files I expect being stored in a way I can control though. It’s a tough compromise to make, but I feel like yarn addressed it in a pretty elegant way.

ericmj

ericmj

Elixir Core Team

Reading through the yarn article it seems like Hex does all of this except it does it automatically without needing to configure a mirror.

All Hex packages you download are cached in ~/.hex which means that if your network is down and you need to fetch the package again the cache will be used as a fallback. You can force the cache to be used by setting the environment flag HEX_OFFLINE=1. Additionally, all your dependencies are locked in the mix.lock file to ensure you always get the same versions that were initially fetched and locked.

If you need something else then please elaborate on what you want to do and how it is different from what Hex provides today.

slouchpie

slouchpie

If I try to mix deps.get on a project, will it try to use this cache? Or will it always prefer to download “fresh” libs (even if same version)?

ericmj

ericmj

Elixir Core Team

There are multiple layers of caching for the different stages of fetching dependencies. We will always try to use the cache if it’s available but that does not necessarily mean we make no HTTP requests if everything is cached.

First of mix deps.get will not do anything if you already have fetched dependencies in the projects deps/ directory and they match the lock. If dependencies are missing in deps/ or they do not match the lockfile they will be fetched.

Before fetching dependencies we may need to do dependency resolution in case dependencies are not locked or they are being updated with mix deps.update. To perform dependency resolution we need to fetch package indexes from the registry. Package indexes are cached but we will always make conditional HTTP requests [1] for them to ensure you have the latest version of the index, if you have the latest version they are not downloaded again.

When dependencies are resolved to a specific version their package tarballs can be fetched, the tarballs are also cached so if you fetched the tarball previously on the same machine and the checksum matches then no request will be made.

[1] HTTP conditional requests - HTTP | MDN

arton

arton OP

Thanks @ericmj , it seems like hex does handle this well already. However, it would be difficult to commit the cached tarballs since they reside in the user’s home directory. Is there any way to specify the location of the cache, so we can make sure it’s available in a CI/CD docker process?

ericmj

ericmj

Elixir Core Team

We don’t have a way to configure only the cache directory location.

Can you explain why you want this feature, what existing problems does it solve? Personally I don’t think you should commit files to version control to help the reliability of CI/CD. I think any concerns about that should be handled by the CI/CD process, by making it more reliable or adding caching there.

chulkilee

chulkilee

More notes

  • You may just tarball deps folder for example and use HEX_OFFLINE env var. However, I’ve seen its content changes (e.g. creating new file under /deps) during compile time..
  • You can easily set up hex repo with mini_repo - but you have to list packages to sync, or sync all.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement