Skip to content

Commit ce50712

Browse files
added several improvements (#107)
* static compiler start * successfully called shared library * several changes and improvements * python file is obsolete * small cleanups * improve Artifacts handling * missed libdl test dependency test run through now again * added julia style guide as formatter option * adding pre-commit hooks for auto formatting * simplified local setup using just * need to include source command so that tools are also available on first run * libdl 1.10
1 parent bb264ae commit ce50712

20 files changed

+3688
-34
lines changed

.JuliaFormatter.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# see https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options
2+
style = "blue"

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
packagecompiler/app
2+
packagecompiler/app.*
3+
.github
4+
.vscode
5+
.CondaPkg
6+
docs
7+
test
8+
tmp
9+
**/tmp
10+
AUTHORS
11+
codemeta.json
12+
Dockerfile
13+
Dockerfile.*
14+
LICENSE
15+
README.md
16+
staticcompiler/lib
17+
staticcompiler/lib.*

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*.jl.mem
44
/docs/Manifest.toml
55
/docs/build/
6-
Manifest.toml
7-
tmp/
6+
/Manifest.toml
7+
tmp
88
/packagecompiler/app
9-
/packagecompiler/app.backup
9+
*.backup
10+
.CondaPkg
11+
.vscode

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
9+
- repo: https://github.com/qiaojunfeng/pre-commit-julia-format
10+
rev: v0.2.0
11+
hooks:
12+
- id: julia-format
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
# all entries marked with `lazy = true` won't be downloaded on package installation
2+
# the rest will be downloaded
3+
# hence we can simply mark all test dependencies as lazy = true and have a single Artifacts.toml for everything
4+
15
[rqatestdata]
26
git-tree-sha1 = "1dc9d7aa975de4f5ecc652f34d6bbee706fcb7bd"
7+
# mark all test Artifacts as lazy
8+
lazy = true
39

410
[[rqatestdata.download]]
511
url = "https://github.com/EarthyScience/RQADeforestationTestData/archive/refs/tags/v2.0.tar.gz"

Dockerfile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
FROM julia:1.11-bookworm AS packagecompiled
2+
3+
RUN --mount=type=cache,target=/var/cache/apt \
4+
--mount=type=cache,target=/var/lib/apt \
5+
apt -y update && apt -y install build-essential curl ca-certificates
6+
7+
# from Debian version 13 onwards, "just" can simply be installed via apt install
8+
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
9+
10+
WORKDIR /repo
11+
COPY . .
12+
RUN --mount=type=cache,target=/root/.julia \
13+
julia --project=. -e "import Pkg; Pkg.instantiate()"
14+
RUN --mount=type=cache,target=/root/.julia \
15+
julia --project="packagecompiler" -e "import Pkg; Pkg.instantiate()"
16+
RUN --mount=type=cache,target=/root/.julia \
17+
just packagecompile
18+
19+
# having precompiled everything we can simply copy the binaries to its slim docker image
120
FROM debian:bookworm-slim
221
WORKDIR /work
3-
COPY packagecompiler/app/bin /usr/bin
4-
COPY packagecompiler/app/lib /usr/lib
5-
COPY packagecompiler/app/share /usr/share
6-
ENTRYPOINT ["RQADeforestation"]
22+
COPY --from=packagecompiled /repo/packagecompiler/app/bin /usr/bin
23+
COPY --from=packagecompiled /repo/packagecompiler/app/lib /usr/lib
24+
COPY --from=packagecompiled /repo/packagecompiler/app/share /usr/share
25+
ENTRYPOINT ["RQADeforestation"]
26+

Dockerfile.staticcompiler

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM julia:1.10
2+
3+
# installing C dependencies to build julia using StaticCompiler.jl
4+
# adapted from stackoverflow https://askubuntu.com/a/1512328
5+
RUN --mount=type=cache,target=/var/cache/apt \
6+
--mount=type=cache,target=/var/lib/apt \
7+
apt -y update && apt -y install build-essential gcc libc-dev
8+
9+
# Set work directory
10+
WORKDIR /app
11+
# Copy project files
12+
COPY . .
13+
# work inside staticcompiler subfolder
14+
WORKDIR /app/staticcompiler
15+
# Precompile packages
16+
17+
RUN --mount=type=cache,target=/root/.julia \
18+
julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.precompile()'
19+
RUN --mount=type=cache,target=/root/.julia \
20+
julia --project=. staticcompile_rqatrend.jl

Project.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,45 @@ YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
4040
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"
4141

4242
[compat]
43+
AllocCheck = "0.2.2"
44+
Aqua = "0.8.13"
4345
ArchGDAL = "0.10"
4446
ArgParse = "1"
47+
BenchmarkTools = "1.6.0"
4548
ConstructionBase = "1"
49+
Dates = "1.10"
4650
DimensionalData = "0.29"
4751
DiskArrayEngine = "0.1, 0.2"
4852
DiskArrayTools = "0.1"
4953
DiskArrays = "0.4"
5054
Distances = "0.10"
55+
Distributed = "1.10"
5156
Distributions = "0.25"
57+
Documenter = "1.12.0"
5258
Extents = "0.1"
5359
FillArrays = "1"
5460
GDAL = "1"
5561
GeoFormatTypes = "0.4"
5662
Glob = "1"
5763
KML = "0.2"
64+
Libdl = "1.10"
5865
LinearAlgebra = "1.10"
5966
LoggingExtras = "1"
6067
Missings = "1"
6168
NetCDF = "0.12"
69+
Pkg = "1.10"
6270
Proj = "1"
71+
PythonCall = "0.9.25"
72+
Random = "1.10"
6373
Rasters = "0.12,0.13, 0.14"
6474
RecurrenceAnalysis = "2"
6575
StaticArrays = "1"
76+
StaticTools = "0.8.11"
6677
Statistics = "1.10"
6778
StatsBase = "0.34"
68-
TestItems = "1.0.0"
79+
Test = "1.10"
80+
TestItemRunner = "1.0"
81+
TestItems = "1.0"
6982
TimeseriesSurrogates = "2"
7083
UnicodePlots = "3"
7184
YAXArrayBase = "0.6, 0.7"
@@ -75,11 +88,16 @@ julia = "1.11"
7588

7689
[extras]
7790
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
91+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
7892
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
93+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
7994
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
95+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
8096
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
97+
StaticTools = "86c06d3c-3f03-46de-9781-57580aa96d0a"
8198
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8299
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
100+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
83101

84102
[targets]
85-
test = ["Test", "TestItemRunner", "Pkg", "Random", "AllocCheck", "BenchmarkTools"]
103+
test = ["Test", "TestItemRunner", "Pkg", "Random", "AllocCheck", "BenchmarkTools", "Aqua", "Documenter", "StaticTools", "PythonCall", "Libdl"]

README_DEVELOPER.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Welcome to RQADeforestation.jl
2+
3+
This README collects important information for local development of the package.
4+
5+
# Local setup
6+
7+
Install `just` into your system, following its README [installation instructions](https://github.com/casey/just?tab=readme-ov-file#installation).
8+
9+
Then run
10+
```bash
11+
just init
12+
```
13+
This will for instance setup pre-commit to enforce the standard Julia styling [blue](https://github.com/JuliaDiff/BlueStyle).

justfile

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
# just configurations
2+
# setting tempdir to local path makes julia macro artifact"..." work
3+
set tempdir := "./tmp"
4+
5+
# global variables
6+
docker_image_name := "rqatest"
7+
18
default:
29
just --list
310

11+
init:
12+
#!/usr/bin/env bash
13+
set -euxo pipefail
14+
# setup pre-commit hooks via pythons uv tooling manager
15+
curl -LsSf https://astral.sh/uv/install.sh | sh
16+
source ~/.local/bin/env
17+
uv tool install pre-commit
18+
uvx pre-commit install
19+
# the julia formatting hook needs JuliaFormatter installed globally
20+
julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
21+
422
# create precompile statements used for `just packagecompile`
523
precompilestatements:
624
julia --project -e 'import Pkg; Pkg.test(julia_args=`--trace-compile=packagecompiler/precompile_statements.jl`)'
@@ -9,11 +27,11 @@ precompilestatements:
927
packagecompile:
1028
#!/usr/bin/env -S julia --project=packagecompiler
1129
using PackageCompiler
12-
if isdir("packagecompiler/app")
30+
if isdir("packagecompiler/app")
1331
rm("packagecompiler/app.backup", recursive=true, force=true)
1432
mv("packagecompiler/app", "packagecompiler/app.backup")
1533
end
16-
PackageCompiler.create_app(".", "packagecompiler/app";
34+
PackageCompiler.create_app(".", "packagecompiler/app";
1735
precompile_statements_file="packagecompiler/precompile_statements.jl",
1836
# see https://github.com/JuliaLang/PackageCompiler.jl/issues/994
1937
include_lazy_artifacts=true,
@@ -23,19 +41,50 @@ packagecompile:
2341
# lets have an easy check whether this actually worked
2442
touch("packagecompiler/app/done")
2543

26-
# test the app `packagecompiler/app/RQADeforestation` with testdata, writing data to `test/tmp/apptestdata`
27-
testapp:
44+
# downloads the Artifact test data to tmp/apptestdata
45+
download-test-data $tmpdir="tmp/apptestdata":
46+
#!/usr/bin/env -S julia --project
47+
import Pkg: Artifacts.@artifact_str
48+
testdatapath = artifact"rqatestdata/RQADeforestationTestData-2.0"
49+
testdir = ENV["tmpdir"]
50+
rm(testdir, recursive=true, force=true)
51+
mkpath(testdir)
52+
cp(testdatapath, joinpath(testdir, "in"))
53+
54+
# test the app `packagecompiler/app/RQADeforestation` with testdata, writing data to `tmp/apptestdata`
55+
test-app $tmpdir="tmp/apptestdata": (download-test-data tmpdir)
56+
#!/usr/bin/env bash
57+
set -euxo pipefail
58+
indir="$tmpdir/in"
59+
outdir="$tmpdir/out.zarr"
60+
./packagecompiler/app/bin/RQADeforestation --tile E051N018T3 --continent EU --start-date "2021-01-01" --end-date "2022-01-01" --in-dir "$indir" --out-dir "$outdir"
61+
62+
# builds the standard docker
63+
build-docker:
64+
docker build -t "{{docker_image_name}}" -f Dockerfile .
65+
66+
# tests the build docker image using the Artifact test data, writing data to `tmp/apptestdata`
67+
test-docker $tmpdir="tmp/apptestdata": (download-test-data tmpdir)
68+
#!/usr/bin/env bash
69+
set -euxo pipefail
70+
indir="$tmpdir/in"
71+
outdir="$tmpdir/out.zarr"
72+
docker run --user $(id -u):$(id -g) --rm -v "$PWD/$tmpdir":"/$tmpdir" "{{docker_image_name}}" --tile E051N018T3 --continent EU --start-date "2021-01-01" --end-date "2022-01-01" --in-dir "/$indir" --out-dir "/$outdir"
73+
74+
# compiles rqatrend to its own c-library using StaticCompiler.jl
75+
staticcompile:
2876
#!/usr/bin/env bash
29-
cd test
30-
indir="tmp/apptestdata/in"
31-
outdir="tmp/apptestdata/out.zarr"
32-
julia --project -e '
33-
import Pkg: Artifacts.@artifact_str, ensure_artifact_installed
34-
ensure_artifact_installed("rqatestdata", "Artifacts.toml")
35-
testdatapath = joinpath(artifact"rqatestdata", "RQADeforestationTestData-1.0")
36-
testdir = dirname(ARGS[1])
37-
rm(testdir, recursive=true, force=true)
38-
mkpath(testdir)
39-
cp(testdatapath, ARGS[1])
40-
' -- "$indir"
41-
../packagecompiler/app/bin/RQADeforestation --tile E051N018T3 --continent EU --in-dir "$indir" --out-dir "$outdir"
77+
set -euxo pipefail
78+
if [ -d staticcompiler/lib ]; then
79+
if [ -d staticcompiler/lib.backup ]; then
80+
rm -rf staticcompiler/lib.backup
81+
fi
82+
mv staticcompiler/lib staticcompiler/lib.backup
83+
fi
84+
# using progress plain is important as staticcompiler.jl
85+
# outputs warnings instead of errors if things may not work
86+
docker build --progress=plain -t temp-image -f Dockerfile.staticcompiler .
87+
docker create --name temp-container temp-image
88+
docker cp temp-container:/app/staticcompiler/lib "$PWD/staticcompiler/lib"
89+
docker rm temp-container
90+
docker rmi temp-image

0 commit comments

Comments
 (0)