I plan to create a docker base image with Julia and all packages for my projects. I will not copy my projects into the docker at this phase, but I have all Project. toml files. What is the proper way to get all packages and add them to the base image?
Something like this
using TOML
function combine_project_files(project_paths, output_path)
global_deps = Dict{String, String}()
for path in project_paths
project_toml = TOML.parsefile(joinpath(path, "Project.toml"))
if haskey(project_toml, "deps")
for (pkg, uuid) in project_toml["deps"]
global_deps[pkg] = uuid
end
end
end
combined_toml = Dict("deps" => global_deps)
open(joinpath(output_path, "Project.toml"), "w") do f
TOML.print(f, combined_toml)
end
end
# List of project paths
project_paths = ["path/to/project1", "path/to/project2", ...]
# Output path for the combined Project.toml
output_path = "path/to/combined"
combine_project_files(project_paths, output_path)
I can copy all Project.toml files into the docker, run the above code, and then
FROM julialang/julia:latest
# Copy combined Project.toml to a directory in the container
COPY path/to/combined/Project.toml /app/Project.toml
# Set that directory as the working directory
WORKDIR /app
# Activate the custom environment and instantiate to pre-download all packages
RUN julia --project=/app -e 'using Pkg; Pkg.instantiate()'
What is a better alternative because I don’t think this is the right way.