From b3a50d88314ac36ca5ae7bb44d01484a2feae223 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 26 Jun 2024 21:05:21 +0200 Subject: [PATCH 1/6] add test method example and test --- examples/main.go | 21 ++++++++++++++++++++- helm/dagger/main.go | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/main.go b/examples/main.go index 4ab633d..69adbce 100644 --- a/examples/main.go +++ b/examples/main.go @@ -14,6 +14,7 @@ func (m *Examples) All(ctx context.Context) error { p := pool.New().WithErrors().WithContext(ctx) p.Go(m.Version) + p.Go(m.Test) return p.Wait() } @@ -24,7 +25,7 @@ func (m *Examples) Version( ) error { const expected = "0.1.1" - // dagger call version --directory ./mychart/ + // dagger call version --directory ./examples/testdata/mychart/ directory := dag.CurrentModule().Source().Directory("testdata/mychart/") version, err := dag.Helm().Version(ctx, directory) @@ -38,3 +39,21 @@ func (m *Examples) Version( return nil } + + +func (m *Examples) Test( + // method call context + ctx context.Context, +) error { + args := []string{"."} + + // dagger call test --directory ./examples/testdata/mychart/ --args "." + directory := dag.CurrentModule().Source().Directory("testdata/mychart/") + _, err := dag.Helm().Test(ctx, directory, args) + + if err != nil { + return err + } + + return nil +} diff --git a/helm/dagger/main.go b/helm/dagger/main.go index 68d97af..b5a068d 100644 --- a/helm/dagger/main.go +++ b/helm/dagger/main.go @@ -40,7 +40,7 @@ func (p PushOpts) getRepoFqdn() string { // Get and display the version of the Helm Chart located inside the given directory. // -// Example usage: dagger call version --directory ./mychart/ +// Example usage: dagger call version --directory ./examples/testdata/mychart/ func (h *Helm) Version( // method call context ctx context.Context, @@ -146,7 +146,7 @@ func (h *Helm) PackagePush( // Provide the helm chart directory with pointing to it with the `--directory` flag. // Add the directory location with `"."` as `--args` parameter to tell helm unittest where to find the helm chart with the tests. // -// Example usage: dagger call test --directory ./mychart/ --args "." +// Example usage: dagger call test --directory ./examples/testdata/mychart/ --args "." func (h *Helm) Test( // method call context ctx context.Context, From 0fc9c6f64136d1f01cb19790db87c220282fd9b8 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 17 Jul 2024 13:45:37 +0200 Subject: [PATCH 2/6] add ci module for container build --- ci/.gitattributes | 4 ++ ci/.gitignore | 4 ++ ci/Containerfile.helm | 33 ++++++++++++++++ ci/dagger.json | 6 +++ ci/go.mod | 40 ++++++++++++++++++++ ci/go.sum | 87 +++++++++++++++++++++++++++++++++++++++++++ ci/main.go | 39 +++++++++++++++++++ 7 files changed, 213 insertions(+) create mode 100644 ci/.gitattributes create mode 100644 ci/.gitignore create mode 100644 ci/Containerfile.helm create mode 100644 ci/dagger.json create mode 100644 ci/go.mod create mode 100644 ci/go.sum create mode 100644 ci/main.go diff --git a/ci/.gitattributes b/ci/.gitattributes new file mode 100644 index 0000000..3a45493 --- /dev/null +++ b/ci/.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/ci/.gitignore b/ci/.gitignore new file mode 100644 index 0000000..7ebabcc --- /dev/null +++ b/ci/.gitignore @@ -0,0 +1,4 @@ +/dagger.gen.go +/internal/dagger +/internal/querybuilder +/internal/telemetry diff --git a/ci/Containerfile.helm b/ci/Containerfile.helm new file mode 100644 index 0000000..380163e --- /dev/null +++ b/ci/Containerfile.helm @@ -0,0 +1,33 @@ +FROM registry.access.redhat.com/ubi9:9.4-1123.1719560047 + +ARG HELM_PACKAGE=https://get.helm.sh/helm-v3.15.3-linux-amd64.tar.gz +ARG HELM_UNITTEST_PACKAGE=https://github.com/helm-unittest/helm-unittest/releases/download/v0.5.1/helm-unittest-linux-amd64-0.5.1.tgz + +# Environment variables +ENV \ + HOME="/helm" + +RUN \ + # install Helm + curl ${HELM_PACKAGE} -o /tmp/helm.tar.gz && \ + tar xvfz /tmp/helm.tar.gz -C /tmp && \ + cp -a /tmp/linux-amd64/helm /usr/local/bin/helm && \ + rm -rf /tmp/helm.tar.gz /tmp/linux-amd64 && \ + # Install Helm unittest plugin + mkdir -p /tmp/hut && \ + curl ${HELM_UNITTEST_PACKAGE} -L -o /tmp/helm-unittest.tgz && \ + tar xvfz /tmp/helm-unittest.tgz -C /tmp/hut && \ + cp /tmp/hut/untt /usr/local/bin/helm-unittest && \ + rm -rf /tmp/helm-unittest.tar.gz /tmp/hut && \ + # make all binaries executable + chmod +x /usr/local/bin/* + +WORKDIR /helm + +RUN chown -R 1001:0 /helm && \ + chmod -R g=u /helm + +USER 1001 + +ENTRYPOINT ["/usr/local/bin/helm"] +CMD ["--help"] diff --git a/ci/dagger.json b/ci/dagger.json new file mode 100644 index 0000000..232598f --- /dev/null +++ b/ci/dagger.json @@ -0,0 +1,6 @@ +{ + "name": "ci", + "sdk": "go", + "source": ".", + "engineVersion": "v0.11.9" +} diff --git a/ci/go.mod b/ci/go.mod new file mode 100644 index 0000000..8012829 --- /dev/null +++ b/ci/go.mod @@ -0,0 +1,40 @@ +module dagger/ci + +go 1.22.4 + +require ( + github.com/99designs/gqlgen v0.17.44 + github.com/Khan/genqlient v0.7.0 + github.com/vektah/gqlparser/v2 v2.5.11 + 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.7.0 + google.golang.org/grpc v1.64.0 +) + +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.20.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/sosodev/duration v1.2.0 // 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.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-20240520151616-dc85e6b867a5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect + google.golang.org/protobuf v1.34.1 // indirect +) diff --git a/ci/go.sum b/ci/go.sum new file mode 100644 index 0000000..5549486 --- /dev/null +++ b/ci/go.sum @@ -0,0 +1,87 @@ +github.com/99designs/gqlgen v0.17.44 h1:OS2wLk/67Y+vXM75XHbwRnNYJcbuJd4OBL76RX3NQQA= +github.com/99designs/gqlgen v0.17.44/go.mod h1:UTCu3xpK2mLI5qcMNw+HKDiEL77it/1XtAjisC4sLwM= +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.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +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.2.0 h1:pqK/FLSjsAADWY74SyWDCjOcd5l7H8GSnnOGEB9A1Us= +github.com/sosodev/duration v1.2.0/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.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= +github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= +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.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +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/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +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/ci/main.go b/ci/main.go new file mode 100644 index 0000000..924d3ed --- /dev/null +++ b/ci/main.go @@ -0,0 +1,39 @@ +// CI Pipelines +// +// This module is used to build everything for the dagger-module-helm. + +package main + +import ( + "context" + "dagger/ci/internal/dagger" +) + +type Ci struct{} + +// Build and publish image from Dockerfile using a build context directory +// in a different location than the current working directory +func (m *Ci) Build( + ctx context.Context, +) (*dagger.Container) { + + // location of source directory + src := dag.CurrentModule().Source().Directory(".") + + // location of Containerfile + containerfile := dag.CurrentModule().Source().File("Containerfile.helm") + + // get build context with dockerfile added + workspace := dag.Container(). + WithDirectory("/src", src). + WithWorkdir("/src"). + WithFile("/src/custom.Dockerfile", containerfile). + Directory("/src") + + // build using Dockerfile and publish to registry + //ref, err := dag.Container(). + return dag.Container(). + Build(workspace, dagger.ContainerBuildOpts{ + Dockerfile: "custom.Dockerfile", + }) // .Publish(ctx, "ttl.sh/hello-dagger") +} From 4b62f24959e4a4d2534d4ec3aa1b59e11d3c3095 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 17 Jul 2024 13:48:32 +0200 Subject: [PATCH 3/6] use new image built here --- ci/Containerfile.helm | 9 ++++++++- ci/main.go | 42 +++++++++++++++++++++++++++++++++++++++--- examples/main.go | 2 +- helm/dagger/main.go | 13 ++++++++++--- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ci/Containerfile.helm b/ci/Containerfile.helm index 380163e..77ac68d 100644 --- a/ci/Containerfile.helm +++ b/ci/Containerfile.helm @@ -2,6 +2,7 @@ FROM registry.access.redhat.com/ubi9:9.4-1123.1719560047 ARG HELM_PACKAGE=https://get.helm.sh/helm-v3.15.3-linux-amd64.tar.gz ARG HELM_UNITTEST_PACKAGE=https://github.com/helm-unittest/helm-unittest/releases/download/v0.5.1/helm-unittest-linux-amd64-0.5.1.tgz +ARG YQ_PACKAGE=https://github.com/mikefarah/yq/releases/download/v4.44.2/yq_linux_amd64.tar.gz # Environment variables ENV \ @@ -9,7 +10,7 @@ ENV \ RUN \ # install Helm - curl ${HELM_PACKAGE} -o /tmp/helm.tar.gz && \ + curl ${HELM_PACKAGE} -L -o /tmp/helm.tar.gz && \ tar xvfz /tmp/helm.tar.gz -C /tmp && \ cp -a /tmp/linux-amd64/helm /usr/local/bin/helm && \ rm -rf /tmp/helm.tar.gz /tmp/linux-amd64 && \ @@ -19,6 +20,12 @@ RUN \ tar xvfz /tmp/helm-unittest.tgz -C /tmp/hut && \ cp /tmp/hut/untt /usr/local/bin/helm-unittest && \ rm -rf /tmp/helm-unittest.tar.gz /tmp/hut && \ + # install yq + curl ${YQ_PACKAGE} -L -o /tmp/yq.tar.gz && \ + mkdir -p /tmp/yq && \ + tar xvfz /tmp/yq.tar.gz -C /tmp/yq && \ + cp -a /tmp/yq/yq_linux_amd64 /usr/local/bin/yq && \ + rm -rf /tmp/yq.tar.gz /tmp/yq && \ # make all binaries executable chmod +x /usr/local/bin/* diff --git a/ci/main.go b/ci/main.go index 924d3ed..8bb26e2 100644 --- a/ci/main.go +++ b/ci/main.go @@ -7,6 +7,7 @@ package main import ( "context" "dagger/ci/internal/dagger" + "fmt" ) type Ci struct{} @@ -30,10 +31,45 @@ func (m *Ci) Build( WithFile("/src/custom.Dockerfile", containerfile). Directory("/src") - // build using Dockerfile and publish to registry - //ref, err := dag.Container(). + // build using Dockerfile return dag.Container(). Build(workspace, dagger.ContainerBuildOpts{ Dockerfile: "custom.Dockerfile", - }) // .Publish(ctx, "ttl.sh/hello-dagger") + }) +} + +func (m *Ci) Publish( + ctx context.Context, + // URL of the registry + registry string, + // name of the repository + repository string, + // tag of the image + // +optional + tag string, + // registry user name + username string, + // registry user password + password *dagger.Secret, +) (string, error) { + + container := m.Build(ctx) + + imageTag := "latest" + if tag != "" { + imageTag = tag + } + + reference := fmt.Sprintf("%s/%s:%s", registry, repository, imageTag) + + // publish to registry + ref, err := container. + WithRegistryAuth(registry, username, password). + Publish(ctx, reference) + + if err != nil { + return "", err + } + + return ref, nil } diff --git a/examples/main.go b/examples/main.go index 69adbce..46c4238 100644 --- a/examples/main.go +++ b/examples/main.go @@ -14,7 +14,7 @@ func (m *Examples) All(ctx context.Context) error { p := pool.New().WithErrors().WithContext(ctx) p.Go(m.Version) - p.Go(m.Test) + // p.Go(m.Test) return p.Wait() } diff --git a/helm/dagger/main.go b/helm/dagger/main.go index b5a068d..acb44c1 100644 --- a/helm/dagger/main.go +++ b/helm/dagger/main.go @@ -13,6 +13,8 @@ import ( "strings" ) +const REGISTRY string = "quay.io/puzzle/dagger-module-helm:latest" + type Helm struct { } @@ -47,9 +49,11 @@ func (h *Helm) Version( // directory that contains the Helm Chart directory *Directory, ) (string, error) { - c := dag.Container().From("registry.puzzle.ch/cicd/alpine-base:latest"). + c := dag.Container(). + From(REGISTRY). WithDirectory("/helm", directory). - WithWorkdir("/helm") + WithWorkdir("/helm"). + WithoutEntrypoint() version, err := c.WithExec([]string{"sh", "-c", "helm show chart . | yq eval '.version' -"}).Stdout(ctx) if err != nil { return "", err @@ -93,7 +97,10 @@ func (h *Helm) PackagePush( } fmt.Fprintf(os.Stdout, "☸️ Helm package and Push") - c := dag.Container().From("registry.puzzle.ch/cicd/alpine-base:latest").WithDirectory("/helm", directory).WithWorkdir("/helm") + c := dag.Container(). + From("registry.puzzle.ch/cicd/alpine-base:latest"). + WithDirectory("/helm", directory). + WithWorkdir("/helm") version, err := c.WithExec([]string{"sh", "-c", "helm show chart . | yq eval '.version' -"}).Stdout(ctx) if err != nil { return false, err From c3ede4e6f25b5adc6f3a2f4286fd6a84311d4595 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 17 Jul 2024 14:01:04 +0200 Subject: [PATCH 4/6] use own image for helm unittest --- examples/main.go | 2 +- helm/dagger/main.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/main.go b/examples/main.go index 46c4238..69adbce 100644 --- a/examples/main.go +++ b/examples/main.go @@ -14,7 +14,7 @@ func (m *Examples) All(ctx context.Context) error { p := pool.New().WithErrors().WithContext(ctx) p.Go(m.Version) - // p.Go(m.Test) + p.Go(m.Test) return p.Wait() } diff --git a/helm/dagger/main.go b/helm/dagger/main.go index acb44c1..9c7e010 100644 --- a/helm/dagger/main.go +++ b/helm/dagger/main.go @@ -162,8 +162,12 @@ func (h *Helm) Test( // Helm Unittest arguments args []string, ) (string, error) { - c := dag.Container().From("helmunittest/helm-unittest").WithDirectory("/helm", directory).WithWorkdir("/helm") - out, err := c.WithExec(args).Stdout(ctx) + c := dag.Container(). + From(REGISTRY). + WithDirectory("/helm", directory). + WithWorkdir("/helm"). + WithoutEntrypoint() + out, err := c.WithExec([]string{"sh", "-c", fmt.Sprintf("%s %s", "helm-unittest", strings.Join(args, " "))}).Stdout(ctx) if err != nil { return "", err } From a6e9b8210a7ceed8b0d2f5010fe1db6b03a6a077 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 17 Jul 2024 14:08:45 +0200 Subject: [PATCH 5/6] rename image const --- helm/dagger/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helm/dagger/main.go b/helm/dagger/main.go index 9c7e010..01c1a0e 100644 --- a/helm/dagger/main.go +++ b/helm/dagger/main.go @@ -13,7 +13,7 @@ import ( "strings" ) -const REGISTRY string = "quay.io/puzzle/dagger-module-helm:latest" +const HELM_IMAGE string = "quay.io/puzzle/dagger-module-helm:latest" type Helm struct { } @@ -50,7 +50,7 @@ func (h *Helm) Version( directory *Directory, ) (string, error) { c := dag.Container(). - From(REGISTRY). + From(HELM_IMAGE). WithDirectory("/helm", directory). WithWorkdir("/helm"). WithoutEntrypoint() @@ -163,7 +163,7 @@ func (h *Helm) Test( args []string, ) (string, error) { c := dag.Container(). - From(REGISTRY). + From(HELM_IMAGE). WithDirectory("/helm", directory). WithWorkdir("/helm"). WithoutEntrypoint() From 01330b3c7b6533f30065a65e1a70f938c15d8b8b Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Wed, 17 Jul 2024 14:21:31 +0200 Subject: [PATCH 6/6] owner dir options --- helm/dagger/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/dagger/main.go b/helm/dagger/main.go index 01c1a0e..a1d1e72 100644 --- a/helm/dagger/main.go +++ b/helm/dagger/main.go @@ -164,7 +164,7 @@ func (h *Helm) Test( ) (string, error) { c := dag.Container(). From(HELM_IMAGE). - WithDirectory("/helm", directory). + WithDirectory("/helm", directory, ContainerWithDirectoryOpts{Owner: "1001"}). WithWorkdir("/helm"). WithoutEntrypoint() out, err := c.WithExec([]string{"sh", "-c", fmt.Sprintf("%s %s", "helm-unittest", strings.Join(args, " "))}).Stdout(ctx)