Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move wflow_cli code from GitLab #295

Merged
merged 8 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
/dev/
/test/data/
/tmp/

# Build files
/build/create_binaries/wflow_cli/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many files are missing EOF (blank line at end of file), indicated by the red sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this. It should be fixed now!

8 changes: 8 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build overview

## Directory tree
- `create_binaries`: folder containing code to compile the Wflow code
- `create_binaries/create_app.jl`: run PackageCompiler
- `create_binaries/precompile.jl`: run models to compile code, making wflow_cli startup faster
- `create_binaries/Project.toml`: project used to build wflow_cli
- `wflow_cli`: folder containing the code for the wflow_cli
154 changes: 154 additions & 0 deletions build/create_binaries/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.9.2"
manifest_format = "2.0"
project_hash = "c56985ee841fb30b2cb92ecec4da345315a95306"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.3"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.84.0+0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.10.2+0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.2+0"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2022.10.11"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.PackageCompiler]]
deps = ["Artifacts", "LazyArtifacts", "Libdl", "Pkg", "Printf", "RelocatableFolders", "TOML", "UUIDs"]
git-tree-sha1 = "1a6a868eb755e8ea9ecd000aa6ad175def0cc85b"
uuid = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
version = "2.1.7"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.9.2"

[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.RelocatableFolders]]
deps = ["SHA", "Scratch"]
git-tree-sha1 = "90bc7a7c96410424509e4263e277e43250c05691"
uuid = "05181044-ff0b-4ac5-8273-598c1e38db00"
version = "1.0.0"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Scratch]]
deps = ["Dates"]
git-tree-sha1 = "30449ee12237627992a99d5e30ae63e4d78cd24a"
uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.2.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.3"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.13+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.48.0+0"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "17.4.0+0"
8 changes: 8 additions & 0 deletions build/create_binaries/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
PackageCompiler = "2"
julia = "1.9"
14 changes: 14 additions & 0 deletions build/create_binaries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Create Binaries


Build the app with:

```
julia --project create_app.jl
```

<!-- Build the shared library with:
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved

```
julia --project create_lib.jl
``` -->
67 changes: 67 additions & 0 deletions build/create_binaries/add_metadata.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Add the following metadata files to the newly created build:

- Build.toml
- Project.toml
- Manifest.toml
- README.md
- LICENSE
"""
function add_metadata(project_dir, license_file, output_dir, git_repo)
# save some environment variables in a Build.toml file for debugging purposes
vars = ["BUILD_NUMBER", "BUILD_VCS_NUMBER"]
dict = Dict(var => ENV[var] for var in vars if haskey(ENV, var))
open(normpath(output_dir, "share/julia/Build.toml"), "w") do io
TOML.print(io, dict)
end

# a stripped Project.toml is already added in the same location by PackageCompiler
# however it is better to copy the original, since it includes the version and compat
cp(
normpath(project_dir, "Project.toml"),
normpath(output_dir, "share/julia/Project.toml");
force=true
)
# the Manifest.toml always gives the exact version of Wflow that was built
cp(
normpath(project_dir, "Manifest.toml"),
normpath(output_dir, "share/julia/Manifest.toml");
force=true
)

# put the LICENSE in the top level directory
cp(license_file, normpath(output_dir, "LICENSE"); force=true)
cp(normpath(project_dir, "README.md"), normpath(output_dir, "README.md"); force=true)
open(normpath(output_dir, "README.md"), "a") do io
# since the exact Wflow version may be hard to find in the Manifest.toml file
# we can also extract that information, and add it to the README.md
manifest = TOML.parsefile(normpath(project_dir, "Manifest.toml"))
if !haskey(manifest, "manifest_format")
error("Manifest.toml is in the old format, run Pkg.upgrade_manifest()")
end
julia_version = manifest["julia_version"]
wflow_entry = only(manifest["deps"]["Wflow"])
tree = wflow_entry["git-tree-sha1"]
version = wflow_entry["version"]
repo = GitRepo(git_repo)
branch = LibGit2.head(repo)
commit = LibGit2.peel(LibGit2.GitCommit, branch)
short_name = LibGit2.shortname(branch)
short_commit = string(LibGit2.GitShortHash(LibGit2.GitHash(commit), 10))
url = "https://github.com/Deltares/Wflow.jl/tree"
version_info = """

## Version

This build uses the Wflow.jl version mentioned below.

