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/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 diff --git a/content/en/docs/01/_index.md b/content/en/docs/01/_index.md index 6999351..c4f8c7a 100644 --- a/content/en/docs/01/_index.md +++ b/content/en/docs/01/_index.md @@ -61,16 +61,16 @@ 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. +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 github.com/shykes/daggerverse/hello@v0.3.0` : `call` command option to use the `hello` module (load its functions)\ -`hello` : execute the `hello` function +`--mod ./mod` : `call` command option to use the specified local module (load its functions)\ +`hello` : execute the `Hello()` function {{% /alert %}} After a while you should see: @@ -80,24 +80,26 @@ 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 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? +And 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 +118,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 +133,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 +163,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,11 +179,12 @@ 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! +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 %}} @@ -193,16 +196,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" %}} @@ -226,28 +235,27 @@ 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 so that it returns the phrase `Welcome, sunshine!` in ASCII-art (giant letters). {{% 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 %}} ## 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 %}} @@ -256,7 +264,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 %}} @@ -264,10 +272,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/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 %}} 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..2509b44 --- /dev/null +++ b/mod/dagger.json @@ -0,0 +1,24 @@ +{ + "name": "mod", + "sdk": "go", + "dependencies": [ + { + "name": "hello", + "source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d" + }, + { + "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": ".", + "engineVersion": "v0.13.1" +} diff --git a/mod/go.mod b/mod/go.mod new file mode 100644 index 0000000..4872437 --- /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.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.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.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.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 + +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..40f88b0 --- /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.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.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= +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.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= +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..65a9556 --- /dev/null +++ b/mod/main.go @@ -0,0 +1,118 @@ +// A module to support the Puzzle dagger techlab. +// +// The functions are used inside the hands-on lab: https://dagger-techlab.puzzle.ch/ + +package main + +import ( + "context" + "dagger/mod/internal/dagger" + "errors" + "strings" +) + +type Mod struct{} + +type LintRun struct { + // +private + Source *dagger.Directory +} + +// Say hello to the world! +// Calls external module Hello https://github.com/shykes/hello +func (m *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, + ) (string, error) { + return dag.Hello(). + Hello(ctx, dagger.HelloHelloOpts{Greeting: greeting, Name: name, Giant: giant, Shout: shout}) +} + +// 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 it's OS + ctr *dagger.Container, + ) (string, error) { + return ctr. + 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, + 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.") +} + +// 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( + // +optional + // +default=22 + port int, + ) *dagger.Service { + return dag.OpensshServer(). + Service(dagger.OpensshServerServiceOpts{Port: port}) +} + +// Lint a Python codebase +// Calls external module Ruff https://github.com/dagger/dagger/tree/main/modules/ruff +func (m *Mod) Lint( + source *dagger.Directory, +) *LintRun { + return &LintRun{ + Source: source, + } +} + +// Returns a JSON report file for this run +func (run LintRun) Report() *dagger.File { + return dag.Ruff(). + Lint(run.Source). + Report() +} + +// Build a Wolfi Linux container +// Calls external module Wolfi https://github.com/shykes/daggerverse/tree/main/wolfi +func (m *Mod) Wolfi() *dagger.Container { + return dag.Wolfi(). + Container() +}