Skip to content

Commit

Permalink
Create standalone Julia environment (#24)
Browse files Browse the repository at this point in the history
* Create standalone Julia environment

* Add packages that were accidentally removed

* Include DataFrames and DisplaAs

* Fix Dockerfile

* Add back SyntacticModels

* Expand install.jl to include new dependencies

* Remove content from precompile

* Everything is seperate, but still works together

---------

Co-authored-by: Matthew Printz <[email protected]>
  • Loading branch information
fivegrant and mattprintz authored Nov 17, 2023
1 parent ea9ee7b commit afabb8d
Show file tree
Hide file tree
Showing 9 changed files with 1,391 additions and 80 deletions.
30 changes: 15 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
ARG JULIA_IMAGE=askem-julia-base
FROM ${JULIA_IMAGE} AS JULIA_BASE_IMAGE


FROM python:3.10
RUN useradd -m jupyter
EXPOSE 8888
RUN mkdir -p /usr/local/share/jupyter/kernels && chmod -R 777 /usr/local/share/jupyter/kernels

ENV JULIA_PATH=/usr/local/julia
ENV JULIA_DEPOT_PATH=/usr/local/julia
ENV JULIA_PROJECT=/home/jupyter/.julia/environments/v1.9

# Install Julia
RUN wget --no-verbose -O julia.tar.gz "https://julialang-s3.julialang.org/bin/linux/$(uname -m|sed 's/86_//')/1.9/julia-1.9.0-linux-$(uname -m).tar.gz"
RUN tar -xzf "julia.tar.gz" && mv julia-1.9.0 /opt/julia && \
ln -s /opt/julia/bin/julia /usr/local/bin/julia && rm "julia.tar.gz"
COPY --from=JULIA_BASE_IMAGE /usr/local/julia /usr/local/julia
COPY --from=JULIA_BASE_IMAGE /ASKEM-Sysimage.so /usr/local/julia/lib/ASKEM-Sysimage.so
RUN chmod -R 777 /usr/local/julia/logs
RUN ln -sf /usr/local/julia/bin/julia /usr/local/bin/julia

COPY --chown=1000:1000 environments/julia /home/jupyter/.julia/environments/v1.9

USER jupyter
WORKDIR /home/jupyter

RUN julia -e 'ENV["JUPYTER_DATA_DIR"] = "/usr/local/share/jupyter"; using Pkg; Pkg.add("IJulia")'
# TODO: Remove these lines and add them back into the Project.toml when branch is merged
RUN julia -e 'using Pkg; Pkg.add(url="https://github.com/fivegrant/Decapodes.jl", rev="jpf/DecaExpr")'
RUN julia -e 'using Pkg; Pkg.add("SyntacticModels")'
RUN julia -e 'using Pkg; Pkg.add("Graphviz_jll")'

USER root

# Install r-lang and kernel
RUN apt update && \
apt install -y r-base r-cran-irkernel && \
Expand Down Expand Up @@ -56,9 +54,11 @@ COPY beaker /usr/local/share/jupyter/kernels/beaker
RUN chown 1000:1000 /jupyter
COPY --chown=1000:1000 . /jupyter


# Switch to non-root user. It is crucial for security reasons to not run jupyter as root user!
USER jupyter

CMD ["python", "service/main.py", "--ip", "0.0.0.0"]
# Install Julia kernel
RUN /usr/local/julia/bin/julia -J /usr/local/julia/lib/ASKEM-Sysimage.so -e 'using IJulia; IJulia.installkernel("julia"; julia=`/usr/local/julia/bin/julia -J /usr/local/julia/lib/ASKEM-Sysimage.so --threads=4`)'

# Service
CMD ["python", "service/main.py", "--ip", "0.0.0.0"]
18 changes: 18 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ variable "VERSION" {

# ----------------------------------------------------------------------------------------------------------------------

function "buildtag" {
params = [image_name, prefix, suffix]
result = [ "${DOCKER_REGISTRY}/${DOCKER_ORG}/${image_name}:${check_prefix(prefix)}${VERSION}${check_suffix(suffix)}", "${image_name}:build" ]
}

function "tag" {
params = [image_name, prefix, suffix]
result = [ "${DOCKER_REGISTRY}/${DOCKER_ORG}/${image_name}:${check_prefix(prefix)}${VERSION}${check_suffix(suffix)}" ]
Expand Down Expand Up @@ -41,10 +46,23 @@ target "_platforms" {
platforms = ["linux/amd64"]
}

target "askem-julia-base" {
inherits = ["_platforms"]
context = "environments/julia/"
tags = buildtag("askem-julia-base", "", "")
dockerfile = "Dockerfile"
}

target "beaker-kernel-base" {
contexts = {
askem-julia-base = "target:askem-julia-base"
}
context = "."
tags = tag("beaker-kernel", "", "")
dockerfile = "Dockerfile"
args = {
JULIA_IMAGE = "askem-julia-base"
}
}

target "beaker-kernel" {
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

version: '3'
services:
julia-base-image:
image: askem-julia-base:build
build:
context: environments/julia
command: ["/bin/true"]

jupyter:
build:
dockerfile: Dockerfile
context: .
args:
JULIA_IMAGE: askem-julia-base:build
ports:
- "8888:8888"
environment:
Expand All @@ -20,6 +27,8 @@ services:
volumes:
- ./beaker:/usr/local/share/jupyter/kernels/beaker
- .:/jupyter
depends_on:
- julia-base-image
command: ["python", "service/dev.py", "--ip", "0.0.0.0", "-y"]

data-service:
Expand Down
23 changes: 23 additions & 0 deletions environments/julia/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM julia:1.9

RUN apt update && \
apt install -y clang jupyter && \
apt clean -y

ENV JULIA_DEPOT_PATH=/usr/local/julia
ENV JULIA_PROJECT=/

WORKDIR /
COPY Project.toml Project.toml
COPY Manifest.toml Manifest.toml
RUN julia -e 'using Pkg; Pkg.instantiate()'
COPY install.jl install.jl
COPY precompile.jl precompile.jl
RUN ./install.jl docker
RUN julia -e 'using Pkg; using IJulia; IJulia.installkernel("Julia ASKEM"; julia=`julia --project=/ --threads=4 -J/ASKEM-Sysimage.so`)'

EXPOSE 8888
EXPOSE 1234

# CMD julia -JASKEM-Sysimage.so --threads=4 -e 'using Pkg; Pkg.activate("/"); using Pluto; Pluto.run(;host="0.0.0.0", port=1234, launch_browser=true)'
CMD jupyter notebook --ip 0.0.0.0 --allow-root --no-browser
Loading

0 comments on commit afabb8d

Please sign in to comment.