Skip to content

Commit

Permalink
docs(dagger): update with v0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Smana committed Jul 22, 2024
1 parent bb4a14d commit a4019ce
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
41 changes: 23 additions & 18 deletions content/en/post/dagger-intro/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The first time we run Dagger, it pulls and starts a local instance of the **Dagg
```console
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3cec5bf51843 registry.dagger.io/engine:v0.11.9 "dagger-entrypoint.s…" 8 days ago Up 2 hours dagger-engine-ceb38152f96f1298
3cec5bf51843 registry.dagger.io/engine:v0.12.1 "dagger-entrypoint.s…" 8 days ago Up 2 hours dagger-engine-ceb38152f96f1298
```
{{% /notice %}}

Expand All @@ -63,12 +63,12 @@ Let's start by **installing the CLI**. If you've read my previous articles, you
```console
asdf plugin-add dagger

asdf install dagger 0.11.9
Downloading dagger from https://github.com/dagger/dagger/releases/download/v0.11.9/dagger_v0.11.9_linux_amd64.tar.gz
asdf install dagger 0.12.1
Downloading dagger from https://github.com/dagger/dagger/releases/download/v0.12.1/dagger_v0.12.1_linux_amd64.tar.gz

asdf global dagger 0.11.9
asdf global dagger 0.12.1
dagger version
dagger v0.11.9 (registry.dagger.io/engine) linux/amd64
dagger v0.12.1 (registry.dagger.io/engine) linux/amd64
```

Let's dive right in and immediately execute a module provided by the community. Suppose we want to scan a git repo and a Docker image with [trivy](https://aquasecurity.github.io/trivy/v0.53/).
Expand Down Expand Up @@ -130,9 +130,9 @@ Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
Oops! It seems there is a critical vulnerability in my image 😨.

```console
dagger call -m ${TRIVY_MODULE} image --ref smana/dagger-cli:v0.11.9 --severity CRITICAL
dagger call -m ${TRIVY_MODULE} image --ref smana/dagger-cli:v0.12.1 --severity CRITICAL

smana/dagger-cli:v0.11.9 (ubuntu 23.04)
smana/dagger-cli:v0.12.1 (ubuntu 23.04)
=======================================
Total: 0 (CRITICAL: 0)

Expand Down Expand Up @@ -385,7 +385,7 @@ Next, we need to decide on the input parameters. For example, I want to be able

The above comments are important: The description will be displayed to the user, and we can make this parameter optional and set a default version.
```console
dagger call -m github.com/Smana/daggerverse/kubeconform@v0.0.4 validate --help
dagger call -m github.com/Smana/daggerverse/kubeconform@v0.1.0 validate --help
Validate the Kubernetes manifests in the provided directory and optional source CRDs directories
...
--version string Kubeconform version to use for validation. (default "v0.6.6")
Expand Down Expand Up @@ -446,7 +446,7 @@ dagger call validate --manifests ~/Sources/demo-cloud-native-ref/clusters --cata
09:32:07 DBG recording span span=telemetry.LogsSource/Subscribe id=b3fc48ec7900f581
09:32:07 DBG recording span child span=telemetry.LogsSource/Subscribe parent=ae535768bb2be9d7 child=b3fc48ec7900f581
09:32:07 DBG new end old="2024-07-06 09:32:07.436103273 +0200 CEST" new="2024-07-06 09:32:07.438699251 +0200 CEST"
09:32:07 DBG recording span span="/home/smana/.asdf/installs/dagger/0.11.9/bin/dagger call -m github.com/Smana/daggerverse/kubeconform@v0.0.4 validate --manifests /home/smana/Sources/demo-cloud-native-ref/clusters --catalog -vvv --debug" id=ae535768bb2be9d7
09:32:07 DBG recording span span="/home/smana/.asdf/installs/dagger/0.12.1/bin/dagger call -m github.com/Smana/daggerverse/kubeconform@v0.1.0 validate --manifests /home/smana/Sources/demo-cloud-native-ref/clusters --catalog -vvv --debug" id=ae535768bb2be9d7
09:32:07 DBG frontend exporting logs logs=4
09:32:07 DBG exporting log span=0xf62760 body=""
09:32:07 DBG got EOF
Expand All @@ -458,16 +458,21 @@ dagger call validate --manifests ~/Sources/demo-cloud-native-ref/clusters --cata
✔ dbd62c92c3db105f exec docker start dagger-engine-ceb38152f96f1298 0.0s
┃ dagger-engine-ceb38152f96f1298
✔ 4db8303f1d7ec940 connecting to engine 0.1s
┃ 09:32:03 DBG connecting runner=docker-image://registry.dagger.io/engine:v0.11.9 client=5fa0kn1nc4qlku1erer3868nj
┃ 09:32:03 DBG subscribing to telemetry remote=docker-image://registry.dagger.io/engine:v0.11.9
┃ 09:32:03 DBG connecting runner=docker-image://registry.dagger.io/engine:v0.12.1 client=5fa0kn1nc4qlku1erer3868nj
┃ 09:32:03 DBG subscribing to telemetry remote=docker-image://registry.dagger.io/engine:v0.12.1
┃ 09:32:03 DBG subscribed to telemetry elapsed=19.095µs
```

I also frequently add commands in the container, for example, to check the contents of a directory.
Starting from version v0.12.x, Dagger introduces an **interactive** mode. By using the `-i` or `--interactive` parameter, it is possible to automatically launch a terminal when the code encounters an error. This allows for performing checks and operations directly within the container.

Additionally, you can insert the execution of `Terminal()` at any point in the container definition to enter interactive mode at that precise moment.

```golang
stdout, err := ctr.
WithExec([]string{"ls", "-l", "/work"}).
...
stdout, err := ctr.WithExec(kubeconform_command).
Terminal().
Stdout(ctx)
...
```

With this module, I was also able to add some missing features that are quite useful:
Expand Down Expand Up @@ -527,11 +532,11 @@ Dagger integrates well with most CI platforms. Indeed we just need to run a `dag
uses: actions/checkout@v4