```toml
version = "$version"
git-tree-sha1 = "$tree"
commit = "$url/$short_commit"
branch = "$url/$short_name"
julia_version = "$julia_version"
```"""
println(io, version_info)
end
end
37 changes: 37 additions & 0 deletions build/create_binaries/create_app.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using PackageCompiler
using TOML
using LibGit2

# change directory to this script's location
cd(@__DIR__)

project_dir = "../wflow_cli"
license_file = "../../LICENSE"
output_dir = "wflow_cli"
git_repo = "../.."

create_app(
project_dir,
output_dir;
# map from binary name to julia function name
executables=["wflow_cli" => "julia_main"],
precompile_execution_file="precompile.jl",
filter_stdlibs=false,
force=true
)

include("add_metadata.jl")
add_metadata(project_dir, license_file, output_dir, git_repo)

# On Windows, write ribasim.cmd in the output_dir, that starts ribasim.exe.
# Since the bin dir contains a julia.exe and many DLLs that you may not want in your path,
# with this script you can put output_dir in your path instead.
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved
# if Sys.iswindows()
# cmd = raw"""
# @echo off
# "%~dp0bin\ribasim.exe" %*
# """
# open(normpath(output_dir, "ribasim.cmd"); write=true) do io
# print(io, cmd)
# end
# end
60 changes: 60 additions & 0 deletions build/create_binaries/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# this script is run during app creation to precompile the code executed in this script
# that way the app will have less latency

using Wflow
using Downloads

# this assumes that the Wflow tests have already been run, so the data has been downloaded
testdir = abspath(dirname(pathof(Wflow)), "..", "test")

# ensure test data is present
# this code is copied from runtests.jl, and is a temporary solution to get the data in place
datadir = joinpath(testdir, "data")
inputdir = joinpath(datadir, "input")
isdir(inputdir) || mkpath(inputdir)

"Download a test data file if it does not already exist"
function testdata(version, source_filename, target_filename)
target_path = joinpath(inputdir, target_filename)
base_url = "https://github.com/visr/wflow-artifacts/releases/download"
url = string(base_url, '/', string('v', version), '/', source_filename)
isfile(target_path) || Downloads.download(url, target_path)
return target_path
end

staticmaps_rhine_path = testdata(v"0.1", "staticmaps.nc", "staticmaps-rhine.nc")
staticmaps_moselle_path =
testdata(v"0.2.8", "staticmaps-moselle.nc", "staticmaps-moselle.nc")
staticmaps_lahn_path = testdata(v"0.2.1", "staticmaps-lahn.nc", "staticmaps-lahn.nc")
staticmaps_meuse_path =
testdata(v"0.2.8", "staticmaps_flex_meuse.nc", "staticmaps_flex_meuse.nc")
forcing_moselle_path = testdata(v"0.2.6", "forcing-moselle.nc", "forcing-moselle.nc")
forcing_lahn_path = testdata(v"0.2", "forcing-lahn.nc", "forcing-lahn.nc")
forcing_moselle_sed_path =
testdata(v"0.2.3", "forcing-moselle-sed.nc", "forcing-moselle-sed.nc")
staticmaps_moselle_sed_path =
testdata(v"0.2.3", "staticmaps-moselle-sed.nc", "staticmaps-moselle-sed.nc")
instates_moselle_sed_path =
testdata(v"0.2", "instates-moselle-sed.nc", "instates-moselle-sed.nc")
instates_moselle_path = testdata(v"0.2.6", "instates-moselle.nc", "instates-moselle.nc")
forcing_sbm_gw_path = testdata(
v"0.2.1",
"forcing-sbm-groundwater-part1.nc",
"forcing-sbm-groundwater-part1.nc",
)
forcing_sbm_gw_path = testdata(
v"0.2.1",
"forcing-sbm-groundwater-part2.nc",
"forcing-sbm-groundwater-part2.nc",
)
forcing_meuse_path = testdata(v"0.2.8", "forcing_meuse.nc", "forcing_meuse.nc")
staticmaps_sbm_gw_path =
testdata(v"0.2.2", "staticmaps-sbm-groundwater.nc", "staticmaps-sbm-groundwater.nc")
lake_sh_1_path = testdata(v"0.2.1", "lake_sh_1.csv", "lake_sh_1.csv")
lake_sh_2_path = testdata(v"0.2.1", "lake_sh_2.csv", "lake_sh_2.csv")
lake_hq_2_path = testdata(v"0.2.1", "lake_hq_2.csv", "lake_hq_2.csv")

Wflow.run(joinpath(testdir, "sbm_config.toml"))
Wflow.run(joinpath(testdir, "sbm_gwf_config.toml"))
Wflow.run(joinpath(testdir, "hbv_config.toml"))
Wflow.run(joinpath(testdir, "sediment_config.toml"))
3 changes: 3 additions & 0 deletions build/wflow_cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Manifest.toml
/create_app/wflow_bundle
Build.toml
11 changes: 11 additions & 0 deletions build/wflow_cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM julia:1.8.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use 1.9 here.

LABEL maintainer="Maarten Pronk <[email protected]>"

RUN apt-get update && apt-get install -y \
g++ gcc \
&& rm -rf /var/lib/apt/lists/*
ADD . /app
WORKDIR /app
RUN julia contrib/build_steps.jl
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT [ "/app/create_app/wflow_bundle/bin/wflow_cli" ]
Loading