diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d286afa..2d51a7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,10 @@ name: Dagger test on: push: +env: + # The Dagger CLI uses the DAGGER_CLOUD_TOKEN environment variable to authenticate with Dagger Cloud + DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN}} + jobs: build: name: build @@ -11,12 +15,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Dagger CLI run: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; } - # The Dagger CLI uses the DAGGER_CLOUD_TOKEN environment variable to authenticate with Dagger Cloud - - name: Run Dagger pipeline + - name: Display module functions run: dagger functions -m helm/ - env: - DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN}} - # For ephemeral runners only: overrides the default Docker stop timeout to give the Dagger engine more time to push cache data to Dagger Cloud - - name: Stop Engine - run: docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q) - if: always() + - name: Run module tests + run: dagger -m examples/ call all diff --git a/.gitignore b/.gitignore index 708fc68..e72b728 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ dagger.gen.go helm/dagger/internal +go.work +go.work.sum diff --git a/README.md b/README.md index 9c303e1..65748d4 100644 --- a/README.md +++ b/README.md @@ -41,31 +41,8 @@ mkdir helm/ cd helm/ # initialize Dagger module -dagger mod init --sdk go --name helm -``` - -### setup development module - -Setup the outer module to be able to develop the Dagger Helm module. - -```bash -dagger mod init --sdk go --name modest -dagger mod use ./helm -``` - -Generate or re-generate the Go definitions file (dagger.gen.go) for use in code completion. - -```bash -dagger mod install -``` - -The functions of the module are available by the `dag` variable. Type `dag.` in your Go file for code completion. - - -Update the module: - -```bash -dagger mod update +dagger init +dagger develop --sdk go --source helm ``` ## To Do diff --git a/examples/dagger.json b/examples/dagger.json new file mode 100644 index 0000000..63e07fb --- /dev/null +++ b/examples/dagger.json @@ -0,0 +1,12 @@ +{ + "name": "examples", + "sdk": "go", + "dependencies": [ + { + "name": "helm", + "source": "../helm" + } + ], + "source": ".", + "engineVersion": "v0.11.6" +} diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..65c5886 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,41 @@ +module dagger/apko/tests + +go 1.22.2 + +require ( + github.com/99designs/gqlgen v0.17.46 + github.com/Khan/genqlient v0.7.0 + github.com/sourcegraph/conc v0.3.0 + github.com/vektah/gqlparser/v2 v2.5.11 + go.opentelemetry.io/otel v1.24.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 + go.opentelemetry.io/otel/sdk v1.24.0 + go.opentelemetry.io/otel/trace v1.24.0 + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 + golang.org/x/sync v0.7.0 + google.golang.org/grpc v1.63.2 +) + +require ( + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.9.0 // indirect +) + +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.19.1 // indirect + github.com/sosodev/duration v1.3.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/proto/otlp v1.2.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect + google.golang.org/protobuf v1.34.0 // indirect +) diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..4b494ea --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,70 @@ +github.com/99designs/gqlgen v0.17.46 h1:Dk/pSCMVp57z/vd6gwZ/wmqbPOL3i5iz4YQHTDfxyuw= +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.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= +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.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/sosodev/duration v1.3.0 h1:g3E6mto+hFdA2uZXeNDYff8LYeg7v5D4YKP/Ng/NUkE= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +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.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= +github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 h1:Mw5xcxMwlqoJd97vwPxA8isEaIoxsta9/Q51+TTJLGE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0/go.mod h1:CQNu9bj7o7mC6U7+CA/schKEYakYXWr79ucDHTMGhCM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= +go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +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.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= +google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= +google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= +google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= +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/examples/main.go b/examples/main.go new file mode 100644 index 0000000..4ab633d --- /dev/null +++ b/examples/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "context" + "fmt" + + "github.com/sourcegraph/conc/pool" +) + +type Examples struct{} + +// All executes all tests. +func (m *Examples) All(ctx context.Context) error { + p := pool.New().WithErrors().WithContext(ctx) + + p.Go(m.Version) + + return p.Wait() +} + +func (m *Examples) Version( + // method call context + ctx context.Context, +) error { + const expected = "0.1.1" + + // dagger call version --directory ./mychart/ + directory := dag.CurrentModule().Source().Directory("testdata/mychart/") + version, err := dag.Helm().Version(ctx, directory) + + if err != nil { + return err + } + + if version != expected { + return fmt.Errorf("expected %q, got %q", expected, version) + } + + return nil +} diff --git a/mychart/.helmignore b/examples/testdata/mychart/.helmignore similarity index 100% rename from mychart/.helmignore rename to examples/testdata/mychart/.helmignore diff --git a/mychart/Chart.yaml b/examples/testdata/mychart/Chart.yaml similarity index 100% rename from mychart/Chart.yaml rename to examples/testdata/mychart/Chart.yaml diff --git a/mychart/templates/NOTES.txt b/examples/testdata/mychart/templates/NOTES.txt similarity index 100% rename from mychart/templates/NOTES.txt rename to examples/testdata/mychart/templates/NOTES.txt diff --git a/mychart/templates/_helpers.tpl b/examples/testdata/mychart/templates/_helpers.tpl similarity index 100% rename from mychart/templates/_helpers.tpl rename to examples/testdata/mychart/templates/_helpers.tpl diff --git a/mychart/templates/deployment.yaml b/examples/testdata/mychart/templates/deployment.yaml similarity index 100% rename from mychart/templates/deployment.yaml rename to examples/testdata/mychart/templates/deployment.yaml diff --git a/mychart/templates/hpa.yaml b/examples/testdata/mychart/templates/hpa.yaml similarity index 100% rename from mychart/templates/hpa.yaml rename to examples/testdata/mychart/templates/hpa.yaml diff --git a/mychart/templates/ingress.yaml b/examples/testdata/mychart/templates/ingress.yaml similarity index 100% rename from mychart/templates/ingress.yaml rename to examples/testdata/mychart/templates/ingress.yaml diff --git a/mychart/templates/service.yaml b/examples/testdata/mychart/templates/service.yaml similarity index 100% rename from mychart/templates/service.yaml rename to examples/testdata/mychart/templates/service.yaml diff --git a/mychart/templates/serviceaccount.yaml b/examples/testdata/mychart/templates/serviceaccount.yaml similarity index 100% rename from mychart/templates/serviceaccount.yaml rename to examples/testdata/mychart/templates/serviceaccount.yaml diff --git a/mychart/templates/tests/test-connection.yaml b/examples/testdata/mychart/templates/tests/test-connection.yaml similarity index 100% rename from mychart/templates/tests/test-connection.yaml rename to examples/testdata/mychart/templates/tests/test-connection.yaml diff --git a/mychart/tests/deployment_test.yaml b/examples/testdata/mychart/tests/deployment_test.yaml similarity index 100% rename from mychart/tests/deployment_test.yaml rename to examples/testdata/mychart/tests/deployment_test.yaml diff --git a/mychart/values.yaml b/examples/testdata/mychart/values.yaml similarity index 100% rename from mychart/values.yaml rename to examples/testdata/mychart/values.yaml