- name: Validate Flux clusters manifests
uses: dagger/dagger-for-github@v5
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
module: github.com/Smana/daggerverse/kubeconform@kubeconform/v0.0.4
module: github.com/Smana/daggerverse/kubeconform@kubeconform/v0.1.0
args: validate --manifests "./clusters" --catalog
```
Expand Down Expand Up @@ -631,14 +636,14 @@ To test this, we will run a job that creates a container and installs many relat
name: Testing in-cluster cache
runs-on: dagger-gha-runner-scale-set
container:
image: smana/dagger-cli:v0.11.9
image: smana/dagger-cli:v0.12.1
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: "tcp://dagger-engine:8080"
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
steps:
- name: Simulate a build with heavy packages
uses: dagger/dagger-for-github@v5
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
Expand Down
41 changes: 23 additions & 18 deletions content/fr/post/dagger-intro/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ Commençons par installer la CLI. Si vous avez parcouru mes précédents article
```console
asdf plugin-add dagger

asdf install dagger 0.11.9
Downloading dagger from https://github.com/dagger/dagger/releases/download/v0.11.9/dagger_v0.11.9_linux_amd64.tar.gz
asdf install dagger 0.12.1
Downloading dagger from https://github.com/dagger/dagger/releases/download/v0.12.1/dagger_v0.12.1_linux_amd64.tar.gz

asdf global dagger 0.11.9
asdf global dagger 0.12.1
dagger version
dagger v0.11.9 (registry.dagger.io/engine) linux/amd64
dagger v0.12.1 (registry.dagger.io/engine) linux/amd64
```

Entrons dans le vif du sujet, nous pouvons tout de suite exécuter un module fournie par la communauté. Supposons que l'on veuille scanner un repo git et une image Docker avec [trivy](https://aquasecurity.github.io/trivy/v0.53/).
Expand Down Expand Up @@ -119,9 +119,9 @@ Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
Oups! il semble qu'il y ait une vulnérabilité critique dans mon image 😨.

```console
dagger call -m ${TRIVY_MODULE} image --ref smana/dagger-cli:v0.11.9 --severity CRITICAL
dagger call -m ${TRIVY_MODULE} image --ref smana/dagger-cli:v0.12.1 --severity CRITICAL

smana/dagger-cli:v0.11.9 (ubuntu 23.04)
smana/dagger-cli:v0.12.1 (ubuntu 23.04)
=======================================
Total: 0 (CRITICAL: 0)

Expand Down Expand Up @@ -377,7 +377,7 @@ Il faut ensuite décider des paramètres d'entrée. Par exemple je souhaite pouv

