Skip to content

Commit

Permalink
add julia example
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Dec 9, 2024
1 parent 287fb30 commit 452f646
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions julia/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions julia/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions julia/src/install_packages.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Pkg

Pkg.add(["GR", "Plots"])
Pkg.precompile()
9 changes: 9 additions & 0 deletions julia/src/plot_example.jl
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions julia/src/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Run example script
julia plot_example.jl

# Copy output to /safe_outputs
mv *.svg /safe_outputs

0 comments on commit 452f646

Please sign in to comment.