23 | );
24 | }
25 |
26 | export default App;
27 |
--------------------------------------------------------------------------------
/go/replace-dockerfile/go.mod:
--------------------------------------------------------------------------------
1 | module replace-dockerfile
2 |
3 | go 1.19
4 |
5 | require dagger.io/dagger v0.7.1
6 |
7 | require (
8 | github.com/99designs/gqlgen v0.17.2 // indirect
9 | github.com/Khan/genqlient v0.5.0 // indirect
10 | github.com/adrg/xdg v0.4.0 // indirect
11 | github.com/iancoleman/strcase v0.2.0 // indirect
12 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
13 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
14 | golang.org/x/sync v0.1.0 // indirect
15 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
16 | golang.org/x/tools v0.1.10 // indirect
17 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
18 | )
19 |
--------------------------------------------------------------------------------
/go/multistage/go.mod:
--------------------------------------------------------------------------------
1 | module multistage
2 |
3 | go 1.20
4 |
5 | require (
6 | dagger.io/dagger v0.7.1
7 | github.com/google/uuid v1.3.0
8 | )
9 |
10 | require (
11 | github.com/99designs/gqlgen v0.17.2 // indirect
12 | github.com/Khan/genqlient v0.5.0 // indirect
13 | github.com/adrg/xdg v0.4.0 // indirect
14 | github.com/iancoleman/strcase v0.2.0 // indirect
15 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
16 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
17 | golang.org/x/sync v0.1.0 // indirect
18 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
19 | golang.org/x/tools v0.1.10 // indirect
20 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
21 | )
22 |
--------------------------------------------------------------------------------
/go/db-service/main_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "database/sql"
5 | "fmt"
6 | _ "github.com/lib/pq"
7 | "github.com/stretchr/testify/assert"
8 | "os"
9 | "testing"
10 | )
11 |
12 | func TestDatabase(t *testing.T) {
13 | db_host := os.Getenv("DB_HOST")
14 | db_name := os.Getenv("DB_NAME")
15 | db_password := os.Getenv("DB_PASSWORD")
16 | db_user := os.Getenv("DB_USER")
17 | connStr := fmt.Sprintf("user=%s password=%s host=%s dbname=%s sslmode=disable", db_user, db_password, db_host, db_name)
18 | db, err := sql.Open("postgres", connStr)
19 |
20 | assert.NoError(t, err)
21 |
22 | var result string
23 | err = db.QueryRow("SELECT 1").Scan(&result)
24 |
25 | assert.NoError(t, err)
26 | assert.Equal(t, "1", result)
27 | }
28 |
--------------------------------------------------------------------------------
/nodejs/secrets/ci.js:
--------------------------------------------------------------------------------
1 | import { connect } from "@dagger.io/dagger"
2 |
3 | // initialize Dagger client
4 | connect(async (client) => {
5 |
6 | const secretEnv = client.setSecret("my-secret-env", "secret value here")
7 | const secretFile = client.setSecret("my-secret-file", "secret file content here")
8 |
9 | // dump secrets to console
10 | const out = await client
11 | .container()
12 | .from("alpine:3.17")
13 | .withSecretVariable("MY_SECRET_VAR", secretEnv)
14 | .withMountedSecret("/my_secret_file", secretFile)
15 | .withExec(["sh", "-c", `echo -e "secret env data: $MY_SECRET_VAR || secret file data: "; cat /my_secret_file`])
16 | .stdout()
17 |
18 | console.log(out)
19 | }, {LogOutput: process.stderr})
--------------------------------------------------------------------------------
/go/aws-cdk/registry.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 |
6 | "dagger.io/dagger"
7 | )
8 |
9 | type RegistryInfo struct {
10 | uri string
11 | username string
12 | password string
13 | }
14 |
15 | // initRegistry creates and/or authenticate with an ECR repository
16 | func initRegistry(ctx context.Context, client *dagger.Client, awsClient *AWSClient) *RegistryInfo {
17 | outputs, err := awsClient.cdkDeployStack(ctx, client, "DaggerDemoECRStack", nil)
18 | if err != nil {
19 | panic(err)
20 | }
21 |
22 | repoUri := outputs["RepositoryUri"]
23 |
24 | username, password, err := awsClient.GetECRUsernamePassword(ctx)
25 | if err != nil {
26 | panic(err)
27 | }
28 |
29 | return &RegistryInfo{repoUri, username, password}
30 | }
31 |
--------------------------------------------------------------------------------
/nodejs/react-build/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/go/aws-cdk/infra/infra_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // import (
4 | // "testing"
5 |
6 | // "github.com/aws/aws-cdk-go/awscdk/v2"
7 | // "github.com/aws/aws-cdk-go/awscdk/v2/assertions"
8 | // "github.com/aws/jsii-runtime-go"
9 | // )
10 |
11 | // example tests. To run these tests, uncomment this file along with the
12 | // example resource in infra_test.go
13 | // func TestInfraStack(t *testing.T) {
14 | // // GIVEN
15 | // app := awscdk.NewApp(nil)
16 |
17 | // // WHEN
18 | // stack := NewInfraStack(app, "MyStack", nil)
19 |
20 | // // THEN
21 | // template := assertions.Template_FromStack(stack)
22 |
23 | // template.HasResourceProperties(jsii.String("AWS::SQS::Queue"), map[string]interface{}{
24 | // "VisibilityTimeout": 300,
25 | // })
26 | // }
27 |
--------------------------------------------------------------------------------
/go/npm-build/go.mod:
--------------------------------------------------------------------------------
1 | module goyarn
2 |
3 | go 1.18
4 |
5 | replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible
6 |
7 | require dagger.io/dagger v0.7.1
8 |
9 | require (
10 | github.com/99designs/gqlgen v0.17.2 // indirect
11 | github.com/Khan/genqlient v0.5.0 // indirect
12 | github.com/adrg/xdg v0.4.0 // indirect
13 | github.com/iancoleman/strcase v0.2.0 // indirect
14 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
15 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
16 | golang.org/x/sync v0.1.0 // indirect
17 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
18 | golang.org/x/tools v0.1.10 // indirect
19 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
20 | )
21 |
--------------------------------------------------------------------------------
/go/yarn-build/go.mod:
--------------------------------------------------------------------------------
1 | module goyarn
2 |
3 | go 1.18
4 |
5 | replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible
6 |
7 | require dagger.io/dagger v0.7.1
8 |
9 | require (
10 | github.com/99designs/gqlgen v0.17.2 // indirect
11 | github.com/Khan/genqlient v0.5.0 // indirect
12 | github.com/adrg/xdg v0.4.0 // indirect
13 | github.com/iancoleman/strcase v0.2.0 // indirect
14 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
15 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
16 | golang.org/x/sync v0.1.0 // indirect
17 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
18 | golang.org/x/tools v0.1.10 // indirect
19 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
20 | )
21 |
--------------------------------------------------------------------------------
/go/gradle-build/go.mod:
--------------------------------------------------------------------------------
1 | module goyarn
2 |
3 | go 1.18
4 |
5 | replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible
6 |
7 | require dagger.io/dagger v0.7.1
8 |
9 | require (
10 | github.com/99designs/gqlgen v0.17.2 // indirect
11 | github.com/Khan/genqlient v0.5.0 // indirect
12 | github.com/adrg/xdg v0.4.0 // indirect
13 | github.com/iancoleman/strcase v0.2.0 // indirect
14 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
15 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
16 | golang.org/x/sync v0.1.0 // indirect
17 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
18 | golang.org/x/tools v0.1.10 // indirect
19 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
20 | )
21 |
--------------------------------------------------------------------------------
/go/multiarch-build/go.mod:
--------------------------------------------------------------------------------
1 | module multiarch
2 |
3 | go 1.19
4 |
5 | require dagger.io/dagger v0.7.1
6 |
7 | require (
8 | github.com/99designs/gqlgen v0.17.2 // indirect
9 | github.com/Khan/genqlient v0.5.0 // indirect
10 | github.com/adrg/xdg v0.4.0 // indirect
11 | github.com/iancoleman/strcase v0.2.0 // indirect
12 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
13 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
14 | golang.org/x/sync v0.1.0 // indirect
15 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
16 | golang.org/x/tools v0.1.10 // indirect
17 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
18 | )
19 |
20 | replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible
21 |
--------------------------------------------------------------------------------
/go/aws-cdk/infra/aws_ecr.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | cdk "github.com/aws/aws-cdk-go/awscdk/v2"
7 | ecr "github.com/aws/aws-cdk-go/awscdk/v2/awsecr"
8 | "github.com/aws/constructs-go/constructs/v10"
9 |
10 | "github.com/aws/jsii-runtime-go"
11 | )
12 |
13 | func NewECRStack(scope constructs.Construct, id string, repositoryName string) cdk.Stack {
14 | stack := cdk.NewStack(scope, &id, &cdk.StackProps{
15 | Description: jsii.String(fmt.Sprintf("ECR stack for repository %s", repositoryName)),
16 | })
17 |
18 | ecrRepo := ecr.NewRepository(stack, jsii.String(repositoryName), &ecr.RepositoryProps{
19 | RepositoryName: jsii.String(repositoryName),
20 | })
21 |
22 | cdk.NewCfnOutput(stack, jsii.String("RepositoryUri"), &cdk.CfnOutputProps{Value: ecrRepo.RepositoryUri()})
23 |
24 | return stack
25 | }
26 |
--------------------------------------------------------------------------------
/nodejs/multistage/build.js:
--------------------------------------------------------------------------------
1 | import { connect } from "@dagger.io/dagger"
2 | import { v4 as uuidv4 } from "uuid";
3 |
4 | // initialize Dagger client
5 | connect(async (client) => {
6 | const project = client.git("https://github.com/dagger/dagger").branch("main").tree()
7 |
8 | const build = client.container()
9 | .from("golang:1.20")
10 | .withDirectory("/src", project)
11 | .withWorkdir("/src")
12 | .withExec(["go", "build", "./cmd/dagger"])
13 |
14 | const prodImage = client.container()
15 | .from("cgr.dev/chainguard/wolfi-base:latest")
16 | .withDefaultArgs() // Set CMD to []
17 | .withFile("/bin/dagger", build.file("/src/dagger"))
18 | .withEntrypoint(["/bin/dagger"])
19 |
20 | const id = uuidv4()
21 | const tag = `ttl.sh/dagger-${id}:1h`
22 |
23 | await prodImage.publish(tag)
24 |
25 | }, {LogOutput: process.stdout})
26 |
--------------------------------------------------------------------------------
/python/secrets/pipeline.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | import anyio
4 | import dagger
5 |
6 | async def main():
7 | async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
8 |
9 | secret_env = client.set_secret("my-secret-var", "secret value here")
10 | secret_file = client.set_secret("my-secret-file", "secret file content here")
11 |
12 | # dump secrets to console
13 | out = await (
14 | client.container()
15 | .from_("alpine:3.17")
16 | .with_secret_variable("MY_SECRET_VAR", secret_env)
17 | .with_mounted_secret("/my_secret_file", secret_file)
18 | .with_exec(["sh", "-c", """ echo -e "secret env data: $MY_SECRET_VAR || secret file data: "; cat /my_secret_file """])
19 | .stdout()
20 | )
21 |
22 | print(out)
23 |
24 | anyio.run(main)
--------------------------------------------------------------------------------
/go/aws-cdk/infra/go.mod:
--------------------------------------------------------------------------------
1 | module infra
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/aws/aws-cdk-go/awscdk/v2 v2.63.2
7 | github.com/aws/constructs-go/constructs/v10 v10.1.235
8 | github.com/aws/jsii-runtime-go v1.74.0
9 | )
10 |
11 | require (
12 | github.com/Masterminds/semver/v3 v3.2.0 // indirect
13 | github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.52 // indirect
14 | github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.1 // indirect
15 | github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv5/v2 v2.0.42 // indirect
16 | github.com/mattn/go-isatty v0.0.16 // indirect
17 | github.com/yuin/goldmark v1.4.13 // indirect
18 | golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
19 | golang.org/x/mod v0.7.0 // indirect
20 | golang.org/x/sys v0.4.0 // indirect
21 | golang.org/x/tools v0.5.0 // indirect
22 | )
23 |
--------------------------------------------------------------------------------
/go/db-service/go.mod:
--------------------------------------------------------------------------------
1 | module db-service
2 |
3 | go 1.20
4 |
5 | require (
6 | dagger.io/dagger v0.7.1
7 | github.com/lib/pq v1.10.7
8 | github.com/stretchr/testify v1.8.1
9 | )
10 |
11 | require (
12 | github.com/99designs/gqlgen v0.17.2 // indirect
13 | github.com/Khan/genqlient v0.5.0 // indirect
14 | github.com/adrg/xdg v0.4.0 // indirect
15 | github.com/davecgh/go-spew v1.1.1 // indirect
16 | github.com/iancoleman/strcase v0.2.0 // indirect
17 | github.com/pmezard/go-difflib v1.0.0 // indirect
18 | github.com/vektah/gqlparser/v2 v2.5.1 // indirect
19 | golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
20 | golang.org/x/sync v0.1.0 // indirect
21 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
22 | golang.org/x/tools v0.1.10 // indirect
23 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
24 | gopkg.in/yaml.v3 v3.0.1 // indirect
25 | )
26 |
--------------------------------------------------------------------------------
/go/secrets/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "os"
7 |
8 | "dagger.io/dagger"
9 | )
10 |
11 | func main() {
12 | ctx := context.Background()
13 |
14 | // create Dagger client
15 | client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
16 | if err != nil {
17 | panic(err)
18 | }
19 | defer client.Close()
20 |
21 | secretEnv := client.SetSecret("my-secret-var", "secret value here")
22 | secretFile := client.SetSecret("my-secret-file", "secret file content here")
23 |
24 | // dump secrets to console
25 | out, err := client.Container().
26 | From("alpine:3.17").
27 | WithSecretVariable("MY_SECRET_VAR", secretEnv).
28 | WithMountedSecret("/my_secret_file", secretFile).
29 | WithExec([]string{"sh", "-c", `echo -e "secret env data: $MY_SECRET_VAR || secret file data: "; cat /my_secret_file`}).
30 | Stdout(ctx)
31 | if err != nil {
32 | panic(err)
33 | }
34 |
35 | fmt.Println(out)
36 | }
37 |
--------------------------------------------------------------------------------
/nodejs/multiplatform/build.js:
--------------------------------------------------------------------------------
1 | import { connect } from "@dagger.io/dagger"
2 | import { v4 as uuidv4 } from "uuid";
3 |
4 | // initialize Dagger client
5 | connect(async (client) => {
6 |
7 | const platforms = ["linux/amd64", "linux/arm64"]
8 |
9 | const project = client.git("https://github.com/dagger/dagger").branch("main").tree()
10 |
11 | const cache = client.cacheVolume("gomodcache")
12 |
13 | let buildArtifacts = client.directory()
14 |
15 | for (let i = 0; i < platforms.length; i++) {
16 | const build = client.container({platform: platforms[i]})
17 | .from("golang:1.20")
18 | .withDirectory("/src", project)
19 | .withWorkdir("/src")
20 | .withMountedCache("/cache", cache)
21 | .withEnvVariable("GOMODCACHE", "/cache")
22 | .withExec(["go", "build", "./cmd/dagger"])
23 |
24 | buildArtifacts = buildArtifacts.withFile(`${platforms[i]}/dagger`, build.file("/src/dagger"))
25 | }
26 |
27 | await buildArtifacts.export(".")
28 | }, {LogOutput: process.stdout})
29 |
--------------------------------------------------------------------------------
/go/gradle-build/ci.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "os"
7 |
8 | "dagger.io/dagger"
9 | )
10 |
11 | func main() {
12 | err := doCi()
13 | if err != nil {
14 | fmt.Println(err)
15 | }
16 | }
17 |
18 | func doCi() error {
19 | ctx := context.Background()
20 |
21 | // create a Dagger client
22 | client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
23 | if err != nil {
24 | return err
25 | }
26 | defer client.Close()
27 |
28 | src := client.Host().Directory(".") // get the projects source directory
29 |
30 | gradle := client.Container().From("gradle:latest"). // Build an gradle image with gradle and bash installed
31 | WithDirectory("/src", src).WithWorkdir("/src"). // mount source directory to /src
32 | WithExec([]string{"gradle", "build"}) // execute gradle build command
33 |
34 | // get gradle output
35 | out, err := gradle.Stdout(ctx)
36 | if err != nil {
37 | return err
38 | }
39 |
40 | // print output to console
41 | fmt.Println(out)
42 |
43 | return nil
44 | }
45 |
--------------------------------------------------------------------------------
/python/multistage/pipeline.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import anyio
3 | import dagger
4 | import uuid
5 |
6 |
7 | async def pipeline():
8 | async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
9 | project = client.git("https://github.com/dagger/dagger").branch("main").tree()
10 |
11 | build = (
12 | client.container()
13 | .from_("golang:1.20")
14 | .with_directory("/src", project)
15 | .with_workdir("/src")
16 | .with_exec(["go", "build", "./cmd/dagger"])
17 | )
18 |
19 | prod_image = (
20 | client.container()
21 | .from_("cgr.dev/chainguard/wolfi-base:latest")
22 | .with_default_args() # Set CMD to []
23 | .with_file("/bin/dagger", build.file("/src/dagger"))
24 | .with_entrypoint(["/bin/dagger"])
25 | )
26 |
27 | id = str(uuid.uuid4())
28 | tag = f'ttl.sh/dagger-{id}:1h'
29 |
30 | await prod_image.publish(tag)
31 |
32 |
33 |
34 |
35 | if __name__ == "__main__":
36 | anyio.run(pipeline)
--------------------------------------------------------------------------------
/nodejs/pulumi/README.md:
--------------------------------------------------------------------------------
1 | # App deployment to AWS with Dagger and Pulumi
2 |
3 | This codebase demonstrates using Dagger with [Pulumi](https://www.pulumi.com/) to deploy the [hello-dagger](https://github.com/dagger/hello-dagger) sample application to ECS on Fargate.
4 |
5 | The codebase contains the following:
6 |
7 | - `index.mjs` contains a Dagger build.
8 | - `/infra/ecr` contains a Pulumi program that creates an Amazon Elastic Container Registry. We use this registry to store our build artifact for deployment later.
9 | - `/infra/ecs` contains a Pulumi program that creates a VPC, ECS cluster, and deploys an ECS on Fargate service (the hello-dagger app) fronted by an Application Load Balancer.
10 |
11 | **IMPORTANT:** Be sure to tear down the infrastructure in the Pulumi stacks to avoid unwanted AWS charges once you are finished with this example!
12 |
13 | ```bash
14 | cd infra/ecs && pulumi stack select dev && pulumi destroy -y && pulumi stack rm dev -y && cd -
15 | ```
16 |
17 | ```bash
18 | cd infra/ecr && pulumi stack select dev && pulumi destroy -y && pulumi stack rm dev -y && cd -
19 | ```
20 |
--------------------------------------------------------------------------------
/go/multistage/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "os"
7 |
8 | "github.com/google/uuid"
9 |
10 | "dagger.io/dagger"
11 | )
12 |
13 | func main() {
14 | ctx := context.Background()
15 |
16 | // create a Dagger client
17 | client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
18 | if err != nil {
19 | panic(err)
20 | }
21 | defer client.Close()
22 |
23 | project := client.Git("https://github.com/dagger/dagger").Branch("main").Tree()
24 |
25 | build := client.Container().
26 | From("golang:1.20").
27 | WithDirectory("/src", project).
28 | WithWorkdir("/src").
29 | WithExec([]string{"go", "build", "./cmd/dagger"})
30 |
31 | prodImage := client.Container().
32 | From("cgr.dev/chainguard/wolfi-base:latest").
33 | WithDefaultArgs(). // Set CMD to []
34 | WithFile("/bin/dagger", build.File("/src/dagger")).
35 | WithEntrypoint([]string{"/bin/dagger"})
36 |
37 | // generate uuid for ttl.sh publish
38 | id := uuid.New()
39 | tag := fmt.Sprintf("ttl.sh/dagger-%s:1h", id.String())
40 |
41 | _, err = prodImage.Publish(ctx, tag)
42 | }
43 |
--------------------------------------------------------------------------------
/nodejs/db-service/build.js:
--------------------------------------------------------------------------------
1 | import { connect } from "@dagger.io/dagger"
2 |
3 | // initialize Dagger client
4 | connect(async (client) => {
5 |
6 | const database = client.container().from("postgres:15.2")
7 | .withEnvVariable("POSTGRES_PASSWORD", "test")
8 | .withExec(["postgres"])
9 | .withExposedPort(5432)
10 | // get reference to the local project
11 | const source = client.host().directory(".", { exclude: ["node_modules/"]})
12 |
13 | await client.container().from("node:16")
14 | .withServiceBinding("db", database) // bind database with the name db
15 | .withEnvVariable("DB_HOST", "db") // db refers to the service binding
16 | .withEnvVariable("DB_PASSWORD", "test") // password set in db container
17 | .withEnvVariable("DB_USER", "postgres") // default user in postgres image
18 | .withEnvVariable("DB_NAME", "postgres") // default db name in postgres image
19 | .withDirectory("/src", source)
20 | .withWorkdir("/src")
21 | .withExec(["npm", "install"])
22 | .withExec(["npm", "run", "test"]) // execute npm run test
23 | .stdout()
24 |
25 | }, {LogOutput: process.stdout})
26 |
--------------------------------------------------------------------------------
/nodejs/react-build/build.js:
--------------------------------------------------------------------------------
1 | import { connect } from "@dagger.io/dagger"
2 |
3 | // initialize Dagger client
4 | connect(async (client) => {
5 | // Set Node versions against which to test and build
6 | const nodeVersions = ["12", "14", "16"]
7 |
8 | // get reference to the local project
9 | const source = client.host().directory(".", { exclude: ["node_modules/"]})
10 |
11 | // for each Node version
12 | for (const nodeVersion of nodeVersions) {
13 | // mount cloned repository into Node image
14 | const runner = client
15 | .container().from(`node:${nodeVersion}`)
16 | .withDirectory("/src", source)
17 | .withWorkdir("/src")
18 | .withExec(["npm", "install"])
19 |
20 | // run tests
21 | await runner.withExec(["npm", "test", "--", "--watchAll=false"]).exitCode()
22 |
23 | // build application using specified Node version
24 | // write the build output to the host
25 | await runner
26 | .withExec(["npm", "run", "build"])
27 | .directory("build/")
28 | .export(`./build-node-${nodeVersion}`)
29 | }
30 | }, {LogOutput: process.stdout})
31 |
--------------------------------------------------------------------------------
/nodejs/react-build/build.ts:
--------------------------------------------------------------------------------
1 | import Client, { connect } from "@dagger.io/dagger"
2 |
3 | // initialize Dagger client
4 | connect(async (client: Client) => {
5 | // Set Node versions against which to test and build
6 | const nodeVersions = ["12", "14", "16"]
7 |
8 | // get reference to the local project
9 | const source = client.host().directory(".", { exclude: ["node_modules/"]})
10 |
11 | // for each Node version
12 | for (const nodeVersion of nodeVersions) {
13 | // mount cloned repository into Node image
14 | const runner = client
15 | .container().from(`node:${nodeVersion}`)
16 | .withDirectory("/src", source)
17 | .withWorkdir("/src")
18 | .withExec(["npm", "install"])
19 |
20 | // run tests
21 | await runner.withExec(["npm", "test", "--", "--watchAll=false"]).exitCode()
22 |
23 | // build application using specified Node version
24 | // write the build output to the host
25 | await runner
26 | .withExec(["npm", "run", "build"])
27 | .directory("build/")
28 | .export(`./build-node-${nodeVersion}`)
29 | }
30 | }, {LogOutput: process.stdout})
--------------------------------------------------------------------------------
/python/multiplatform/pipeline.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import anyio
3 | import dagger
4 | import uuid
5 |
6 |
7 | async def pipeline():
8 | async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client:
9 | platforms = ["linux/amd64", "linux/arm64"]
10 |
11 | project = client.git("https://github.com/dagger/dagger").branch("main").tree()
12 |
13 | cache = client.cache_volume("gomodcache")
14 |
15 | build_artifacts = client.directory()
16 |
17 | for platform in platforms:
18 | build = (
19 | client.container(platform=dagger.Platform(platform))
20 | .from_("golang:1.20")
21 | .with_directory("/src", project)
22 | .with_workdir("/src")
23 | .with_mounted_cache("/cache", cache)
24 | .with_env_variable("GOMODCACHE", "/cache")
25 | .with_exec(["go", "build", "./cmd/dagger"])
26 | )
27 | build_artifacts = build_artifacts.with_file(f'{platform}/dagger', build.file('/src/dagger'))
28 | await build_artifacts.export('.')
29 | if __name__ == "__main__":
30 | anyio.run(pipeline)
--------------------------------------------------------------------------------
/bash/git-build/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # get Go examples source code repository
4 | source=$(dagger --debug query <