Building Docker image on a machine and deploying on another invalidates precompile cache

I’m building a Docker image with a precompile statement in its Dockerfile to make startup faster. If I deploy the image on the same machine where it was built, it starts up very quick. However, If I deploy to a different machine, the precompilation runs again whenever the container is started.

I suppose the precompile cache is invalidated due to the machine change, even if they share the same architecture. Does anyone know how to solve this?

Here’s an example of the type of app I’m trying to deploy

and its Dockerfile


FROM julia:latest
RUN apt-get update && apt-get install -y vim
RUN useradd --create-home --shell /bin/bash genie
RUN mkdir /home/genie/app
COPY . /home/genie/app
WORKDIR /home/genie/app
RUN chown -R genie:genie /home/
USER genie
EXPOSE 8000
EXPOSE 80
ENV JULIA_DEPOT_PATH "/home/genie/.julia"
ENV JULIA_REVISE = "off"
ENV GENIE_ENV "prod"
ENV GENIE_HOST "0.0.0.0"
ENV PORT "8000"
ENV WSPORT "8000"
ENV EARLYBIND "true"
RUN julia -e "using Pkg; Pkg.activate(\".\"); Pkg.instantiate(); Pkg.precompile(); "
ENTRYPOINT ["julia", "--project", "-e", "using GenieFramework; Genie.loadapp(); up(async=false);"]
3 Likes

Set the JULIA_CPU_TARGET environment variable before precompiling, see PkgServer.jl/Dockerfile at 90390794dd4a0eb65b2952970c6a5ccebb5871c3 · JuliaPackaging/PkgServer.jl · GitHub

6 Likes

See julia-buildkite/utilities/build_envs.sh at 33dbca22c2ed5be868ec08f343415580fd57238e · JuliaCI/julia-buildkite · GitHub to determine JULIA_CPU_TARGETS for different architectures.

2 Likes

That worked perfectly, thank you!