-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetting_started.qmd
105 lines (79 loc) · 3.73 KB
/
getting_started.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: "Get Started"
order: 1
search: false
---
Let's start with a simple example: Download, unzip and validate an INTERLIS transfer file:
## Java flavour
You need Java 11 and [_Gradle_](https://gradle.org) >= 7.6 installed on your machine.
Create a _build.gradle_ file and paste the following code into the file:
```groovy
import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download
buildscript {
repositories {
maven { url "https://jars.interlis.ch" }
maven { url "https://repo.osgeo.org/repository/release/" }
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s01.oss.sonatype.org/service/local/repositories/releases/content/" }
maven { url "https://s01.oss.sonatype.org/service/local/repositories/snapshots/content/" }
mavenCentral()
}
}
plugins {
id "de.undercouch.download" version "5.6.0"
id "ch.so.agi.gretl" version "3.0.+"
}
defaultTasks 'validateData'
tasks.register('downloadFile', Download) {
src "https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
dest file("2549.ch.so.agi.av.dm01_ch.itf.zip")
overwrite true
}
tasks.register('unzipFile', Copy) {
dependsOn 'downloadFile'
from zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
into file(".")
include "**/*.itf"
}
tasks.register('validateData', IliValidator) {
dependsOn 'unzipFile'
dataFiles = ["2549.ch.so.agi.av.dm01_ch.itf"]
}
```
To run your first GRETL job just type `gradle --rerun-tasks` in the terminal - in the same directory where you saved the _build.gradle_ file - and hit enter. On the first run, it will download a lot of dependencies (external libraries). Be patient and after downloading everything it will actually run the job and should finish with `BUILD SUCCESSFUL`.
If you want some more logging output, use `gradle --rerun-tasks -i` and you should see e.g. the well known output from [_ilivalidator_](https://github.com/claeis/ilivalidator).
## Docker flavour
You can build your very own image or just use [_docker.io/sogis/gretl:3_](https://hub.docker.com/repository/docker/sogis/gretl/general). Since the image makes use of an _init.gradle_ file, the _build.gradle_ file looks a little bit different:
```groovy
import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download
apply plugin: 'ch.so.agi.gretl'
apply plugin: 'de.undercouch.download'
defaultTasks 'validateData'
tasks.register('downloadFile', Download) {
src "https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
dest file("2549.ch.so.agi.av.dm01_ch.itf.zip")
overwrite true
}
tasks.register('unzipFile', Copy) {
dependsOn 'downloadFile'
from zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
into file(".")
include "**/*.itf"
}
tasks.register('validateData', IliValidator) {
dependsOn 'unzipFile'
dataFiles = ["2549.ch.so.agi.av.dm01_ch.itf"]
}
```
Run the following Docker command in the directory where the _build.gradle_ file is stored:
```bash
docker run -i --rm --name gretl --entrypoint="/bin/sh" -u $UID -v $PWD:/home/gradle/project -v /tmp:/home/gradle/.gradle/caches sogis/gretl:3 -c 'gretl'
```
The most important part is the bind mount of the working directory (`$PWD`) to _/home/gradle/project/_ in the image. The image expects the _build.gradle_ file in this specific directory.
If you want it a less verbose - especially if the run command gets more and more complex by adding more options - you can use e.g. a [shell script](https://raw.githubusercontent.com/sogis/gretljobs/32e1e849332eb46c9b4e480101901de17a984190/start-gretl.sh).