Skip to content

Commit

Permalink
Merge pull request #1188 from openmeterio/dagger
Browse files Browse the repository at this point in the history
ci: upgrade Dagger
  • Loading branch information
sagikazarmark authored Jul 14, 2024
2 parents 024b40c + 4bcedd8 commit c9b088f
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:
contents: read

env:
DAGGER_VERSION: 0.11.8
DAGGER_VERSION: 0.12.0

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
module: github.com/${{ github.repository }}@${{ github.ref }}
args: --ref ${{ github.ref }} release --version ${{ github.ref_name }} --github-actor ${{ github.actor }} --github-token env:GITHUB_TOKEN --pypi-token env:PYPI_TOKEN --npm-token env:NPM_TOKEN
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.11.8"
version: "0.12.0"
env:
GITHUB_TOKEN: ${{ github.token }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
verb: call
args: --source .:default generate node-sdk -o api/client/node
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.11.8"
version: "0.12.0"

- name: Open pull request
uses: peter-evans/create-pull-request@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
verb: call
args: --source .:default generate python-sdk -o api/client/python
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.11.8"
version: "0.12.0"

- name: Open pull request
uses: peter-evans/create-pull-request@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
verb: call
args: --source .:default generate web-sdk -o api/client/web
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.11.8"
version: "0.12.0"

- name: Open pull request
uses: peter-evans/create-pull-request@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
module: github.com/${{ github.repository }}@${{ github.ref }}
args: --ref ${{ github.ref }} snapshot --stainless-token env:STAINLESS_TOKEN
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.11.8"
version: "0.12.0"
env:
STAINLESS_TOKEN: ${{ secrets.STAINLESS_TOKEN }}
74 changes: 38 additions & 36 deletions ci/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"time"

"github.com/sourcegraph/conc/pool"

"github.com/openmeterio/openmeter/ci/internal/dagger"
)