Les commentaires ci-dessus sont importants: La description sera affichée à l'utilisateur et nous pouvons faire en sorte que ce paramètre ne soit pas requis avec une version par défault.
```console
dagger call -m github.com/Smana/daggerverse/kubeconform@v0.0.4 validate --help
dagger call -m github.com/Smana/daggerverse/kubeconform@v0.1.0 validate --help
Validate the Kubernetes manifests in the provided directory and optional source CRDs directories
...
--version string Kubeconform version to use for validation. (default "v0.6.6")
Expand Down Expand Up @@ -440,7 +440,7 @@ dagger call validate --manifests ~/Sources/demo-cloud-native-ref/clusters --cata
09:32:07 DBG recording span span=telemetry.LogsSource/Subscribe id=b3fc48ec7900f581
09:32:07 DBG recording span child span=telemetry.LogsSource/Subscribe parent=ae535768bb2be9d7 child=b3fc48ec7900f581
09:32:07 DBG new end old="2024-07-06 09:32:07.436103273 +0200 CEST" new="2024-07-06 09:32:07.438699251 +0200 CEST"
09:32:07 DBG recording span span="/home/smana/.asdf/installs/dagger/0.11.9/bin/dagger call -m github.com/Smana/daggerverse/kubeconform@v0.0.4 validate --manifests /home/smana/Sources/demo-cloud-native-ref/clusters --catalog -vvv --debug" id=ae535768bb2be9d7
09:32:07 DBG recording span span="/home/smana/.asdf/installs/dagger/0.12.1/bin/dagger call -m github.com/Smana/daggerverse/kubeconform@v0.1.0 validate --manifests /home/smana/Sources/demo-cloud-native-ref/clusters --catalog -vvv --debug" id=ae535768bb2be9d7
09:32:07 DBG frontend exporting logs logs=4
09:32:07 DBG exporting log span=0xf62760 body=""
09:32:07 DBG got EOF
Expand All @@ -452,16 +452,21 @@ dagger call validate --manifests ~/Sources/demo-cloud-native-ref/clusters --cata
✔ dbd62c92c3db105f exec docker start dagger-engine-ceb38152f96f1298 0.0s
┃ dagger-engine-ceb38152f96f1298
✔ 4db8303f1d7ec940 connecting to engine 0.1s
┃ 09:32:03 DBG connecting runner=docker-image://registry.dagger.io/engine:v0.11.9 client=5fa0kn1nc4qlku1erer3868nj
┃ 09:32:03 DBG subscribing to telemetry remote=docker-image://registry.dagger.io/engine:v0.11.9
┃ 09:32:03 DBG connecting runner=docker-image://registry.dagger.io/engine:v0.12.1 client=5fa0kn1nc4qlku1erer3868nj
┃ 09:32:03 DBG subscribing to telemetry remote=docker-image://registry.dagger.io/engine:v0.12.1
┃ 09:32:03 DBG subscribed to telemetry elapsed=19.095µs
```

Il m'est aussi arrivé régulièrement d'ajouter des commandes dans le conteneur, par exemple pour vérifier le contenu d'un répertoire
À partir de la version v0.12.x, Dagger propose un mode **interactif**. En utilisant le paramètre `-i` ou `--interactive`, il est possible de lancer automatiquement un terminal lorsque le code rencontre une erreur. Cela permet de réaliser des vérifications et des opérations directement dans le conteneur.

De plus, il est possible d'ajouter l'exécution de `Terminal()` à n'importe quel endroit dans la définition du conteneur pour entrer en mode interactif à ce moment précis.

```golang
stdout, err := ctr.
WithExec([]string{"ls", "-l", "/work"}).
...
stdout, err := ctr.WithExec(kubeconform_command).
Terminal().
Stdout(ctx)
...
```

Avec ce module j'ai pu ajouter aussi des fonctionnalités manquantes qui sont fort utiles:
Expand All @@ -485,7 +490,7 @@ Par défaut, le moteur Dagger est disponible en local, et utilise du cache local
```console
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3cec5bf51843 registry.dagger.io/engine:v0.11.9 "dagger-entrypoint.s…" 8 days ago Up 2 hours dagger-engine-ceb38152f96f1298
3cec5bf51843 registry.dagger.io/engine:v0.12.1 "dagger-entrypoint.s…" 8 days ago Up 2 hours dagger-engine-ceb38152f96f1298
```

La proposition suivante vise à définir un **cache partagé et distant**, accessible à tous les collaborateurs ainsi que depuis la CI. L'objectif est d'**accélérer** les exécutions ultérieures, peu importe où Dagger est exécuté.
Expand Down Expand Up @@ -529,11 +534,11 @@ Dagger s'intègre bien avec la plupart des solutions de CI. Il suffit en effet d
uses: actions/checkout@v4

- name: Validate Flux clusters manifests
uses: dagger/dagger-for-github@v5
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
module: github.com/Smana/daggerverse/kubeconform@kubeconform/v0.0.4
module: github.com/Smana/daggerverse/kubeconform@kubeconform/v0.1.0
args: validate --manifests "./clusters" --catalog
```
Expand Down Expand Up @@ -633,14 +638,14 @@ Afin de tester cela, nous allons lancer un job qui crée un conteneur en install
name: Testing in-cluster cache
runs-on: dagger-gha-runner-scale-set
container:
image: smana/dagger-cli:v0.11.9
image: smana/dagger-cli:v0.12.1
env:
_EXPERIMENTAL_DAGGER_RUNNER_HOST: "tcp://dagger-engine:8080"
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
steps:
- name: Simulate a build with heavy packages
uses: dagger/dagger-for-github@v5
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
Expand Down

0 comments on commit a4019ce

Please sign in to comment.