From e74b8cc18519565cbdee78bcfe99db3435f5d5f5 Mon Sep 17 00:00:00 2001 From: Patrick Sy Date: Tue, 15 Oct 2024 10:15:29 +0200 Subject: [PATCH] feat(publish): example publishing to some remote registry --- README.md | 27 ++++++++++++++++++++++++++- dagger/src/index.ts | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af7182e..20c4ce6 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,33 @@ as the `source` parameter of that function. > becomes > > ```shell -> dagger call build --source=. as-service up --ports=8080:8080 +> dagger call build --source=. as-service up --ports=8080:9000 > ``` > After running a dagger command the Dagger Engine stays alive as a local > container waiting for the next call. + +> The [Cookbook](https://docs.dagger.io/cookbook) does contain a lot of +> extremely useful patterns on how to handle builds and containers. More +> importantly, it showcases ways to debug everyday problems when working on +> container builds, see `temrinal()`, `File.contents()` + +Run `golangci-lint`: + +```shell +dagger call lint --source=. +``` + +Run trivy: + +```shell +dagger call security-scan --source=. +``` + +> Trivy is setup as a dagger module. Modules are most of the time simple +> wrappers instructing container images with some convenience functions. There +> is actually not too much magic here. + +> Modules in dagger can be written in Go, Python, or Typescript. Either way, +> they are usable in any other language, e.g. a Python module can be used in a +> Typescript config. The proper API functions are exposed on the `dag` object. diff --git a/dagger/src/index.ts b/dagger/src/index.ts index a01e0bb..fe76a63 100644 --- a/dagger/src/index.ts +++ b/dagger/src/index.ts @@ -59,6 +59,20 @@ class HelloDagger { .withExec(["golangci-lint", "run", "-v"]); } + @func() + async publish(source: Directory, target?: string): Promise { + // publish can only push to external registries + // to publish to your local docker, you have to export the tarball and use `docker load` + + // This example is somewhat useless as one could just chain `publish` to `call build` + + // publish automatically picks up the local auth from the host + // otherwise, use `withRegistryAuth()` + return this.build(source).publish( + target ?? "mtr.devops.telekom.de/patrick_sy/hello-dagger:latest", + ); + } + /** * Build a ready-to-use development environment */