// Build individual artifacts. (Useful for testing and development)
Expand All @@ -17,15 +19,15 @@ func (m *Ci) Build() *Build {

type Build struct {
// +private
Source *Directory
Source *dagger.Directory
}

func (m *Build) All(
ctx context.Context,

// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
platform dagger.Platform,
) error {
p := pool.New().WithErrors().WithContext(ctx)

Expand All @@ -36,13 +38,13 @@ func (m *Build) All(
return p.Wait()
}

func (m *Build) containerImages(version string) []*Container {
platforms := []Platform{
func (m *Build) containerImages(version string) []*dagger.Container {
platforms := []dagger.Platform{
"linux/amd64",
"linux/arm64",
}

variants := make([]*Container, 0, len(platforms))
variants := make([]*dagger.Container, 0, len(platforms))

for _, platform := range platforms {
variants = append(variants, m.containerImage(platform, version))
Expand All @@ -55,21 +57,21 @@ func (m *Build) containerImages(version string) []*Container {
func (m *Build) ContainerImage(
// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
) *Container {
platform dagger.Platform,
) *dagger.Container {
return m.containerImage(platform, "")
}

func (m *Build) containerImage(platform Platform, version string) *Container {
return dag.Container(ContainerOpts{Platform: platform}).
func (m *Build) containerImage(platform dagger.Platform, version string) *dagger.Container {
return dag.Container(dagger.ContainerOpts{Platform: platform}).
From(alpineBaseImage).
WithLabel("org.opencontainers.image.title", "openmeter").
WithLabel("org.opencontainers.image.description", "Cloud Metering for AI, Billing and FinOps. Collect and aggregate millions of usage events in real-time.").
WithLabel("org.opencontainers.image.url", "https://github.com/openmeterio/openmeter").
WithLabel("org.opencontainers.image.created", time.Now().String()). // TODO: embed commit timestamp
WithLabel("org.opencontainers.image.source", "https://github.com/openmeterio/openmeter").
WithLabel("org.opencontainers.image.licenses", "Apache-2.0").
With(func(c *Container) *Container {
With(func(c *dagger.Container) *dagger.Container {
if version != "" {
c = c.WithLabel("org.opencontainers.image.version", version)
}
Expand All @@ -90,7 +92,7 @@ func (m *Build) Binary() *Binary {

type Binary struct {
// +private
Source *Directory
Source *dagger.Directory
}

// Build all binaries.
Expand All @@ -99,7 +101,7 @@ func (m *Binary) All(

// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
platform dagger.Platform,
) error {
p := pool.New().WithErrors().WithContext(ctx)

Expand All @@ -114,29 +116,29 @@ func (m *Binary) All(
func (m *Binary) Api(
// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
) *File {
platform dagger.Platform,
) *dagger.File {
return m.api(platform, "")
}

func (m *Binary) api(platform Platform, version string) *File {
func (m *Binary) api(platform dagger.Platform, version string) *dagger.File {
return m.buildCross(platform, version, "./cmd/server").WithName("server")
}

// Build the sink worker binary.
func (m *Binary) SinkWorker(
// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
) *File {
platform dagger.Platform,
) *dagger.File {
return m.sinkWorker(platform, "")
}

func (m *Binary) sinkWorker(platform Platform, version string) *File {
func (m *Binary) sinkWorker(platform dagger.Platform, version string) *dagger.File {
return m.buildCross(platform, version, "./cmd/sink-worker").WithName("sink-worker")
}

func (m *Binary) buildCross(platform Platform, version string, pkg string) *File {
func (m *Binary) buildCross(platform dagger.Platform, version string, pkg string) *dagger.File {
if version == "" {
version = "unknown"
}
Expand All @@ -145,7 +147,7 @@ func (m *Binary) buildCross(platform Platform, version string, pkg string) *File

binary := goMod.
WithSource(m.Source).
Build(GoWithSourceBuildOpts{
Build(dagger.GoWithSourceBuildOpts{
Pkg: pkg,
Trimpath: true,
Tags: []string{"musl"},
Expand All @@ -168,24 +170,24 @@ func (m *Binary) buildCross(platform Platform, version string, pkg string) *File
func (m *Binary) BenthosCollector(
// Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
// +optional
platform Platform,
) *File {
platform dagger.Platform,
) *dagger.File {
return m.benthosCollector(platform, "")
}

func (m *Binary) benthosCollector(platform Platform, version string) *File {
func (m *Binary) benthosCollector(platform dagger.Platform, version string) *dagger.File {
return m.build(platform, version, "./cmd/benthos-collector").WithName("benthos")
}

func (m *Binary) build(platform Platform, version string, pkg string) *File {
func (m *Binary) build(platform dagger.Platform, version string, pkg string) *dagger.File {
if version == "" {
version = "unknown"
}

return goModule().
WithSource(m.Source).
WithPlatform(platform).
Build(GoWithSourceBuildOpts{
Build(dagger.GoWithSourceBuildOpts{
Pkg: pkg,
Trimpath: true,
Ldflags: []string{
Expand All @@ -195,13 +197,13 @@ func (m *Binary) build(platform Platform, version string, pkg string) *File {
})
}

func goModule() *Go {
return dag.Go(GoOpts{Version: goBuildVersion}).
func goModule() *dagger.Go {
return dag.Go(dagger.GoOpts{Version: goBuildVersion}).
WithModuleCache(dag.CacheVolume("openmeter-go-mod-v2")).
WithBuildCache(dag.CacheVolume("openmeter-go-build-v2"))
}

func goModuleCross(platform Platform) *Go {
func goModuleCross(platform dagger.Platform) *dagger.Go {
container := goModule().
WithCgoEnabled(). // TODO: set env var instead?
Container().
Expand All @@ -211,7 +213,7 @@ func goModuleCross(platform Platform) *Go {
WithExec([]string{"xx-apk", "add", "--update", "--no-cache", "musl-dev", "gcc"}).
WithExec([]string{"xx-go", "--wrap"})

return dag.Go(GoOpts{Container: container})
return dag.Go(dagger.GoOpts{Container: container})
}

func (m *Build) HelmChart(
Expand All @@ -221,12 +223,12 @@ func (m *Build) HelmChart(
// Release version.
// +optional
version string,
) *File {
) *dagger.File {
return m.helmChart(name, version).File()
}

func (m *Build) helmChart(name string, version string) *HelmPackage {
opts := HelmChartPackageOpts{
func (m *Build) helmChart(name string, version string) *dagger.HelmPackage {
opts := dagger.HelmChartPackageOpts{
DependencyUpdate: true,
}

Expand All @@ -238,11 +240,11 @@ func (m *Build) helmChart(name string, version string) *HelmPackage {
return helmChart(m.Source, name).Package(opts)
}

func helmChart(source *Directory, name string) *HelmChart {
func helmChart(source *dagger.Directory, name string) *dagger.HelmChart {
chart := source.Directory("deploy/charts").Directory(name)

readme := dag.HelmDocs(HelmDocsOpts{Version: helmDocsVersion}).Generate(chart, HelmDocsGenerateOpts{
Templates: []*File{
readme := dag.HelmDocs(dagger.HelmDocsOpts{Version: helmDocsVersion}).Generate(chart, dagger.HelmDocsGenerateOpts{
Templates: []*dagger.File{
source.File("deploy/charts/template.md"),
chart.File("README.tmpl.md"),
},
Expand All @@ -251,5 +253,5 @@ func helmChart(source *Directory, name string) *HelmChart {

chart = chart.WithFile("README.md", readme)

return dag.Helm(HelmOpts{Version: helmVersion}).Chart(chart)
return dag.Helm(dagger.HelmOpts{Version: helmVersion}).Chart(chart)
}
14 changes: 8 additions & 6 deletions ci/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package main

import (
"fmt"

"github.com/openmeterio/openmeter/ci/internal/dagger"
)

func (m *Ci) Etoe(
// +optional
test string,
) *Container {
) *dagger.Container {
image := m.Build().ContainerImage("").
WithExposedPort(10000).
WithMountedFile("/etc/openmeter/config.yaml", m.Source.File("e2e/config.yaml")).
WithServiceBinding("kafka", dag.Kafka(KafkaOpts{Version: kafkaVersion}).Service()).
WithServiceBinding("kafka", dag.Kafka(dagger.KafkaOpts{Version: kafkaVersion}).Service()).
WithServiceBinding("clickhouse", clickhouse())

api := image.
Expand All @@ -35,7 +37,7 @@ func (m *Ci) Etoe(

args = append(args, "./e2e/...")

return dag.Go(GoOpts{
return dag.Go(dagger.GoOpts{
Container: goModule().
WithSource(m.Source).
Container().
Expand All @@ -47,7 +49,7 @@ func (m *Ci) Etoe(
Exec(args)
}

func clickhouse() *Service {
func clickhouse() *dagger.Service {
return dag.Container().
From(fmt.Sprintf("clickhouse/clickhouse-server:%s-alpine", clickhouseVersion)).
WithEnvVariable("CLICKHOUSE_USER", "default").
Expand All @@ -59,14 +61,14 @@ func clickhouse() *Service {
AsService()
}

func redis() *Service {
func redis() *dagger.Service {
return dag.Container().
From(fmt.Sprintf("redis:%s-alpine", redisVersion)).
WithExposedPort(6379).
AsService()
}

func postgres() *Service {
func postgres() *dagger.Service {
return dag.Container().
From(fmt.Sprintf("postgres:%s", postgresVersion)).
WithEnvVariable("POSTGRES_USER", "postgres").
Expand Down
10 changes: 6 additions & 4 deletions ci/generate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

import "github.com/openmeterio/openmeter/ci/internal/dagger"

// Generate various artifacts.
func (m *Ci) Generate() *Generate {
return &Generate{
Expand All @@ -9,11 +11,11 @@ func (m *Ci) Generate() *Generate {

type Generate struct {
// +private
Source *Directory
Source *dagger.Directory
}

// Generate the Python SDK.
func (m *Generate) PythonSdk() *Directory {
func (m *Generate) PythonSdk() *dagger.Directory {
// We build our image as the official autorest Dockerfile is outdated
// and not compatible with the latest autorest.
// More specifically, the latest autorest npm package depends on
Expand All @@ -33,7 +35,7 @@ func (m *Generate) PythonSdk() *Directory {
}

// Generate the Node SDK.
func (m *Generate) NodeSdk() *Directory {
func (m *Generate) NodeSdk() *dagger.Directory {
return dag.Container().
From("node:20-alpine").
WithExec([]string{"npm", "install", "-g", "pnpm"}).
Expand All @@ -47,7 +49,7 @@ func (m *Generate) NodeSdk() *Directory {
}

// Generate the Web SDK.
func (m *Generate) WebSdk() *Directory {
func (m *Generate) WebSdk() *dagger.Directory {
return dag.Container().
From("node:20-alpine").
WithExec([]string{"npm", "install", "-g", "pnpm"}).
Expand Down
Loading

0 comments on commit c9b088f

Please sign in to comment.