Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dagger go sdk support. Run mage goGaBadge #49

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ dist
# TernJS port file
.tern-port
dist/

ga-badge
20 changes: 20 additions & 0 deletions cli/build/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package build

import (
"context"

"dagger.io/dagger"
"github.com/abtris/ga-badge/daggerutils"
)

func Build(ctx context.Context, client *dagger.Client, os, arch string) *dagger.Directory {
directory := client.Host().Workdir()
return daggerutils.GoBuild(daggerutils.GoBuildInput{
Client: client,
Os: os,
Arch: arch,
Ctx: ctx,
Directory: directory,
Workdir: "cli/",
})
}
4 changes: 2 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"

"log"
"net/url"
"os"
Expand Down Expand Up @@ -67,7 +67,7 @@ func ensureDir(dirName string) error {

func createFile(content []byte, filename string) error {
if _, err := os.Stat(".github/workflows/" + filename); os.IsNotExist(err) {
err := ioutil.WriteFile(".github/workflows/"+filename, content, os.ModePerm)
err := os.WriteFile(".github/workflows/"+filename, content, os.ModePerm)
if err != nil {
return err
}
Expand Down
40 changes: 40 additions & 0 deletions daggerutils/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package daggerutils

import (
"context"
"path"

"dagger.io/dagger"
)

const (
golangImage = "golang:latest"
)

type GoBuildInput struct {
Directory *dagger.Directory
Client *dagger.Client
Ctx context.Context
Os string
Arch string
Workdir string
}

func GoBuild(cfg GoBuildInput) *dagger.Directory {
// Load image
builder := cfg.Client.Container().From(golangImage)

workdir := path.Join("/src", cfg.Workdir)

builder = builder.WithMountedDirectory("/src", cfg.Directory).
WithWorkdir(workdir).
WithEnvVariable("GOARCH", cfg.Arch).
WithEnvVariable("GOOS", cfg.Os)

// Execute Command
builder = builder.Exec(dagger.ContainerExecOpts{
Args: []string{"go", "build", "-o", "ga-badge"},
})

return builder.Directory(workdir)
}
74 changes: 71 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,80 @@
module github.com/abtris/ga-badge

go 1.17
go 1.19

require github.com/urfave/cli/v2 v2.11.1
require (
dagger.io/dagger v0.4.0
github.com/urfave/cli/v2 v2.23.5
)

require (
github.com/Khan/genqlient v0.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/containerd v1.6.9 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dagger/dagger v0.3.3 // indirect
github.com/dagger/graphql v0.0.0-20221102000338-24d5e47d3b72 // indirect
github.com/dagger/graphql-go-tools v0.0.0-20221102001222-e68b44170936 // indirect
github.com/docker/cli v20.10.17+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.17+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/buildkit v0.10.5 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rs/zerolog v1.28.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/tonistiigi/fsutil v0.0.0-20220115021204-b19f7f9cb274 // indirect
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f // indirect
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.34.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.4.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.9.0 // indirect
go.opentelemetry.io/otel/sdk v1.9.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)

replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible
Loading