From 66ec0903d9e2f2c00f8914ed2dfb3b9a2b5035af Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Wed, 21 Aug 2024 07:10:42 -0400 Subject: [PATCH] fix setup scripts Signed-off-by: Greg Werner --- umich-notebook/Dockerfile | 18 +--- umich-notebook/setup-scripts/setup_julia.py | 97 --------------------- 2 files changed, 3 insertions(+), 112 deletions(-) delete mode 100755 umich-notebook/setup-scripts/setup_julia.py diff --git a/umich-notebook/Dockerfile b/umich-notebook/Dockerfile index 7537a10..1ab9a7e 100644 --- a/umich-notebook/Dockerfile +++ b/umich-notebook/Dockerfile @@ -2,28 +2,18 @@ # https://github.com/jupyter/docker-stacks/blob/main/images/julia-notebook ARG REGISTRY=quay.io ARG OWNER=jupyter -ARG BASE_CONTAINER=$REGISTRY/$OWNER/minimal-notebook -FROM $BASE_CONTAINER +ARG BASE_CONTAINER=$REGISTRY/$OWNER/julia-notebook +FROM ${BASE_CONTAINER} # Fix: https://github.com/hadolint/hadolint/wiki/DL4006 # Fix: https://github.com/koalaman/shellcheck/wiki/SC3014 SHELL ["/bin/bash", "-o", "pipefail", "-c"] -USER root - -# Julia dependencies -# install Julia packages in /opt/julia instead of ${HOME} -ENV JULIA_DEPOT_PATH=/opt/julia \ - JULIA_PKGDIR=/opt/julia - -# Setup Julia -RUN /opt/setup-scripts/setup_julia.py - USER ${NB_UID} # Setup IJulia kernel & other packages COPY --chown=${NB_UID}:${NB_GID} setup-scripts/*.* /opt/setup-scripts/. -RUN chown +rx /opt/setup-scripts/install-julia-packages.bash \ +RUN chmod +rx /opt/setup-scripts/install-julia-packages.bash \ && /opt/setup-scripts/install-julia-packages.bash RUN pip install jupyter_kernel_gateway psycopg2-binary @@ -31,5 +21,3 @@ RUN pip install jupyter_kernel_gateway psycopg2-binary WORKDIR "${HOME}" CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.port=8888"] - -CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.port=8888"] \ No newline at end of file diff --git a/umich-notebook/setup-scripts/setup_julia.py b/umich-notebook/setup-scripts/setup_julia.py deleted file mode 100755 index 114e64c..0000000 --- a/umich-notebook/setup-scripts/setup_julia.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) Jupyter Development Team. -# Distributed under the terms of the Modified BSD License. - -# Requirements: -# - Run as the root user -# - The JULIA_PKGDIR environment variable is set - -import logging -import os -import platform -import shutil -import subprocess -from pathlib import Path - -import requests - -LOGGER = logging.getLogger(__name__) - - -def unify_aarch64(platform: str) -> str: - """ - Renames arm64->aarch64 to support local builds on on aarch64 Macs - """ - return { - "aarch64": "aarch64", - "arm64": "aarch64", - "x86_64": "x86_64", - }[platform] - - -def get_latest_julia_url() -> tuple[str, str]: - """ - Get the last stable version of Julia - Based on: https://github.com/JuliaLang/www.julialang.org/issues/878#issuecomment-749234813 - """ - LOGGER.info("Downloading Julia versions information") - versions = requests.get( - "https://julialang-s3.julialang.org/bin/versions.json" - ).json() - stable_versions = {k: v for k, v in versions.items() if v["stable"]} - # Compare versions semantically - latest_stable_version = max( - stable_versions, key=lambda ver: [int(sub_ver) for sub_ver in ver.split(".")] - ) - latest_version_files = stable_versions[latest_stable_version]["files"] - triplet = unify_aarch64(platform.machine()) + "-linux-gnu" - file_info = [vf for vf in latest_version_files if vf["triplet"] == triplet][0] - LOGGER.info(f"Latest version: {file_info['version']} url: {file_info['url']}") - return file_info["url"], file_info["version"] - - -def download_julia(julia_url: str) -> None: - """ - Downloads and unpacks julia - The resulting julia directory is "/opt/julia-VERSION/" - """ - LOGGER.info("Downloading and unpacking Julia") - tmp_file = Path("/tmp/julia.tar.gz") - subprocess.check_call( - ["curl", "--progress-bar", "--location", "--output", tmp_file, julia_url] - ) - shutil.unpack_archive(tmp_file, "/opt/") - tmp_file.unlink() - - -def configure_julia(julia_version: str) -> None: - """ - Creates /usr/local/bin/julia symlink - Make Julia aware of conda libraries - Creates a directory for Julia user libraries - """ - LOGGER.info("Configuring Julia") - # Link Julia installed version to /usr/local/bin, so julia launches it - subprocess.check_call( - ["ln", "-fs", f"/opt/julia-{julia_version}/bin/julia", "/usr/local/bin/julia"] - ) - - # Tell Julia where conda libraries are - Path("/etc/julia").mkdir() - Path("/etc/julia/juliarc.jl").write_text( - f'push!(Libdl.DL_LOAD_PATH, "{os.environ["CONDA_DIR"]}/lib")\n' - ) - - # Create JULIA_PKGDIR, where user libraries are installed - JULIA_PKGDIR = Path(os.environ["JULIA_PKGDIR"]) - JULIA_PKGDIR.mkdir() - subprocess.check_call(["chown", os.environ["NB_USER"], JULIA_PKGDIR]) - subprocess.check_call(["fix-permissions", JULIA_PKGDIR]) - - -if __name__ == "__main__": - logging.basicConfig(level=logging.INFO) - - julia_url, julia_version = get_latest_julia_url() - download_julia(julia_url=julia_url) - configure_julia(julia_version=julia_version)