|
| 1 | +# See https://hub.docker.com/_/julia for valid versions. |
| 2 | +ARG JULIA_VERSION="1.10.4" |
| 3 | + |
| 4 | +#------------------------------------------------------------------------------ |
| 5 | +# internal-base build target: julia with OS updates and an empty @reefguide |
| 6 | +# Julia environment prepared for use. NOT intended for standalone use. |
| 7 | +#------------------------------------------------------------------------------ |
| 8 | +FROM julia:${JULIA_VERSION}-bookworm AS internal-base |
| 9 | + |
| 10 | +# Record the actual base image used from the FROM command as label in the compiled image |
| 11 | +ARG BASE_IMAGE=$BASE_IMAGE |
| 12 | +LABEL org.opencontainers.image.base.name=${BASE_IMAGE} |
| 13 | + |
| 14 | +# Update all pre-installed OS packages (to get security updates) |
| 15 | +# and add a few extra utilities |
| 16 | +RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ |
| 17 | + --mount=target=/var/cache/apt,type=cache,sharing=locked \ |
| 18 | + apt-get update \ |
| 19 | + && apt-get -y upgrade \ |
| 20 | + && apt-get install --no-install-recommends -y \ |
| 21 | + git \ |
| 22 | + less \ |
| 23 | + nano \ |
| 24 | + && apt-get clean \ |
| 25 | + && apt-get autoremove --purge \ |
| 26 | + && rm -rf /var/lib/apt/lists/* |
| 27 | + |
| 28 | +# Tweak the JULIA_DEPOT_PATH setting so that our shared environments will end up |
| 29 | +# in a user-agnostic location, not in ~/.julia => /root/.julia which is the default. |
| 30 | +# See https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_DEPOT_PATH |
| 31 | +# This allows apps derived from this image to drop privileges and run as non-root |
| 32 | +# user accounts, but still activate environments configured by this dockerfile. |
| 33 | +ENV JULIA_DEPOT_PATH="/usr/local/share/julia" |
| 34 | + |
| 35 | +# Prepare an empty @reefguide Julia environment for derived images to use - this is created in the shared depot path |
| 36 | +RUN mkdir -p "${JULIA_DEPOT_PATH}" && \ |
| 37 | + chmod 0755 "${JULIA_DEPOT_PATH}" && \ |
| 38 | + julia -e 'using Pkg; Pkg.activate("reefguide", shared=true)' |
| 39 | + |
| 40 | +# Ensure the @reefguide environment is in the load path for Julia, so that apps derived |
| 41 | +# from this image can access any packages installed to there. |
| 42 | +# (See https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_LOAD_PATH) |
| 43 | +ENV JULIA_LOAD_PATH="@:@reefguide:@v#.#:@stdlib" |
| 44 | + |
| 45 | +# Run Julia commands by default as the container launches. |
| 46 | +# Derived applications should override the command. |
| 47 | +ENTRYPOINT ["julia", "--project=@reefguide"] |
| 48 | + |
| 49 | + |
| 50 | +#------------------------------------------------------------------------------ |
| 51 | +# reefguide-base build target: ReefGuideAPI.jl preinstalled as a non-dev package. |
| 52 | +# Use `--target=reefguide-base` on your `docker build command to build *just* this. |
| 53 | +#------------------------------------------------------------------------------ |
| 54 | + |
| 55 | +# TODO enable and update this once the package is available from registry |
| 56 | +# FROM internal-base AS reefguide-base |
| 57 | +# |
| 58 | +# # What version of ReefGuideAPI.jl from package registry to install in reefguide-base |
| 59 | +# # TODO this doesn't make sense yet |
| 60 | +# ARG REEFGUIDE_VERSION="0.1.0" |
| 61 | +# |
| 62 | +# # Which julia package registry version to install |
| 63 | +# ENV REEFGUIDE_VERSION=$REEFGUIDE_VERSION |
| 64 | +# |
| 65 | +# # Try to coerce Julia to build across multiple targets |
| 66 | +# ENV JULIA_CPU_TARGET=x86_64;haswell;skylake;skylake-avx512;tigerlake |
| 67 | +# |
| 68 | +# # Install ReefGuideAPI.jl into the @reefguide shared environment as an unregistered package. |
| 69 | +# # - Allow the package source and version to be overridden at build-time. |
| 70 | +# # - Include citation information for ReefGuideAPI.jl in the image labels. |
| 71 | +# RUN mkdir -p "${JULIA_DEPOT_PATH}" && \ |
| 72 | +# chmod 0755 "${JULIA_DEPOT_PATH}" && \ |
| 73 | +# julia --project=@reefguide -e "using Pkg; Pkg.add(name=\"ReefGuideAPI\", version=\"${REEFGUIDE_VERSION}\"); Pkg.instantiate(); Pkg.precompile(); using ReefGuideAPI;" |
| 74 | +# LABEL au.gov.aims.reefguideapi.source="https://github.com/open-AIMS/ReefGuideAPI.jl/releases/tag/v${REEFGUIDE_VERSION}" \ |
| 75 | +# au.gov.aims.reefguideapi.version="${REEFGUIDE_VERSION}" \ |
| 76 | +# au.gov.aims.reefguideapi.vendor="Australian Institute of Marine Science" \ |
| 77 | +# au.gov.aims.reefguideapi.licenses=MIT |
| 78 | +# |
| 79 | +# # Expect to include the prepped data at /data/reefguide and the config at |
| 80 | +# # /data/.config.toml |
| 81 | +# VOLUME ["/data/reefguide"] |
| 82 | +# |
| 83 | +# EXPOSE 8000 |
| 84 | +# |
| 85 | +# # Run Julia commands by default as the container launches. |
| 86 | +# # Derived applications should override the command. |
| 87 | +# ENTRYPOINT ["julia", "--project=@reefguide", "-t", "1,auto", "-e", "using ReefGuideAPI; ReefGuideAPI.start_server(\"/data/reefguide/config.toml\")"] |
| 88 | + |
| 89 | +#------------------------------------------------------------------------------ |
| 90 | +# reefguide-src build target: installs directly from source files in this repo. |
| 91 | +#------------------------------------------------------------------------------ |
| 92 | +FROM internal-base AS reefguide-src |
| 93 | + |
| 94 | +ENV REEFGUIDE_ENV_DIR="${JULIA_DEPOT_PATH}/environments/reefguide" \ |
| 95 | + REEFGUIDE_SRC_DIR="/usr/local/src/reefguide" |
| 96 | + |
| 97 | +# Try to coerce Julia to build across multiple targets |
| 98 | +ENV JULIA_CPU_TARGET=x86_64;haswell;skylake;skylake-avx512;tigerlake |
| 99 | + |
| 100 | +# Install the versioned .toml file(s) into the shared reefguide environment and use |
| 101 | +# those to set up the ReefGuideAPI source code as a development package in the |
| 102 | +# shared @reefguide environment, pre-installing and precompiling dependencies. |
| 103 | +WORKDIR "${REEFGUIDE_SRC_DIR}" |
| 104 | +COPY ./Project.toml ./Project.toml |
| 105 | +COPY ./Manifest.toml ./Manifest.toml |
| 106 | +RUN julia --project=@reefguide -e 'using Pkg; Pkg.instantiate(verbose=true)' |
| 107 | + |
| 108 | +# Install the ReefGuideAPI source code and configure it as a development |
| 109 | +# package in the @reefguide shared environment. |
| 110 | +# Should be v speedy if the .toml file is unchanged, because all the |
| 111 | +# dependencies *should* already be installed. |
| 112 | +COPY ./src src |
| 113 | +RUN julia --project=@reefguide \ |
| 114 | + -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.precompile(); using ReefGuideAPI;' |
| 115 | + |
| 116 | +# Expect to include the prepped data at /data/reefguide and the config at |
| 117 | +# /data/.config.toml |
| 118 | +VOLUME ["/data/reefguide"] |
| 119 | + |
| 120 | +EXPOSE 8000 |
| 121 | + |
| 122 | +# Run Julia commands by default as the container launches. |
| 123 | +# Derived applications should override the command. |
| 124 | +ENTRYPOINT ["julia", "--project=@reefguide", "-t", "1,auto", "-e", "using ReefGuideAPI; ReefGuideAPI.start_server(\"/data/reefguide/config.toml\")"] |
0 commit comments