From 122aa59ffc5e61a3a65d610bcb4f0586c5afb389 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Mon, 9 Sep 2024 08:05:43 +0200 Subject: [PATCH 01/16] add module for labs 1 + 2 --- content/en/docs/01/_index.md | 27 +++++------ go.sum | 1 + mod/.gitattributes | 4 ++ mod/.gitignore | 4 ++ mod/README.md | 4 ++ mod/dagger.json | 5 ++ mod/go.mod | 48 ++++++++++++++++++++ mod/go.sum | 87 +++++++++++++++++++++++++++++++++++ mod/main.go | 88 ++++++++++++++++++++++++++++++++++++ 9 files changed, 255 insertions(+), 13 deletions(-) create mode 100644 mod/.gitattributes create mode 100644 mod/.gitignore create mode 100644 mod/README.md create mode 100644 mod/dagger.json create mode 100644 mod/go.mod create mode 100644 mod/go.sum create mode 100644 mod/main.go diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index 6999351..f668943 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -61,7 +61,7 @@ It is similar to the [MvnRepository](https://mvnrepository.com/). The MvnReposit The most common way to call Dagger Functions is using the `dagger` CLI: ```bash -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello +dagger call --mod ./mod hello ``` The `dagger` CLI first loads a `hello` module directly from its [GitHub repository](https://github.com/shykes/daggerverse/tree/main/hello) and then executes the `Hello()` function from that module. @@ -69,7 +69,7 @@ The `dagger` CLI first loads a `hello` module directly from its [GitHub reposito {{% alert title="Note" color="primary" %}} Explanation to the dagger CLI call.\ `dagger call` : execute the dagger CLI `call` command\ -`--mod github.com/shykes/daggerverse/hello@v0.3.0` : `call` command option to use the `hello` module (load its functions)\ +`--mod ./mod` : `call` command option to use the `hello` module (load its functions)\ `hello` : execute the `hello` function {{% /alert %}} @@ -90,14 +90,14 @@ If you are curious, what other [Functions](https://docs.dagger.io/api/reference/ or you can explore its functions using: ```bash -dagger functions --mod github.com/shykes/daggerverse/hello@v0.3.0 +dagger functions --mod ./mod ``` In this particular case, there aren't any other functions :( - but what about additional arguments of the `Hello()` function? Let's find out: ```bash -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --help +dagger call --mod ./mod hello --help ``` {{% alert title="Note" color="primary" %}} @@ -116,7 +116,7 @@ Dagger also defines powerful core types: [Container](https://docs.dagger.io/api/ To pass a String argument to a Dagger Function, append the corresponding flag to the dagger call command, followed by the string value: ```bash -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --name=sun +dagger call --mod ./mod hello --name=sun ``` @@ -131,24 +131,24 @@ True: ```bash # explicit -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --shout=true +dagger call --mod ./mod hello --shout=true ``` ```bash # implicit -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --shout +dagger call --mod ./mod hello --shout ``` False: ```bash # explicit -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --shout=false +dagger call --mod ./mod hello --shout=false ``` ```bash # implicit -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello +dagger call --mod ./mod hello ``` @@ -161,12 +161,12 @@ and pass the resulting `Directory` object as argument to the Dagger Function. Filesystem path: ```bash -dagger call --mod github.com/softwaredevelop/daggerverse/shellcheck@3872d4fb4e5b0e8a2844b2148ea00c076396a53b check --source=/usr/bin +dagger call --mod ./mod ls --dir . ``` Git repository: ```bash -dagger call --mod github.com/softwaredevelop/daggerverse/shellcheck@3872d4fb4e5b0e8a2844b2148ea00c076396a53b check --source=https://github.com/puzzle/action-owasp-dependecy-track-check +dagger call --mod ./mod ls --dir https://github.com/puzzle/action-owasp-dependecy-track-check ``` @@ -177,8 +177,9 @@ Same as directories, you can pass a Container argument. To do so, add the corres The CLI will dynamically pull the image, and pass the resulting `Container` object as argument to the Dagger Function. ```bash -dagger call --mod github.com/jpadams/daggerverse/trivy@v0.4.0 scan-container --ctr=alpine:latest +dagger --mod ./mod call os --ctr=alpine:latest ``` + {{% alert title="Note" color="primary" %}} It is important to know that in Dagger, a `Container` object is not merely a string referencing an image on a remote registry. It is the **actual state of a container**, managed by the Dagger Engine, and passed to a Dagger Function's code as if it were just another variable! @@ -230,7 +231,7 @@ Call the `Hello()` function of `github.com/shykes/daggerverse/hello@v0.3.0` so t {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/shykes/daggerverse/hello@v0.3.0 hello --giant --greeting=Welcome --name=sunshine +dagger call --mod ./mod hello --giant --greeting=Welcome --name=sunshine ``` {{% /details %}} diff --git a/go.sum b/go.sum index 41aebbc..6d56004 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ github.com/acend/docsy-plus v1.0.0 h1:Ag2xQv15gwqPnsvWSBP8GKAnRrctVkADwaG3Qymt5w github.com/acend/docsy-plus v1.0.0/go.mod h1:YDHqf+DCZcx5HvKGzaBluPmLfgHQ2GKkYjggvF98jR4= github.com/acend/docsy-plus v1.1.0 h1:MgHPR3YRPrJSWtMS3eQKJivdCEwFHCIKD0jChsZS3SM= github.com/acend/docsy-plus v1.1.0/go.mod h1:LPbI0Ljrhzt0YHUg8qozWVUXjrMVI1cFVPn3TyQxbcY= +github.com/acend/docsy-plus v1.2.0 h1:MJaMdkqXU6ws7A+6Lzhx4qGvncifund3NF44Tzs7iVM= github.com/acend/docsy-plus v1.2.0/go.mod h1:LPbI0Ljrhzt0YHUg8qozWVUXjrMVI1cFVPn3TyQxbcY= github.com/google/docsy v0.4.0 h1:Eyt2aiDC1fnw/Qq/9xnIqUU5n5Yyk4c8gX3nBDdTv/4= github.com/google/docsy v0.4.0/go.mod h1:vJjGkHNaw9bO42gpFTWwAUzHZWZEVlK46Kx7ikY5c7Y= diff --git a/mod/.gitattributes b/mod/.gitattributes new file mode 100644 index 0000000..3a45493 --- /dev/null +++ b/mod/.gitattributes @@ -0,0 +1,4 @@ +/dagger.gen.go linguist-generated +/internal/dagger/** linguist-generated +/internal/querybuilder/** linguist-generated +/internal/telemetry/** linguist-generated diff --git a/mod/.gitignore b/mod/.gitignore new file mode 100644 index 0000000..7ebabcc --- /dev/null +++ b/mod/.gitignore @@ -0,0 +1,4 @@ +/dagger.gen.go +/internal/dagger +/internal/querybuilder +/internal/telemetry diff --git a/mod/README.md b/mod/README.md new file mode 100644 index 0000000..31ef482 --- /dev/null +++ b/mod/README.md @@ -0,0 +1,4 @@ +# Dagger Module fot the Dagger techlab + +Helper module for the [Dagger Techlab](https://dagger-techlab.puzzle.ch/) + diff --git a/mod/dagger.json b/mod/dagger.json new file mode 100644 index 0000000..3fa71ad --- /dev/null +++ b/mod/dagger.json @@ -0,0 +1,5 @@ +{ + "name": "mod", + "sdk": "go", + "engineVersion": "v0.12.7" +} diff --git a/mod/go.mod b/mod/go.mod new file mode 100644 index 0000000..60fc4e6 --- /dev/null +++ b/mod/go.mod @@ -0,0 +1,48 @@ +module dagger/mod + +go 1.23.0 + +require ( + github.com/99designs/gqlgen v0.17.49 + github.com/Khan/genqlient v0.7.0 + github.com/vektah/gqlparser/v2 v2.5.16 + go.opentelemetry.io/otel v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 + go.opentelemetry.io/otel/log v0.3.0 + go.opentelemetry.io/otel/sdk v1.27.0 + go.opentelemetry.io/otel/sdk/log v0.3.0 + go.opentelemetry.io/otel/trace v1.27.0 + go.opentelemetry.io/proto/otlp v1.3.1 + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa + golang.org/x/sync v0.7.0 + google.golang.org/grpc v1.64.0 +) + +require ( + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/sosodev/duration v1.3.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect + go.opentelemetry.io/otel/metric v1.27.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect + google.golang.org/protobuf v1.34.1 // indirect +) + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 + +replace go.opentelemetry.io/otel/log => go.opentelemetry.io/otel/log v0.3.0 + +replace go.opentelemetry.io/otel/sdk/log => go.opentelemetry.io/otel/sdk/log v0.3.0 diff --git a/mod/go.sum b/mod/go.sum new file mode 100644 index 0000000..6fea81b --- /dev/null +++ b/mod/go.sum @@ -0,0 +1,87 @@ +github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ= +github.com/99designs/gqlgen v0.17.49/go.mod h1:tC8YFVZMed81x7UJ7ORUwXF4Kn6SXuucFqQBhN8+BU0= +github.com/Khan/genqlient v0.7.0 h1:GZ1meyRnzcDTK48EjqB8t3bcfYvHArCUUvgOwpz1D4w= +github.com/Khan/genqlient v0.7.0/go.mod h1:HNyy3wZvuYwmW3Y7mkoQLZsa/R5n5yIRajS1kPBvSFM= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= +github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8= +github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 h1:oM0GTNKGlc5qHctWeIGTVyda4iFFalOzMZ3Ehj5rwB4= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88/go.mod h1:JGG8ebaMO5nXOPnvKEl+DiA4MGwFjCbjsxT1WHIEBPY= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 h1:ccBrA8nCY5mM0y5uO7FT0ze4S0TuFcWdDB2FxGMTjkI= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0/go.mod h1:/9pb6634zi2Lk8LYg9Q0X8Ar6jka4dkFOylBLbVQPCE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY= +go.opentelemetry.io/otel/log v0.3.0 h1:kJRFkpUFYtny37NQzL386WbznUByZx186DpEMKhEGZs= +go.opentelemetry.io/otel/log v0.3.0/go.mod h1:ziCwqZr9soYDwGNbIL+6kAvQC+ANvjgG367HVcyR/ys= +go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= +go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= +go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= +go.opentelemetry.io/otel/sdk/log v0.3.0 h1:GEjJ8iftz2l+XO1GF2856r7yYVh74URiF9JMcAacr5U= +go.opentelemetry.io/otel/sdk/log v0.3.0/go.mod h1:BwCxtmux6ACLuys1wlbc0+vGBd+xytjmjajwqqIul2g= +go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= +go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mod/main.go b/mod/main.go new file mode 100644 index 0000000..2afefe4 --- /dev/null +++ b/mod/main.go @@ -0,0 +1,88 @@ +// A module to support the Puzzle dagger techlab. +// +// This module has been generated via dagger init --sdk go. +// +// The functions are used inside the hands-on lab: https://dagger-techlab.puzzle.ch/ + +package main + +import ( + "context" + "dagger/mod/internal/dagger" + "fmt" + "strings" +) + +var defaultFigletContainer = dag. + Container(). + From("alpine:latest"). + WithExec([]string{ + "apk", "add", "figlet", + }) + +type Mod struct{} + +// Say hello to the world! +// Code taken from https://github.com/shykes/hello. Thanks! +func (hello *Mod) Hello( + ctx context.Context, + // Change the greeting + // +optional + // +default="hello" + greeting string, + // Change the name + // +optional + // +default="world" + name string, + // Encode the message in giant multi-character letters + // +optional + giant bool, + // Make the message uppercase, and add more exclamation points + // +optional + shout bool, + // Custom container for running the figlet tool + // +optional + figletContainer *dagger.Container, +) (string, error) { + message := fmt.Sprintf("%s, %s!", greeting, name) + if shout { + message = strings.ToUpper(message) + "!!!!!" + } + if giant { + // Run 'figlet' in a container to produce giant letters + ctr := figletContainer + if ctr == nil { + ctr = defaultFigletContainer + } + return ctr. + WithoutEntrypoint(). // clear the entrypoint to make sure 'figlet' is executed + WithExec([]string{"figlet", message}). + Stdout(ctx) + } + return message, nil +} + +// Returns the files of the directory +func (m *Mod) Ls( + ctx context.Context, + // directory to list it's files + dir *dagger.Directory, + ) (string, error) { + return dag.Container(). + From("alpine:latest"). + WithMountedDirectory("/mnt", dir). + WithWorkdir("/mnt"). + WithExec([]string{"ls", "-l", "."}). + Stdout(ctx) +} + +// Returns the operating system of the container +func (m *Mod) Os( + ctx context.Context, + // container to get is's OS + ctr *dagger.Container, + ) (string, error) { + return ctr. + WithExec([]string{"cat", "/etc/os-release"}). + Stdout(ctx) +} From 4ebcf6cde7b70ec6e0fe6614c6d1b89c2c402d37 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Thu, 19 Sep 2024 20:35:07 +0200 Subject: [PATCH 02/16] update module to v0.13.1 --- mod/dagger.json | 3 ++- mod/go.mod | 20 ++++++++++---------- mod/go.sum | 40 ++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/mod/dagger.json b/mod/dagger.json index 3fa71ad..9b8e4a0 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -1,5 +1,6 @@ { "name": "mod", "sdk": "go", - "engineVersion": "v0.12.7" + "source": ".", + "engineVersion": "v0.13.1" } diff --git a/mod/go.mod b/mod/go.mod index 60fc4e6..4872437 100644 --- a/mod/go.mod +++ b/mod/go.mod @@ -17,26 +17,26 @@ require ( go.opentelemetry.io/otel/trace v1.27.0 go.opentelemetry.io/proto/otlp v1.3.1 golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa - golang.org/x/sync v0.7.0 - google.golang.org/grpc v1.64.0 + golang.org/x/sync v0.8.0 + google.golang.org/grpc v1.66.1 ) require ( github.com/cenkalti/backoff/v4 v4.3.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/sosodev/duration v1.3.1 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect go.opentelemetry.io/otel/metric v1.27.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect - google.golang.org/protobuf v1.34.1 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/protobuf v1.34.2 // indirect ) replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 diff --git a/mod/go.sum b/mod/go.sum index 6fea81b..40f88b0 100644 --- a/mod/go.sum +++ b/mod/go.sum @@ -10,16 +10,16 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -63,22 +63,22 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ= -google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM= +google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From e6aad328bf32f1c31154625792a90e061ccbd295 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Tue, 24 Sep 2024 19:53:18 +0200 Subject: [PATCH 03/16] implement secret example with module --- .gitignore | 1 + content/en/docs/01/_index.md | 23 ++++++++++++++--------- mod/main.go | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index ef1712f..cd5e63e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Thumbs.db .sass-cache npm-debug.log node_modules +secret.txt builds public .env diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index f668943..f4aba40 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -194,16 +194,22 @@ writing them into the filesystem of containers you're building, or inserting the To pass a Secret to a Dagger Function, source it from a host environment variable `env:`, the host filesystem `file:`, or a host command `cmd:`. Here is an example of passing a GitHub access token from an environment variable named `GITHUB_TOKEN` to a Dagger Function. + The Dagger Function uses the token to query the GitHub CLI for a list of issues in the Dagger open-source repository: ```bash dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=env:GITHUB_TOKEN --cmd="issue list --repo=dagger/dagger" ``` +{{% alert title="Note" color="primary" %}} +This is only an example, you don't have to make it run. +{{% /alert %}} + ## Task {{% param sectionnumber %}}.1: Explore a module Explore the `github.com/purpleclay/daggerverse/ponysay@v0.1.0` module. + Make it return the phrase `Dagger puts a smile on my face!`. {{% details title="show hint" mode-switcher="normalexpertmode" %}} @@ -227,7 +233,7 @@ dagger call --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 say --msg="Da ## Task {{% param sectionnumber %}}.2: Make use of multiple arguments -Call the `Hello()` function of `github.com/shykes/daggerverse/hello@v0.3.0` so that it returns the phrase `Welcome, sunshine!` in ASCII-art. +Call the `Hello()` function of `github.com/shykes/daggerverse/hello@v0.3.0` so that it returns the phrase `Welcome, sunshine!` in ASCII-art (giant letters). {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash @@ -238,17 +244,16 @@ dagger call --mod ./mod hello --giant --greeting=Welcome --name=sunshine ## Task {{% param sectionnumber %}}.3: Pass a secret -Set and replace the `--token` value in the following call with a secret using an environment variable +Set the `--password` value in the following call with a secret, using an environment variable, containing the password "MySuperSecret". ```bash -dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=visible --cmd="issue list --repo=dagger/dagger" +dagger call --mod ./mod unlock --password=visible ``` - {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -export SECRET=invisible -dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=env:SECRET --cmd="issue list --repo=dagger/dagger" +export SECRET=MySuperSecret +dagger call --mod ./mod unlock --password env:SECRET ``` {{% /details %}} @@ -257,7 +262,7 @@ or using a file {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash echo $SECRET > secret.txt -dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=file:./secret.txt --cmd="issue list --repo=dagger/dagger" +dagger call --mod ./mod unlock --password file:./secret.txt ``` {{% /details %}} @@ -265,10 +270,10 @@ or using a command {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=cmd:"head -c10 /dev/random | base64" --cmd="issue list --repo=dagger/dagger" +dagger call --mod ./mod unlock --password cmd:"echo $SECRET" ``` {{% /details %}} {{% alert title="Note" color="primary" %}} -Unless you provide a working token, the function execution will fail with an `HTTP 401` error. +Unless you provide the right password, the function execution will fail with an error. {{% /alert %}} diff --git a/mod/main.go b/mod/main.go index 2afefe4..484daa4 100644 --- a/mod/main.go +++ b/mod/main.go @@ -1,7 +1,5 @@ // A module to support the Puzzle dagger techlab. // -// This module has been generated via dagger init --sdk go. -// // The functions are used inside the hands-on lab: https://dagger-techlab.puzzle.ch/ package main @@ -9,6 +7,7 @@ package main import ( "context" "dagger/mod/internal/dagger" + "errors" "fmt" "strings" ) @@ -86,3 +85,20 @@ func (m *Mod) Os( WithExec([]string{"cat", "/etc/os-release"}). Stdout(ctx) } + +// Returns the answer to everything when the password is right. +func (m *Mod) Unlock( + ctx context.Context, + // container to get is's OS + password *dagger.Secret, + ) (string, error) { + passwordText, err := password.Plaintext(ctx) + if err != nil { + return "", err + } + passwordTextClean := strings.TrimSpace(passwordText) + if passwordTextClean == "MySuperSecret" { + return "You unlocked the secret. The answer is 42!", nil + } + return "", errors.New("Nice try ;-) Provide right password to unlock the secret.") +} From 01d35cba47c2453e057f5d492621d3773df28220 Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Mon, 14 Oct 2024 12:14:09 +0200 Subject: [PATCH 04/16] Add hello module as dependency --- mod/dagger.json | 6 ++++++ mod/main.go | 25 +++++-------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/mod/dagger.json b/mod/dagger.json index 9b8e4a0..a4c588a 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -1,6 +1,12 @@ { "name": "mod", "sdk": "go", + "dependencies": [ + { + "name": "hello", + "source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d" + } + ], "source": ".", "engineVersion": "v0.13.1" } diff --git a/mod/main.go b/mod/main.go index 484daa4..1a96491 100644 --- a/mod/main.go +++ b/mod/main.go @@ -8,7 +8,6 @@ import ( "context" "dagger/mod/internal/dagger" "errors" - "fmt" "strings" ) @@ -22,8 +21,8 @@ var defaultFigletContainer = dag. type Mod struct{} // Say hello to the world! -// Code taken from https://github.com/shykes/hello. Thanks! -func (hello *Mod) Hello( +// Calls external (sub-)module https://github.com/shykes/hello +func (m *Mod) Hello( ctx context.Context, // Change the greeting // +optional @@ -42,25 +41,11 @@ func (hello *Mod) Hello( // Custom container for running the figlet tool // +optional figletContainer *dagger.Container, -) (string, error) { - message := fmt.Sprintf("%s, %s!", greeting, name) - if shout { - message = strings.ToUpper(message) + "!!!!!" - } - if giant { - // Run 'figlet' in a container to produce giant letters - ctr := figletContainer - if ctr == nil { - ctr = defaultFigletContainer - } - return ctr. - WithoutEntrypoint(). // clear the entrypoint to make sure 'figlet' is executed - WithExec([]string{"figlet", message}). - Stdout(ctx) - } - return message, nil + ) (string, error) { + return dag.Hello().Hello(ctx,dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) } + // Returns the files of the directory func (m *Mod) Ls( ctx context.Context, From 4e8ab2b77fcc87dc8f011711a3362f3f553fb75e Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Mon, 14 Oct 2024 14:06:20 +0200 Subject: [PATCH 05/16] Add openssh-server module as dependency --- mod/dagger.json | 4 ++++ mod/main.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mod/dagger.json b/mod/dagger.json index a4c588a..e1ef059 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -2,6 +2,10 @@ "name": "mod", "sdk": "go", "dependencies": [ + { + "name": "openssh-server", + "source": "github.com/sagikazarmark/daggerverse/openssh-server@c767a220a5f507555fd415e9c9729234589fd95c" + }, { "name": "hello", "source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d" diff --git a/mod/main.go b/mod/main.go index 1a96491..62d1c4a 100644 --- a/mod/main.go +++ b/mod/main.go @@ -42,10 +42,9 @@ func (m *Mod) Hello( // +optional figletContainer *dagger.Container, ) (string, error) { - return dag.Hello().Hello(ctx,dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) + return dag.Hello().Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) } - // Returns the files of the directory func (m *Mod) Ls( ctx context.Context, @@ -87,3 +86,13 @@ func (m *Mod) Unlock( } return "", errors.New("Nice try ;-) Provide right password to unlock the secret.") } + +// Return a service that runs the OpenSSH server. +// Calls external (sub-)module https://github.com/sagikazarmark/daggerverse/openssh-server +func (m *Mod) Service( + // +optional + // +default=22 + port int, + ) *dagger.Service { + return dag.OpensshServer().Service(dagger.OpensshServerServiceOpts{Port: port}) +} From 1dd36324c57564f3591cee4a125659544671f268 Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Mon, 14 Oct 2024 16:44:47 +0200 Subject: [PATCH 06/16] Add ruff module as dependency --- mod/dagger.json | 8 ++++++-- mod/main.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mod/dagger.json b/mod/dagger.json index e1ef059..c3825f7 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -3,12 +3,16 @@ "sdk": "go", "dependencies": [ { - "name": "openssh-server", - "source": "github.com/sagikazarmark/daggerverse/openssh-server@c767a220a5f507555fd415e9c9729234589fd95c" + "name": "ruff", + "source": "github.com/dagger/dagger/dev/ruff@d9a15262229f1dba0aa53dbd0216908438331995" }, { "name": "hello", "source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d" + }, + { + "name": "openssh-server", + "source": "github.com/sagikazarmark/daggerverse/openssh-server@c767a220a5f507555fd415e9c9729234589fd95c" } ], "source": ".", diff --git a/mod/main.go b/mod/main.go index 62d1c4a..607d5d3 100644 --- a/mod/main.go +++ b/mod/main.go @@ -20,6 +20,11 @@ var defaultFigletContainer = dag. type Mod struct{} +type LintRun struct { + // +private + Source *dagger.Directory +} + // Say hello to the world! // Calls external (sub-)module https://github.com/shykes/hello func (m *Mod) Hello( @@ -96,3 +101,19 @@ func (m *Mod) Service( ) *dagger.Service { return dag.OpensshServer().Service(dagger.OpensshServerServiceOpts{Port: port}) } + +// Lint a Python codebase +// Calls external (sub-)module https://github.com/dagger/dagger/modules/ruff +func (m *Mod) Lint( + source *dagger.Directory, +) *LintRun { + return &LintRun{ + Source: source, + } +} + +// Return a JSON report file for this run +func (run LintRun) Report() *dagger.File { + return dag.Ruff().Lint(run.Source).Report() +} + From f138845180d6f2893ce4f6b8e5690d3d4c0c3bae Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 08:39:12 +0200 Subject: [PATCH 07/16] Add wolfi module as dependency --- mod/dagger.json | 12 ++++++++---- mod/main.go | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/mod/dagger.json b/mod/dagger.json index c3825f7..2509b44 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -2,10 +2,6 @@ "name": "mod", "sdk": "go", "dependencies": [ - { - "name": "ruff", - "source": "github.com/dagger/dagger/dev/ruff@d9a15262229f1dba0aa53dbd0216908438331995" - }, { "name": "hello", "source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d" @@ -13,6 +9,14 @@ { "name": "openssh-server", "source": "github.com/sagikazarmark/daggerverse/openssh-server@c767a220a5f507555fd415e9c9729234589fd95c" + }, + { + "name": "ruff", + "source": "github.com/dagger/dagger/dev/ruff@d9a15262229f1dba0aa53dbd0216908438331995" + }, + { + "name": "wolfi", + "source": "github.com/shykes/daggerverse/wolfi@3338120927f8e291c4780de691ef63a7c9d825c0" } ], "source": ".", diff --git a/mod/main.go b/mod/main.go index 607d5d3..d8352b0 100644 --- a/mod/main.go +++ b/mod/main.go @@ -26,7 +26,7 @@ type LintRun struct { } // Say hello to the world! -// Calls external (sub-)module https://github.com/shykes/hello +// Calls external module https://github.com/shykes/hello func (m *Mod) Hello( ctx context.Context, // Change the greeting @@ -47,7 +47,8 @@ func (m *Mod) Hello( // +optional figletContainer *dagger.Container, ) (string, error) { - return dag.Hello().Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) + return dag.Hello(). + Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) } // Returns the files of the directory @@ -67,7 +68,7 @@ func (m *Mod) Ls( // Returns the operating system of the container func (m *Mod) Os( ctx context.Context, - // container to get is's OS + // container to get it's OS ctr *dagger.Container, ) (string, error) { return ctr. @@ -78,7 +79,6 @@ func (m *Mod) Os( // Returns the answer to everything when the password is right. func (m *Mod) Unlock( ctx context.Context, - // container to get is's OS password *dagger.Secret, ) (string, error) { passwordText, err := password.Plaintext(ctx) @@ -93,17 +93,18 @@ func (m *Mod) Unlock( } // Return a service that runs the OpenSSH server. -// Calls external (sub-)module https://github.com/sagikazarmark/daggerverse/openssh-server +// Calls external module https://github.com/sagikazarmark/daggerverse/tree/main/openssh-server func (m *Mod) Service( // +optional // +default=22 port int, ) *dagger.Service { - return dag.OpensshServer().Service(dagger.OpensshServerServiceOpts{Port: port}) + return dag.OpensshServer(). + Service(dagger.OpensshServerServiceOpts{Port: port}) } // Lint a Python codebase -// Calls external (sub-)module https://github.com/dagger/dagger/modules/ruff +// Calls external module https://github.com/dagger/dagger/tree/main/modules/ruff func (m *Mod) Lint( source *dagger.Directory, ) *LintRun { @@ -114,6 +115,14 @@ func (m *Mod) Lint( // Return a JSON report file for this run func (run LintRun) Report() *dagger.File { - return dag.Ruff().Lint(run.Source).Report() + return dag.Ruff(). + Lint(run.Source). + Report() } +// Build a Wolfi Linux container +// https://github.com/shykes/daggerverse/tree/main/wolfi +func (m *Mod) Container() *dagger.Container { + return dag.Wolfi(). + Container() +} From 1f0c80bc6153681d5c906c995a84edb3d5c7822f Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 09:15:24 +0200 Subject: [PATCH 08/16] Update lab 1 --- content/en/docs/01/_index.md | 14 ++++++++------ mod/main.go | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index f4aba40..40c696e 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -64,12 +64,12 @@ The most common way to call Dagger Functions is using the `dagger` CLI: dagger call --mod ./mod hello ``` -The `dagger` CLI first loads a `hello` module directly from its [GitHub repository](https://github.com/shykes/daggerverse/tree/main/hello) and then executes the `Hello()` function from that module. +The `dagger` CLI first loads the modules dependencies and then executes the local modules `Hello()` function. {{% alert title="Note" color="primary" %}} Explanation to the dagger CLI call.\ `dagger call` : execute the dagger CLI `call` command\ -`--mod ./mod` : `call` command option to use the `hello` module (load its functions)\ +`--mod ./mod` : `call` command option to use the specified local module (load its functions)\ `hello` : execute the `hello` function {{% /alert %}} @@ -80,20 +80,22 @@ hello, world! ``` {{% alert title="Note" color="primary" %}} -Due to Daggers caching mechanism, subsequent calls will be executed much faster! +The first execution will take a considerable amount of time, as the module depends on several other modules +which have to be downloaded.\ +For this reason and thanks to Daggers caching mechanism, subsequent calls will be executed much faster! {{% /alert %}} ### Exploring Modules and Functions -If you are curious, what other [Functions](https://docs.dagger.io/api/reference/#definition-Function) are available on this [Module](https://docs.dagger.io/api/reference/#definition-Module), you can either have a look at its [source code](https://github.com/shykes/daggerverse/blob/main/hello/main.go) +If you are curious, what other [Functions](https://docs.dagger.io/api/reference/#definition-Function) are available on this module, you can either have a look at its [source code](https://github.com/puzzle/dagger-techlab/blob/main/mod/main.go) or you can explore its functions using: ```bash dagger functions --mod ./mod ``` -In this particular case, there aren't any other functions :( - but what about additional arguments of the `Hello()` function? +And what about additional arguments of the `Hello()` function? Let's find out: ```bash @@ -233,7 +235,7 @@ dagger call --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 say --msg="Da ## Task {{% param sectionnumber %}}.2: Make use of multiple arguments -Call the `Hello()` function of `github.com/shykes/daggerverse/hello@v0.3.0` so that it returns the phrase `Welcome, sunshine!` in ASCII-art (giant letters). +Call the `Hello()` function so that it returns the phrase `Welcome, sunshine!` in ASCII-art (giant letters). {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash diff --git a/mod/main.go b/mod/main.go index d8352b0..db82bf3 100644 --- a/mod/main.go +++ b/mod/main.go @@ -26,7 +26,7 @@ type LintRun struct { } // Say hello to the world! -// Calls external module https://github.com/shykes/hello +// Calls external module Hello https://github.com/shykes/hello func (m *Mod) Hello( ctx context.Context, // Change the greeting @@ -76,7 +76,7 @@ func (m *Mod) Os( Stdout(ctx) } -// Returns the answer to everything when the password is right. +// Returns the answer to everything when the password is right func (m *Mod) Unlock( ctx context.Context, password *dagger.Secret, @@ -92,8 +92,8 @@ func (m *Mod) Unlock( return "", errors.New("Nice try ;-) Provide right password to unlock the secret.") } -// Return a service that runs the OpenSSH server. -// Calls external module https://github.com/sagikazarmark/daggerverse/tree/main/openssh-server +// Return a service that runs an OpenSSH server +// Calls external module OpensshServer https://github.com/sagikazarmark/daggerverse/tree/main/openssh-server func (m *Mod) Service( // +optional // +default=22 @@ -104,7 +104,7 @@ func (m *Mod) Service( } // Lint a Python codebase -// Calls external module https://github.com/dagger/dagger/tree/main/modules/ruff +// Calls external module Ruff https://github.com/dagger/dagger/tree/main/modules/ruff func (m *Mod) Lint( source *dagger.Directory, ) *LintRun { @@ -121,7 +121,7 @@ func (run LintRun) Report() *dagger.File { } // Build a Wolfi Linux container -// https://github.com/shykes/daggerverse/tree/main/wolfi +// Calls external module Wolfi https://github.com/shykes/daggerverse/tree/main/wolfi func (m *Mod) Container() *dagger.Container { return dag.Wolfi(). Container() From ff534dad020e4dc57188fd5b194424ac6032c382 Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 10:28:27 +0200 Subject: [PATCH 09/16] Streamline docu --- mod/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/main.go b/mod/main.go index db82bf3..a28e271 100644 --- a/mod/main.go +++ b/mod/main.go @@ -92,9 +92,9 @@ func (m *Mod) Unlock( return "", errors.New("Nice try ;-) Provide right password to unlock the secret.") } -// Return a service that runs an OpenSSH server +// Returns a service that runs an OpenSSH server // Calls external module OpensshServer https://github.com/sagikazarmark/daggerverse/tree/main/openssh-server -func (m *Mod) Service( +func (m *Mod) SshService( // +optional // +default=22 port int, @@ -113,7 +113,7 @@ func (m *Mod) Lint( } } -// Return a JSON report file for this run +// Returns a JSON report file for this run func (run LintRun) Report() *dagger.File { return dag.Ruff(). Lint(run.Source). @@ -122,7 +122,7 @@ func (run LintRun) Report() *dagger.File { // Build a Wolfi Linux container // Calls external module Wolfi https://github.com/shykes/daggerverse/tree/main/wolfi -func (m *Mod) Container() *dagger.Container { +func (m *Mod) Wolfi() *dagger.Container { return dag.Wolfi(). Container() } From 8215a3d1cf5e5905a6939074d4564a77afd6a85a Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 11:00:55 +0200 Subject: [PATCH 10/16] Fix syntax --- content/en/docs/01/_index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index 40c696e..c4f8c7a 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -70,7 +70,7 @@ The `dagger` CLI first loads the modules dependencies and then executes the loca Explanation to the dagger CLI call.\ `dagger call` : execute the dagger CLI `call` command\ `--mod ./mod` : `call` command option to use the specified local module (load its functions)\ -`hello` : execute the `hello` function +`hello` : execute the `Hello()` function {{% /alert %}} After a while you should see: @@ -80,9 +80,9 @@ hello, world! ``` {{% alert title="Note" color="primary" %}} -The first execution will take a considerable amount of time, as the module depends on several other modules -which have to be downloaded.\ -For this reason and thanks to Daggers caching mechanism, subsequent calls will be executed much faster! +The first execution will take a considerable amount of time, as the module depends on several other modules +which have to be downloaded. +For this reason and thanks to Daggers caching mechanism, subsequent calls will be executed **much** faster! {{% /alert %}} @@ -184,7 +184,7 @@ dagger --mod ./mod call os --ctr=alpine:latest {{% alert title="Note" color="primary" %}} It is important to know that in Dagger, a `Container` object is not merely a string referencing an image on a remote registry. -It is the **actual state of a container**, managed by the Dagger Engine, and passed to a Dagger Function's code as if it were just another variable! +It is the **actual state of a container**, managed by the Dagger Engine, and passed to a Dagger Functions code as if it were just another variable! {{% /alert %}} From d6228b4aee1587b1ebbca86c62e8f2d9355d334f Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 11:12:18 +0200 Subject: [PATCH 11/16] Update lab 2 --- content/en/docs/02/_index.md | 45 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/content/en/docs/02/_index.md b/content/en/docs/02/_index.md index 1ca8dda..90a2de4 100644 --- a/content/en/docs/02/_index.md +++ b/content/en/docs/02/_index.md @@ -17,7 +17,7 @@ are all objects. They each define various functions for interacting with their r Let's explore them step by step: ```bash -dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 --help +dagger call --mod ./mod --help ``` {{% details title="show available 'module' functions" mode-switcher="normalexpertmode" %}} @@ -25,24 +25,25 @@ dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 --h USAGE dagger call [options] [arguments] - FUNCTIONS - container - host-keys Returns the SSH host keys. - known-hosts Return a formatted SSH known_hosts file. - ---> service Return a service that runs the OpenSSH server. - with-authorized-key Authorize a public key. - with-config Mount a custom SSH configuration file (with .conf extension). + FUNCTIONS + hello Say hello to the world! + lint Lint a Python codebase + ls Returns the files of the directory + os Returns the operating system of the container + ---> ssh-service Returns a service that runs an OpenSSH server + unlock Returns the answer to everything when the password is right + wolfi Build a Wolfi Linux container ``` {{% /details %}} ```bash -dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 service --help +dagger call --mod ./mod ssh-service --help ``` {{% details title="show available 'service' object functions" mode-switcher="normalexpertmode" %}} ``` USAGE - dagger call service [arguments] + dagger call ssh-service [arguments] FUNCTIONS endpoint Retrieves an endpoint that clients can use to reach this container. @@ -55,13 +56,13 @@ dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 ser {{% /details %}} ```bash -dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 service up --help +dagger call --mod ./mod ssh-service up --help ``` {{% details title="show available 'up' function arguments" mode-switcher="normalexpertmode" %}} ``` USAGE - dagger call service up [arguments] + dagger call ssh-service up [arguments] ARGUMENTS ---> --ports PortForward List of frontend/backend port mappings to forward. @@ -72,23 +73,27 @@ dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 ser {{% /details %}} Now that we have got all the pieces together, let's expose a Service returned by a Dagger Function on a specified host port, -by chaining a call to the `Service` object's `Up()` function: +by chaining a call to the `Service` objects `Up()` function: + +{{% alert title="Note" color="primary" %}} +The `Service` object is returned by the modules `SshService()` function. +{{% /alert %}} ```bash -dagger call --mod github.com/sagikazarmark/daggerverse/openssh-server@v0.1.0 service up --ports=22022:22 +dagger call --mod ./mod ssh-service up --ports=22022:22 ``` -Here we print the contents of a File returned by a Dagger Function, by chaining a call to the `File` object's `Contents()` function: +Here we print the contents of a File returned by a Dagger Function, by chaining a call to the `File` objects `Contents()` function: ```bash -dagger call --mod github.com/dagger/dagger/dev/ruff@a29dadbb5d9968784847a15fccc5629daf2985ae lint --source=https://github.com/puzzle/puzzle-radicale-auth-ldap report contents +dagger call --mod ./mod lint --source=https://github.com/puzzle/puzzle-radicale-auth-ldap report contents ``` ### Task {{% param sectionnumber %}}.1: Chain calls Display and return the contents of the `/etc/os-release` file in a container, by chaining additional calls to the `Container` -object of the `github.com/shykes/daggerverse/wolfi@v0.1.3` module: +object, returned by the modules `Wolfi()` function: {{% details title="show hint" mode-switcher="normalexpertmode" %}} Have a look at the [WithExec()](https://docs.dagger.io/api/reference/#Container-withExec) and [Stout()](https://docs.dagger.io/api/reference/#Container-stdout) functions. @@ -96,7 +101,7 @@ Have a look at the [WithExec()](https://docs.dagger.io/api/reference/#Container- {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/shykes/daggerverse/wolfi@v0.1.3 container with-exec --args="cat","/etc/os-release" stdout +dagger call --mod ./mod wolfi with-exec --args="cat","/etc/os-release" stdout ``` {{% /details %}} @@ -104,12 +109,12 @@ Try an alternative approach using [File()](https://docs.dagger.io/api/reference/ {{% details title="show hint" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/shykes/daggerverse/wolfi@v0.1.3 container file --help +dagger call --mod ./mod wolfi file --help ``` {{% /details %}} {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/shykes/daggerverse/wolfi@v0.1.3 container file --path=/etc/os-release contents +dagger call --mod ./mod wolfi file --path=/etc/os-release contents ``` {{% /details %}} From 8681ac434d07d55e375e127aa6e49802626eec1a Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Tue, 15 Oct 2024 11:32:30 +0200 Subject: [PATCH 12/16] Chore --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 952d226..41f005f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,12 +25,12 @@ RUN wkhtmltopdf --enable-internal-links --enable-local-file-access \ FROM docker.io/nginxinc/nginx-unprivileged:1.27-alpine -LABEL maintainer acend.ch -LABEL org.opencontainers.image.title "puzzle.ch's Dagger Basics Training" -LABEL org.opencontainers.image.description "Container with acend.ch's Dagger Techlab content" -LABEL org.opencontainers.image.authors acend.ch -LABEL org.opencontainers.image.source https://github.com/puzzle/dagger-techlab/ -LABEL org.opencontainers.image.licenses CC-BY-SA-4.0 +LABEL maintainer=acend.ch +LABEL org.opencontainers.image.title="puzzle.ch's Dagger Basics Training" +LABEL org.opencontainers.image.description="Container with acend.ch's Dagger Techlab content" +LABEL org.opencontainers.image.authors=acend.ch +LABEL org.opencontainers.image.source =ttps://github.com/puzzle/dagger-techlab/ +LABEL org.opencontainers.image.licenses=CC-BY-SA-4.0 EXPOSE 8080 From 8601827e31fbb89fd6e04d0b7079a319c6bfe7a2 Mon Sep 17 00:00:00 2001 From: Reto Galante Date: Wed, 16 Oct 2024 12:53:59 +0200 Subject: [PATCH 13/16] Remove superfluous type --- mod/main.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/mod/main.go b/mod/main.go index a28e271..65a9556 100644 --- a/mod/main.go +++ b/mod/main.go @@ -11,13 +11,6 @@ import ( "strings" ) -var defaultFigletContainer = dag. - Container(). - From("alpine:latest"). - WithExec([]string{ - "apk", "add", "figlet", - }) - type Mod struct{} type LintRun struct { @@ -43,12 +36,9 @@ func (m *Mod) Hello( // Make the message uppercase, and add more exclamation points // +optional shout bool, - // Custom container for running the figlet tool - // +optional - figletContainer *dagger.Container, ) (string, error) { return dag.Hello(). - Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout, FigletContainer: figletContainer}) + Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout}) } // Returns the files of the directory From 0437877e0809d7aef35ea031a3a36eb943876e63 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Fri, 1 Nov 2024 09:17:36 +0100 Subject: [PATCH 14/16] rename dagger module --- Dockerfile | 8 ++++---- mod/dagger.json | 2 +- mod/main.go | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 41f005f..fe6c7db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,11 +25,11 @@ RUN wkhtmltopdf --enable-internal-links --enable-local-file-access \ FROM docker.io/nginxinc/nginx-unprivileged:1.27-alpine -LABEL maintainer=acend.ch +LABEL maintainer=puzzle.ch LABEL org.opencontainers.image.title="puzzle.ch's Dagger Basics Training" -LABEL org.opencontainers.image.description="Container with acend.ch's Dagger Techlab content" -LABEL org.opencontainers.image.authors=acend.ch -LABEL org.opencontainers.image.source =ttps://github.com/puzzle/dagger-techlab/ +LABEL org.opencontainers.image.description="Container with puzzle.ch's Dagger Techlab content" +LABEL org.opencontainers.image.authors=puzzle.ch +LABEL org.opencontainers.image.source=https://github.com/puzzle/dagger-techlab/ LABEL org.opencontainers.image.licenses=CC-BY-SA-4.0 EXPOSE 8080 diff --git a/mod/dagger.json b/mod/dagger.json index 2509b44..56cd110 100644 --- a/mod/dagger.json +++ b/mod/dagger.json @@ -1,5 +1,5 @@ { - "name": "mod", + "name": "dagger-techlab-module", "sdk": "go", "dependencies": [ { diff --git a/mod/main.go b/mod/main.go index 65a9556..c808d12 100644 --- a/mod/main.go +++ b/mod/main.go @@ -11,7 +11,7 @@ import ( "strings" ) -type Mod struct{} +type DaggerTechlabModule struct{} type LintRun struct { // +private @@ -20,7 +20,7 @@ type LintRun struct { // Say hello to the world! // Calls external module Hello https://github.com/shykes/hello -func (m *Mod) Hello( +func (m *DaggerTechlabModule) Hello( ctx context.Context, // Change the greeting // +optional @@ -42,7 +42,7 @@ func (m *Mod) Hello( } // Returns the files of the directory -func (m *Mod) Ls( +func (m *DaggerTechlabModule) Ls( ctx context.Context, // directory to list it's files dir *dagger.Directory, @@ -56,7 +56,7 @@ func (m *Mod) Ls( } // Returns the operating system of the container -func (m *Mod) Os( +func (m *DaggerTechlabModule) Os( ctx context.Context, // container to get it's OS ctr *dagger.Container, @@ -67,7 +67,7 @@ func (m *Mod) Os( } // Returns the answer to everything when the password is right -func (m *Mod) Unlock( +func (m *DaggerTechlabModule) Unlock( ctx context.Context, password *dagger.Secret, ) (string, error) { @@ -84,7 +84,7 @@ func (m *Mod) Unlock( // Returns a service that runs an OpenSSH server // Calls external module OpensshServer https://github.com/sagikazarmark/daggerverse/tree/main/openssh-server -func (m *Mod) SshService( +func (m *DaggerTechlabModule) SshService( // +optional // +default=22 port int, @@ -95,7 +95,7 @@ func (m *Mod) SshService( // Lint a Python codebase // Calls external module Ruff https://github.com/dagger/dagger/tree/main/modules/ruff -func (m *Mod) Lint( +func (m *DaggerTechlabModule) Lint( source *dagger.Directory, ) *LintRun { return &LintRun{ @@ -112,7 +112,7 @@ func (run LintRun) Report() *dagger.File { // Build a Wolfi Linux container // Calls external module Wolfi https://github.com/shykes/daggerverse/tree/main/wolfi -func (m *Mod) Wolfi() *dagger.Container { +func (m *DaggerTechlabModule) Wolfi() *dagger.Container { return dag.Wolfi(). Container() } From ec356e74f4760fa3b80ec5fce976727e4129bcd6 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Tue, 12 Nov 2024 08:30:50 +0100 Subject: [PATCH 15/16] use mod from daggerverse --- content/en/docs/01/_index.md | 95 +++++++++++++++++++++++++++--------- content/en/docs/02/_index.md | 32 +++++++++--- 2 files changed, 95 insertions(+), 32 deletions(-) diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index c4f8c7a..ac7fb75 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -61,16 +61,21 @@ It is similar to the [MvnRepository](https://mvnrepository.com/). The MvnReposit The most common way to call Dagger Functions is using the `dagger` CLI: ```bash -dagger call --mod ./mod hello +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello ``` The `dagger` CLI first loads the modules dependencies and then executes the local modules `Hello()` function. {{% alert title="Note" color="primary" %}} -Explanation to the dagger CLI call.\ -`dagger call` : execute the dagger CLI `call` command\ -`--mod ./mod` : `call` command option to use the specified local module (load its functions)\ -`hello` : execute the `Hello()` function +Explanation to the dagger CLI call. +* `dagger call`: + * execute the dagger CLI `call` command +* `--mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63`: + * `call` command option to use the specified local module (load its functions) +* `hello`: + * execute the `Hello()` function {{% /alert %}} After a while you should see: @@ -92,14 +97,17 @@ If you are curious, what other [Functions](https://docs.dagger.io/api/reference/ or you can explore its functions using: ```bash -dagger functions --mod ./mod +dagger functions \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 ``` And what about additional arguments of the `Hello()` function? Let's find out: ```bash -dagger call --mod ./mod hello --help +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello --help ``` {{% alert title="Note" color="primary" %}} @@ -118,7 +126,9 @@ Dagger also defines powerful core types: [Container](https://docs.dagger.io/api/ To pass a String argument to a Dagger Function, append the corresponding flag to the dagger call command, followed by the string value: ```bash -dagger call --mod ./mod hello --name=sun +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello --name=sun ``` @@ -133,24 +143,32 @@ True: ```bash # explicit -dagger call --mod ./mod hello --shout=true +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello --shout=true ``` ```bash # implicit -dagger call --mod ./mod hello --shout +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello --shout ``` False: ```bash # explicit -dagger call --mod ./mod hello --shout=false +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello --shout=false ``` ```bash # implicit -dagger call --mod ./mod hello +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello ``` @@ -163,12 +181,16 @@ and pass the resulting `Directory` object as argument to the Dagger Function. Filesystem path: ```bash -dagger call --mod ./mod ls --dir . +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + ls --dir . ``` Git repository: ```bash -dagger call --mod ./mod ls --dir https://github.com/puzzle/action-owasp-dependecy-track-check +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + ls --dir https://github.com/puzzle/action-owasp-dependecy-track-check ``` @@ -179,7 +201,9 @@ Same as directories, you can pass a Container argument. To do so, add the corres The CLI will dynamically pull the image, and pass the resulting `Container` object as argument to the Dagger Function. ```bash -dagger --mod ./mod call os --ctr=alpine:latest +dagger \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + call os --ctr=alpine:latest ``` {{% alert title="Note" color="primary" %}} @@ -200,7 +224,12 @@ Here is an example of passing a GitHub access token from an environment variable The Dagger Function uses the token to query the GitHub CLI for a list of issues in the Dagger open-source repository: ```bash -dagger call --mod github.com/aweris/daggerverse/gh@v0.0.2 run --token=env:GITHUB_TOKEN --cmd="issue list --repo=dagger/dagger" +dagger call \ + --mod github.com/aweris/daggerverse/gh@v0.0.2 \ + run \ + --token=env:GITHUB_TOKEN \ + --cmd="issue list \ + --repo=dagger/dagger" ``` {{% alert title="Note" color="primary" %}} @@ -216,19 +245,24 @@ Make it return the phrase `Dagger puts a smile on my face!`. {{% details title="show hint" mode-switcher="normalexpertmode" %}} ```bash -dagger functions --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 +dagger functions \ + --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 ``` {{% /details %}} {{% details title="show hint" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 say --help +dagger call \ + --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 \ + say --help ``` {{% /details %}} {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 say --msg="Dagger puts a smile on my face!" +dagger call \ + --mod github.com/purpleclay/daggerverse/ponysay@v0.1.0 \ + say --msg="Dagger puts a smile on my face!" ``` {{% /details %}} @@ -239,7 +273,12 @@ Call the `Hello()` function so that it returns the phrase `Welcome, sunshine!` i {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod ./mod hello --giant --greeting=Welcome --name=sunshine +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + hello \ + --giant \ + --greeting=Welcome \ + --name=sunshine ``` {{% /details %}} @@ -249,13 +288,17 @@ dagger call --mod ./mod hello --giant --greeting=Welcome --name=sunshine Set the `--password` value in the following call with a secret, using an environment variable, containing the password "MySuperSecret". ```bash -dagger call --mod ./mod unlock --password=visible +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + unlock --password=visible ``` {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash export SECRET=MySuperSecret -dagger call --mod ./mod unlock --password env:SECRET +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + unlock --password env:SECRET ``` {{% /details %}} @@ -264,7 +307,9 @@ or using a file {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash echo $SECRET > secret.txt -dagger call --mod ./mod unlock --password file:./secret.txt +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + unlock --password file:./secret.txt ``` {{% /details %}} @@ -272,7 +317,9 @@ or using a command {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod ./mod unlock --password cmd:"echo $SECRET" +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + unlock --password cmd:"echo $SECRET" ``` {{% /details %}} diff --git a/content/en/docs/02/_index.md b/content/en/docs/02/_index.md index 90a2de4..3c15083 100644 --- a/content/en/docs/02/_index.md +++ b/content/en/docs/02/_index.md @@ -17,7 +17,9 @@ are all objects. They each define various functions for interacting with their r Let's explore them step by step: ```bash -dagger call --mod ./mod --help +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + --help ``` {{% details title="show available 'module' functions" mode-switcher="normalexpertmode" %}} @@ -37,7 +39,9 @@ dagger call --mod ./mod --help {{% /details %}} ```bash -dagger call --mod ./mod ssh-service --help +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + ssh-service --help ``` {{% details title="show available 'service' object functions" mode-switcher="normalexpertmode" %}} @@ -56,7 +60,9 @@ dagger call --mod ./mod ssh-service --help {{% /details %}} ```bash -dagger call --mod ./mod ssh-service up --help +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + ssh-service up --help ``` {{% details title="show available 'up' function arguments" mode-switcher="normalexpertmode" %}} @@ -80,13 +86,17 @@ The `Service` object is returned by the modules `SshService()` function. {{% /alert %}} ```bash -dagger call --mod ./mod ssh-service up --ports=22022:22 +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + ssh-service up --ports=22022:22 ``` Here we print the contents of a File returned by a Dagger Function, by chaining a call to the `File` objects `Contents()` function: ```bash -dagger call --mod ./mod lint --source=https://github.com/puzzle/puzzle-radicale-auth-ldap report contents +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + lint --source=https://github.com/puzzle/puzzle-radicale-auth-ldap report contents ``` @@ -101,7 +111,9 @@ Have a look at the [WithExec()](https://docs.dagger.io/api/reference/#Container- {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod ./mod wolfi with-exec --args="cat","/etc/os-release" stdout +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + wolfi with-exec --args="cat","/etc/os-release" stdout ``` {{% /details %}} @@ -109,12 +121,16 @@ Try an alternative approach using [File()](https://docs.dagger.io/api/reference/ {{% details title="show hint" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod ./mod wolfi file --help +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + wolfi file --help ``` {{% /details %}} {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```bash -dagger call --mod ./mod wolfi file --path=/etc/os-release contents +dagger call \ + --mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63 \ + wolfi file --path=/etc/os-release contents ``` {{% /details %}} From b620dc234c16bf8562b1c6c4d8c4f35408f5c466 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Tue, 12 Nov 2024 08:39:17 +0100 Subject: [PATCH 16/16] fix lint --- content/en/docs/01/_index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index ac7fb75..d463477 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -66,10 +66,11 @@ dagger call \ hello ``` -The `dagger` CLI first loads the modules dependencies and then executes the local modules `Hello()` function. +The `dagger` CLI first loads the `dagger-techlab-module` module directly from its [GitHub repository](https://github.com/puzzle/dagger-techlab/tree/main/mod) and then executes the `Hello()` function from that module. {{% alert title="Note" color="primary" %}} -Explanation to the dagger CLI call. +Explanation to the dagger CLI call: + * `dagger call`: * execute the dagger CLI `call` command * `--mod github.com/puzzle/dagger-techlab/mod@0437877e0809d7aef35ea031a3a36eb943876e63`: