From 452f6465e412ff21f196206e825ebb0e77a41a19 Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Mon, 9 Dec 2024 10:58:24 +0000 Subject: [PATCH] add julia example --- julia/Dockerfile | 14 ++++++++++++++ julia/README.md | 7 +++++++ julia/src/install_packages.jl | 4 ++++ julia/src/plot_example.jl | 9 +++++++++ julia/src/run_test.sh | 7 +++++++ 5 files changed, 41 insertions(+) create mode 100644 julia/Dockerfile create mode 100644 julia/README.md create mode 100644 julia/src/install_packages.jl create mode 100644 julia/src/plot_example.jl create mode 100644 julia/src/run_test.sh diff --git a/julia/Dockerfile b/julia/Dockerfile new file mode 100644 index 0000000..52f646c --- /dev/null +++ b/julia/Dockerfile @@ -0,0 +1,14 @@ +FROM docker.io/julia:latest@sha256:32b91d5ff59276c5986b9b35b76b232651d71e8273dcf22ead1593a960ce816e + +ENV JULIA_DEPOT_PATH=/home/ces-user/.julia + +USER root +RUN mkdir /safe_data /safe_outputs /scratch + +WORKDIR /app + +COPY --chmod=0755 src/* . + +RUN julia /app/install_packages.jl + +ENTRYPOINT ["/app/run_test.sh"] diff --git a/julia/README.md b/julia/README.md new file mode 100644 index 0000000..89e5b2e --- /dev/null +++ b/julia/README.md @@ -0,0 +1,7 @@ +# TRE Julia example + +## Notes + +This example is structured as a script `plot_example.jl` that generates a plot, and a bash script `run_test.sh` that executes the plot script and saves the output to `/safe_outputs`. Both files are found under the `src` directory, which is copied inside the container in the `Dockerfile`. + +The required packages are installed using the `install_packages.jl` script. Note that it is important to set the `ENV JULIA_DEPOT_PATH` to ensure the packages are installed in the same environment as where the scripts are to be executed. diff --git a/julia/src/install_packages.jl b/julia/src/install_packages.jl new file mode 100644 index 0000000..e76886d --- /dev/null +++ b/julia/src/install_packages.jl @@ -0,0 +1,4 @@ +using Pkg + +Pkg.add(["GR", "Plots"]) +Pkg.precompile() diff --git a/julia/src/plot_example.jl b/julia/src/plot_example.jl new file mode 100644 index 0000000..4fd60b2 --- /dev/null +++ b/julia/src/plot_example.jl @@ -0,0 +1,9 @@ +using Plots + +# plot some data +plot([cumsum(rand(500) .- 0.5), cumsum(rand(500) .- 0.5)]) + +# save the current figure +savefig("plots.svg") +# .eps, .pdf, & .png are also supported +# we used svg here because it respects the width and height specified above diff --git a/julia/src/run_test.sh b/julia/src/run_test.sh new file mode 100644 index 0000000..5095f86 --- /dev/null +++ b/julia/src/run_test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Run example script +julia plot_example.jl + +# Copy output to /safe_outputs +mv *.svg /safe_outputs