with buildpath
This commit is contained in:
parent
e9dd36f1e4
commit
f89936200e
@ -16,7 +16,7 @@ steps:
|
||||
- "sleep 5"
|
||||
- apk add git
|
||||
- mkdir -p tmp/dagger-go
|
||||
- git clone "https://git.front.kjuulh.io/kjuulh/dagger-go.git" /mnt/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 "$PWD/:/src/" -v /var/run/docker.sock:/var/run/docker.sock dagger-go-builder:${DRONE_COMMIT} dagger-go build --image-tag "{{ or .input.imageTag $imageTag }}"'
|
||||
|
||||
|
27
example/main.go
Normal file
27
example/main.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := run(ctx); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
builder, err := internal.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer builder.CleanUp()
|
||||
|
||||
return tasks.Build(builder, "some-image")
|
||||
}
|
@ -10,7 +10,7 @@ import (
|
||||
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
|
||||
)
|
||||
|
||||
func Build(builder *internal.Builder, imageTag string) error {
|
||||
func Build(builder *internal.Builder, imageTag string, buildPath string) error {
|
||||
log.Printf("building image: %s", imageTag)
|
||||
|
||||
client := builder.Dagger
|
||||
@ -31,18 +31,10 @@ func Build(builder *internal.Builder, imageTag string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("listing files in /src/")
|
||||
dir, err := os.ReadDir("/src/")
|
||||
if err == nil {
|
||||
for _, d := range dir {
|
||||
log.Printf("content: %s\n", d.Name())
|
||||
}
|
||||
}
|
||||
|
||||
golang := client.Container().From("golang:latest")
|
||||
golang = golang.WithMountedDirectory("/src", src).WithWorkdir("/src")
|
||||
_, err = golang.Exec(dagger.ContainerExecOpts{
|
||||
Args: []string{"go", "build", "-o", "build/"},
|
||||
Args: []string{"go", "build", "-o", "build/", buildPath},
|
||||
}).ExitCode(ctx)
|
||||
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user