add build steps
This commit is contained in:
parent
626e7bec93
commit
f5d28094c8
@ -18,7 +18,7 @@ steps:
|
||||
- mkdir -p tmp/dagger-go
|
||||
- git clone "https://git.front.kjuulh.io/kjuulh/dagger-go.git" tmp/dagger-go
|
||||
- docker build -t dagger-go-builder:${DRONE_COMMIT} -f tmp/dagger-go/Dockerfile .
|
||||
- 'docker run -v /var/run/docker.sock:/var/run/docker.sock dagger-go-builder:${DRONE_COMMIT} ./dagger-go build "{{ or .input.imageTag $imageTag }}"'
|
||||
- 'docker run -v /var/run/docker.sock:/var/run/docker.sock dagger-go-builder:${DRONE_COMMIT} ./dagger-go build --image-tag "{{ or .input.imageTag $imageTag }}"'
|
||||
|
||||
services:
|
||||
- name: docker
|
||||
|
3
go.mod
3
go.mod
@ -8,6 +8,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
git.front.kjuulh.io/kjuulh/byg v0.0.1 // indirect
|
||||
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
|
||||
@ -68,7 +69,7 @@ require (
|
||||
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/sync v0.1.0 // 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
|
||||
|
4
go.sum
4
go.sum
@ -35,6 +35,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
|
||||
dagger.io/dagger v0.3.1 h1:JjUTPyDSrs+pDPmopVfhYAldHS4Rxn3XechACUlmTHQ=
|
||||
dagger.io/dagger v0.3.1/go.mod h1:+p5s9Itrr/KT4UttGNpeUTNtVQUI2z9LDIOH9wBzu8g=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
git.front.kjuulh.io/kjuulh/byg v0.0.1 h1:SBrM5WBv1zTzt29pQMwGUJljGRI7Li7uATnZ3taotC0=
|
||||
git.front.kjuulh.io/kjuulh/byg v0.0.1/go.mod h1:8Vg5Mgqzva5fzHGeMlxjp/DMLbUy9uaKFxMNB34yYuA=
|
||||
github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
@ -506,6 +508,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
@ -2,13 +2,26 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
func CreateBuilder(ctx context.Context) error {
|
||||
type Builder struct {
|
||||
Dagger *dagger.Client
|
||||
}
|
||||
|
||||
func New(ctx context.Context) (*Builder, error) {
|
||||
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Builder{
|
||||
Dagger: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *Builder) CleanUp() error {
|
||||
return b.Dagger.Close()
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Build(requirementsf func(*cobra.Command), buildf func(ctx context.Context) error) *cobra.Command {
|
||||
func Build() *cobra.Command {
|
||||
var (
|
||||
imageTag string
|
||||
)
|
||||
@ -20,21 +20,22 @@ func Build(requirementsf func(*cobra.Command), buildf func(ctx context.Context)
|
||||
return err
|
||||
}
|
||||
|
||||
if imageTag != "" {
|
||||
log.Printf("Building image: %s\n", imageTag)
|
||||
}
|
||||
ctx := cmd.Context()
|
||||
|
||||
if buildf != nil {
|
||||
return buildf(cmd.Context())
|
||||
}
|
||||
log.Printf("Building image: %s\n", imageTag)
|
||||
|
||||
return tasks.Build(imageTag)
|
||||
client, err := internal.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.CleanUp()
|
||||
|
||||
return tasks.Build(client, imageTag)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name")
|
||||
|
||||
requirementsf(cmd)
|
||||
cmd.MarkPersistentFlagRequired("image-tag")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -1,10 +1,44 @@
|
||||
package tasks
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
func Build(imageTag string) error {
|
||||
"dagger.io/dagger"
|
||||
"git.front.kjuulh.io/kjuulh/byg"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
)
|
||||
|
||||
func Build(builder *internal.Builder, imageTag string) error {
|
||||
log.Printf("building image: %s", imageTag)
|
||||
|
||||
return nil
|
||||
client := builder.Dagger
|
||||
ctx := context.Background()
|
||||
|
||||
return byg.
|
||||
New().
|
||||
Step(
|
||||
"build golang",
|
||||
byg.Step{
|
||||
Execute: func(_ byg.Context) error {
|
||||
src, err := client.
|
||||
Host().
|
||||
Workdir().
|
||||
Read().
|
||||
ID(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
golang := client.Container().From("golang:latest")
|
||||
golang = golang.WithMountedDirectory("/src", src).WithWorkdir("/src")
|
||||
_, err = golang.Exec(dagger.ContainerExecOpts{
|
||||
Args: []string{"go", "build", "-o", "build/"},
|
||||
}).ExitCode(ctx)
|
||||
|
||||
return err
|
||||
},
|
||||
}).
|
||||
Execute(context.Background())
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user