Compare commits

..

48 Commits

Author SHA1 Message Date
8cf6173a69
chore: remove root
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-15 22:18:07 +02:00
986ab429b7
chore: update to always include root
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-15 22:16:24 +02:00
6fe0d0677c
feat: change to harbor.front.kjuulh.io
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-15 21:57:27 +02:00
5aed38a484
add readme
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-29 02:50:33 +01:00
58f331b9ec
with proper location
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 16:23:04 +01:00
3de2001d7e
update template
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 01:13:14 +01:00
0dfa3b350b
trying agian
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 01:12:49 +01:00
9c8a3719ce
Updated to image thwich can handle musl
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 01:11:45 +01:00
4e10b5c543
with musl-tools
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 00:59:01 +01:00
b2e9b54245
update rustbin
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 00:42:44 +01:00
6c885ec33c
with rust template
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-06 00:39:03 +01:00
c6c42c4d08
with default
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-31 22:35:42 +01:00
aa7036f10f Merge pull request 'Configure Renovate' (#1) from renovate/configure into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #1
2022-10-31 21:18:58 +00:00
a663931ce4 Add renovate.json
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-10-31 21:16:07 +00:00
aef05e5fee
remove redundant
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2022-10-31 22:04:59 +01:00
f62519e9cd
with ls
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-31 22:03:50 +01:00
c990e50622
with docker template
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-31 22:00:45 +01:00
f44ef84c89
with docker
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-31 21:57:16 +01:00
03fb65a9b4
add template option
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-31 21:08:44 +01:00
b9d4260597
update go.mod
All checks were successful
continuous-integration/drone Build is passing
2022-10-31 20:28:01 +01:00
d50776d172
update template 2022-10-31 20:23:47 +01:00
59249886ad
rename 2022-10-31 20:16:26 +01:00
e67569e776
with cgo_disabled 2022-10-31 02:04:16 +01:00
c4663856c4
with cgo disabled 2022-10-31 02:02:00 +01:00
217e9c5a4d
set another base image 2022-10-31 01:54:39 +01:00
4c1eff5988
with base golang 2022-10-31 01:52:32 +01:00
478e3662bc
removed tests 2022-10-31 01:49:21 +01:00
4ceceae6a7
removed typo 2022-10-31 01:48:32 +01:00
9583c9fa5e
with updated template 2022-10-31 01:47:02 +01:00
b1f64fdd74
remove execute on entrypoint 2022-10-31 01:43:19 +01:00
49dab03d9e
bumped version 2022-10-31 01:29:52 +01:00
50204fd54f
fix ci 2022-10-31 01:16:36 +01:00
cc2aea8c43
move to internal server instead 2022-10-31 01:03:48 +01:00
e9e5d1e958
with err exit 2022-10-31 00:35:40 +01:00
cb789bfa2e
with updated template 2022-10-31 00:29:02 +01:00
d5b0d6b25d
update version 2022-10-31 00:28:27 +01:00
45d63c2f90
disable with entrypoint 2022-10-31 00:26:44 +01:00
d90cbb8ff4
with actual name 2022-10-31 00:21:58 +01:00
b06ed52413
with mkdir 2022-10-31 00:13:07 +01:00
3bf5168347
with actual revision 2022-10-30 22:37:30 +01:00
050c50f6c7
dagger go instead 2022-10-30 22:29:22 +01:00
0376578c61
trying to just mount instead 2022-10-30 22:27:04 +01:00
98a08fc3ef
just cp 2022-10-30 22:12:09 +01:00
a83a28f40d
just ls 2022-10-30 22:08:30 +01:00
20298898fb
just ls 2022-10-30 22:06:14 +01:00
064cec5742
without comma 2022-10-30 22:03:56 +01:00
33b60cea3b
more debugging 2022-10-30 22:01:48 +01:00
9ffb6b71bd
remove file 2022-10-30 21:55:09 +01:00
46 changed files with 772 additions and 131 deletions

42
'
View File

@ -1,42 +0,0 @@
package main
import (
"context"
"log"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
)
func main() {
log.Printf("building dagger-go")
err := cli.NewCustomGoBuild("golangbin", func(ctx context.Context) error {
builder, err := builder.New(ctx)
if err != nil {
return err
}
err = pipelines.
New(builder).
WithGolangBin(&pipelines.GolangBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: "dagger-go",
},
BuildPath: "main.go",
BinName: "main",
BaseImage: "harbor.front.kjuulh.io/docker-proxy/library/docker:dind",
}).
Execute(ctx)
if err != nil {
return err
}
return nil
})
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,4 +1,4 @@
kind: template
load: dagger_go_template.yaml
name: dagger-go
load: bust_gobin_template.yaml
name: bust
data: {}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
main
ci/ci

View File

@ -4,10 +4,10 @@ WORKDIR /src/builder
COPY ci/. .
RUN go build -o dist/dagger-go main.go
RUN go build -o dist/bust main.go
FROM harbor.front.kjuulh.io/docker-proxy/library/docker:dind
WORKDIR /src
COPY --from=builder /src/builder/dist/dagger-go /usr/bin/
COPY --from=builder /src/builder/dist/bust /usr/bin/

14
README.md Normal file
View File

@ -0,0 +1,14 @@
# Bust
Bust is a platform agnostic pipeline. It is built on top of `dagger` and
`kjuulh/byg`. The goal of this project is to produce a way to easily extend and
interact with a golang pipeline for CI
## Examples
see `examples` for example pipelines, thought do note that the project usually
needs to be self-contained like the `ci` folder. `Bust` is built with `Bust`
after all.
To run simply `go run example/golang-bin/main.go`, this may require certain
setup for docker-hub, or alternate registries.

View File

@ -2,7 +2,7 @@ module ci
go 1.19
require git.front.kjuulh.io/kjuulh/dagger-go v0.0.12
require git.front.kjuulh.io/kjuulh/bust v0.0.32
require (
dagger.io/dagger v0.3.1 // indirect

View File

@ -35,18 +35,10 @@ 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/bust v0.0.32 h1:L05xJw7rR/wymSTU0cRzyM6L5JvDMUjv2Wzn6cXk00Q=
git.front.kjuulh.io/kjuulh/bust v0.0.32/go.mod h1:qp+96w2UHIk24jKGv6JxV0yx8YMm88lj6K/NJDDzEDk=
git.front.kjuulh.io/kjuulh/byg v0.0.7 h1:0ZDkRj1R2lvbWUQO5GjWJum9zpVMej6l8ZXn5YNmBNE=
git.front.kjuulh.io/kjuulh/byg v0.0.7/go.mod h1:8Vg5Mgqzva5fzHGeMlxjp/DMLbUy9uaKFxMNB34yYuA=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.8 h1:hbXEOYw3Q3sdwMjaEMz+v/TOnyUWSDAYFR8aQwQZF/o=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.8/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.9 h1:XxKhvUM8q7QcRSTeE7hF56zoXKGOncdHBdccKBKnS6M=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.9/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.10 h1:d9VNhI6OsiR/W4/1iJvchuHwTq2C3AHw3yetncKWfUM=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.10/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.11 h1:j3ylHiGmhcFomggJcrNJghbYBK/nuuvw0naFBIWqEqo=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.11/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.12 h1:c75Ac8joaOMfaOSPf+ZcvNdBcytx0hzIJMYXexKGXJ0=
git.front.kjuulh.io/kjuulh/dagger-go v0.0.12/go.mod h1:N/EXT0aOJzph/9AXuFlaA2ZuKU0P8WzaDZQXLlAL0D8=
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=

View File

@ -4,13 +4,13 @@ import (
"context"
"log"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
)
func main() {
log.Printf("building dagger-go")
log.Printf("building bust")
err := cli.NewCustomGoBuild("golangbin", func(ctx context.Context) error {
builder, err := builder.New(ctx)
@ -22,11 +22,12 @@ func main() {
New(builder).
WithGolangBin(&pipelines.GolangBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: "dagger-go",
ImageName: "bust",
},
BuildPath: "main.go",
BinName: "main",
BinName: "bust",
BaseImage: "harbor.front.kjuulh.io/docker-proxy/library/docker:dind",
CGOEnabled: true,
}).
Execute(ctx)

View File

@ -1,13 +0,0 @@
FROM harbor.front.kjuulh.io/docker-proxy/library/golang:alpine as builder
WORKDIR /src/builder
COPY tmp/dagger-go .
RUN go build -o dist/dagger-go main.go
FROM harbor.front.kjuulh.io/docker-proxy/library/docker:dind
WORKDIR /src
COPY --from=builder /src/builder/dist/dagger-go /usr/bin/

View File

@ -3,7 +3,7 @@ package main
import (
"log"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
)
func main() {

View File

@ -4,8 +4,8 @@ import (
"context"
"log"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
)
func main() {

View File

@ -0,0 +1 @@
target/

1
example/rust-bin/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

7
example/rust-bin/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust-bin"
version = "0.1.0"

View File

@ -0,0 +1,8 @@
[package]
name = "rust-bin"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

34
example/rust-bin/main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"context"
"log"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
)
func main() {
ctx := context.Background()
if err := run(ctx); err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context) error {
builder, err := builder.New(ctx)
if err != nil {
return err
}
defer builder.CleanUp()
return pipelines.
New(builder).
WithRustBin(&pipelines.RustBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: "rust-bin",
},
BinName: "rust-bin",
}).
Execute(ctx)
}

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

6
go.mod
View File

@ -1,14 +1,15 @@
module git.front.kjuulh.io/kjuulh/dagger-go
module git.front.kjuulh.io/kjuulh/bust
go 1.19
require (
dagger.io/dagger v0.3.1
git.front.kjuulh.io/kjuulh/byg v0.0.7
github.com/spf13/cobra v1.6.1
golang.org/x/sync v0.1.0
)
require (
git.front.kjuulh.io/kjuulh/byg v0.0.7 // 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
@ -69,7 +70,6 @@ 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.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
View File

@ -35,8 +35,6 @@ 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=
git.front.kjuulh.io/kjuulh/byg v0.0.7 h1:0ZDkRj1R2lvbWUQO5GjWJum9zpVMej6l8ZXn5YNmBNE=
git.front.kjuulh.io/kjuulh/byg v0.0.7/go.mod h1:8Vg5Mgqzva5fzHGeMlxjp/DMLbUy9uaKFxMNB34yYuA=
github.com/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
@ -508,8 +506,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
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=

View File

@ -3,7 +3,7 @@ package main
import (
"log"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
)
func main() {

View File

@ -9,7 +9,11 @@ func Build() *cobra.Command {
Use: "build",
}
cmd.AddCommand(BuildGolangBin())
cmd.AddCommand(
BuildRustBin(),
BuildGolangBin(),
BuildDocker(),
)
return cmd
}

40
pkg/cli/build_docker.go Normal file
View File

@ -0,0 +1,40 @@
package cli
import (
"errors"
"os"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
"github.com/spf13/cobra"
)
func BuildDocker() *cobra.Command {
cmd := &cobra.Command{
Use: "docker",
RunE: func(cmd *cobra.Command, args []string) error {
repoName := os.Getenv("DRONE_REPO_NAME")
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
ctx := cmd.Context()
builder, err := builder.New(ctx)
if err != nil {
return err
}
defer builder.CleanUp()
return pipelines.
New(builder).
WithDocker(&pipelines.DockerOpt{
DockerImageOpt: &pipelines.DockerImageOpt{ImageName: repoName},
Path: "Dockerfile",
}).
Execute(ctx)
},
}
return cmd
}

View File

@ -2,11 +2,10 @@ package cli
import (
"errors"
"fmt"
"os"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
"github.com/spf13/cobra"
)
@ -18,7 +17,6 @@ func BuildGolangBin() *cobra.Command {
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
imageTag := fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
ctx := cmd.Context()
@ -32,10 +30,12 @@ func BuildGolangBin() *cobra.Command {
New(builder).
WithGolangBin(&pipelines.GolangBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: imageTag,
ImageName: repoName,
},
BuildPath: "main.go",
BinName: "main",
CGOEnabled: false,
ExecuteOnEntrypoint: false,
}).
Execute(ctx)
},

52
pkg/cli/build_rust_bin.go Normal file
View File

@ -0,0 +1,52 @@
package cli
import (
"errors"
"os"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
"github.com/spf13/cobra"
)
func BuildRustBin() *cobra.Command {
var (
binName string
)
cmd := &cobra.Command{
Use: "rustbin",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
repoName := os.Getenv("DRONE_REPO_NAME")
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
ctx := cmd.Context()
builder, err := builder.New(ctx)
if err != nil {
return err
}
defer builder.CleanUp()
return pipelines.
New(builder).
WithRustBin(&pipelines.RustBinOpts{
DockerImageOpt: &pipelines.DockerImageOpt{
ImageName: repoName,
},
BinName: binName,
}).
Execute(ctx)
},
}
cmd.PersistentFlags().StringVar(&binName, "bin-name", "", "bin-name is the binary to build, and what will be present in the output folder")
return cmd
}

View File

@ -9,7 +9,7 @@ import (
func NewCustomGoBuild(command string, runf func(ctx context.Context) error) error {
cmd := &cobra.Command{
Use: fmt.Sprintf("dagger-go build %s", command),
Use: fmt.Sprintf("bust build %s", command),
RunE: func(cmd *cobra.Command, args []string) error {
return runf(cmd.Context())
},

View File

@ -1,13 +1,17 @@
package cli
import "github.com/spf13/cobra"
import (
"git.front.kjuulh.io/kjuulh/bust/pkg/cli/templatecmd"
"github.com/spf13/cobra"
)
func NewCli() *cobra.Command {
cmd := &cobra.Command{
Use: "dagger",
Use: "bust",
}
cmd.AddCommand(Build())
cmd.AddCommand(templatecmd.NewTemplateCmd())
return cmd
}

View File

@ -0,0 +1,99 @@
package templatecmd
import (
"embed"
"errors"
"fmt"
"os"
"text/template"
"github.com/spf13/cobra"
)
//go:embed templates/gobin_default/*
var gobinDefault embed.FS
//go:embed templates/docker/*
var docker embed.FS
//go:embed templates/default/*
var defaultFs embed.FS
//go:embed templates/rustbin_default/*
var rustbinDefault embed.FS
func NewInitCmd() *cobra.Command {
var (
template string
name string
)
cmd := &cobra.Command{
Use: "init",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
switch template {
case "gobin_default":
if err := initializeTemplate(&gobinDefault, "gobin_default", name); err != nil {
return err
}
break
case "docker":
if err := initializeTemplate(&docker, "docker", name); err != nil {
return err
}
break
case "default":
if err := initializeTemplate(&defaultFs, "default", name); err != nil {
return err
}
break
case "rustbin_default":
if err := initializeTemplate(&rustbinDefault, "rustbin_default", name); err != nil {
return err
}
break
default:
return errors.New("could not find matching templates, please run [bust template ls] instead")
}
return nil
},
}
cmd.PersistentFlags().StringVarP(&template, "template", "p", "", "The template to initialize")
cmd.MarkPersistentFlagRequired("template")
cmd.PersistentFlags().StringVarP(&name, "name", "n", "", "The name into the template")
cmd.MarkPersistentFlagRequired("name")
return cmd
}
func initializeTemplate(t *embed.FS, path string, name string) error {
tinit := template.
Must(
template.
New("").
Delims("[[", "]]").
ParseFS(
t,
fmt.Sprintf("templates/%s/*", path),
),
)
type data struct {
Name string
}
droneWriter, err := os.Create(".drone.yml")
if err != nil {
return err
}
return tinit.ExecuteTemplate(droneWriter, ".drone.yml", data{
Name: name,
})
}

23
pkg/cli/templatecmd/ls.go Normal file
View File

@ -0,0 +1,23 @@
package templatecmd
import (
"fmt"
"github.com/spf13/cobra"
)
var templates = []string{"docker", "gobin_default", "default", "rustbin_default"}
func NewLsCmd() *cobra.Command {
return &cobra.Command{
Use: "ls",
RunE: func(cmd *cobra.Command, args []string) error {
for _, t := range templates {
fmt.Printf("%s\n", t)
}
return nil
},
}
}

View File

@ -0,0 +1,16 @@
package templatecmd
import "github.com/spf13/cobra"
func NewTemplateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "template",
}
cmd.AddCommand(
NewInitCmd(),
NewLsCmd(),
)
return cmd
}

View File

@ -0,0 +1,4 @@
kind: template
load: bust_default_template.yaml
name: [[.Name]]
data: {}

View File

@ -0,0 +1,4 @@
kind: template
load: bust_docker_template.yaml
name: [[.Name]]
data: {}

View File

@ -0,0 +1,4 @@
kind: template
load: bust_gobin_default_template.yaml
name: [[.Name]]
data: {}

View File

@ -0,0 +1,5 @@
kind: template
load: bust_rustbin_default_template.yaml
name: [[.Name]]
data:
binName: default

70
pkg/pipelines/docker.go Normal file
View File

@ -0,0 +1,70 @@
package pipelines
import (
"context"
"fmt"
"log"
"strconv"
"time"
"dagger.io/dagger"
"git.front.kjuulh.io/kjuulh/byg"
)
type DockerOpt struct {
*DockerImageOpt
Path string
}
func (p *Pipeline) WithDocker(opts *DockerOpt) *Pipeline {
log.Printf("building image: %s", opts.ImageName)
client := p.builder.Dagger
ctx := context.Background()
var (
finalImage *dagger.Container
)
pipeline := byg.
New().
Step(
"build image",
byg.Step{
Execute: func(_ byg.Context) error {
var err error
dir, err := client.Host().Workdir().Read().ID(ctx)
if err != nil {
return err
}
finalImage = client.Container().Build(dir, dagger.ContainerBuildOpts{Dockerfile: opts.Path})
if _, err = finalImage.ExitCode(ctx); err != nil {
return err
}
return nil
},
},
).
Step(
"upload-image",
byg.Step{
Execute: func(_ byg.Context) error {
if opts.ImageTag == "" {
opts.ImageTag = strconv.FormatInt(time.Now().UTC().UnixMilli(), 10)
}
tag := fmt.Sprintf("harbor.front.kjuulh.io/kjuulh/%s:%s", opts.ImageName, opts.ImageTag)
_, err := finalImage.Publish(ctx, tag)
return err
},
},
)
p.add(pipeline)
return p
}

View File

@ -4,14 +4,15 @@ import (
"context"
"fmt"
"log"
"path"
"strconv"
"time"
"dagger.io/dagger"
"git.front.kjuulh.io/kjuulh/bust/pkg/tasks/container"
"git.front.kjuulh.io/kjuulh/bust/pkg/tasks/golang"
golangbin "git.front.kjuulh.io/kjuulh/bust/pkg/tasks/golang-bin"
"git.front.kjuulh.io/kjuulh/byg"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks/container"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks/golang"
golangbin "git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks/golang-bin"
)
type DockerImageOpt struct {
@ -24,6 +25,8 @@ type GolangBinOpts struct {
BuildPath string
BinName string
BaseImage string
ExecuteOnEntrypoint bool
CGOEnabled bool
}
func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
@ -52,6 +55,12 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
}
c = container.Workdir(c, "/src")
if opts.CGOEnabled {
c = c.WithEnvVariable("CGO_ENABLED", "1")
} else {
c = c.WithEnvVariable("CGO_ENABLED", "0")
}
build, err = golang.Cache(ctx, client, c)
if err != nil {
return err
@ -69,21 +78,31 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
Step(
"create-production-image",
byg.Step{
Execute: func(ctx byg.Context) error {
Execute: func(_ byg.Context) error {
if opts.BaseImage == "" {
opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/busybox"
opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/alpine"
}
binpath := "/usr/bin"
usrbin := path.Join(binpath, opts.BinName)
c := container.LoadImage(client, opts.BaseImage)
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{"mkdir", "-p", "/tmp/bin/", "/usr/bin/"},
})
tempmount := fmt.Sprintf("/tmp/bin/%s", opts.BinName)
usrbin := fmt.Sprintf("/usr/bin/%s", opts.BinName)
c = container.MountFileFromLoaded(c, bin, tempmount)
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{"cp", tempmount, usrbin},
Args: []string{"mkdir", "-p", binpath},
})
_, err := c.ExitCode(ctx)
if err != nil {
return err
}
c, err = container.MountFileFromLoaded(ctx, c, bin, usrbin)
if err != nil {
return err
}
if opts.ExecuteOnEntrypoint {
finalImage = c.WithEntrypoint([]string{usrbin})
} else {
finalImage = c
}
return nil
},

View File

@ -3,8 +3,8 @@ package pipelines
import (
"context"
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
"git.front.kjuulh.io/kjuulh/byg"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
"golang.org/x/sync/errgroup"
)

134
pkg/pipelines/rust-bin.go Normal file
View File

@ -0,0 +1,134 @@
package pipelines
import (
"context"
"fmt"
"log"
"path"
"strconv"
"time"
"dagger.io/dagger"
"git.front.kjuulh.io/kjuulh/bust/pkg/tasks/container"
rustbin "git.front.kjuulh.io/kjuulh/bust/pkg/tasks/rust-bin"
"git.front.kjuulh.io/kjuulh/byg"
)
type RustBinOpts struct {
*DockerImageOpt
BinName string
BaseImage string
}
func (p *Pipeline) WithRustBin(opts *RustBinOpts) *Pipeline {
log.Printf("building image: %s", opts.ImageName)
client := p.builder.Dagger
ctx := context.Background()
var (
bin dagger.FileID
finalImage *dagger.Container
)
pipeline := byg.
New().
Step(
"build rust",
byg.Step{
Execute: func(_ byg.Context) error {
var err error
c := container.LoadImage(client, "harbor.front.kjuulh.io/docker-proxy/library/rust:buster")
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{
"apt", "update", "-y",
},
})
if _, err := c.ExitCode(ctx); err != nil {
return err
}
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{
"apt", "install", "musl-tools", "-y",
},
})
if _, err := c.ExitCode(ctx); err != nil {
return err
}
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{
"rustup",
"target",
"add",
"x86_64-unknown-linux-musl",
},
})
if _, err := c.ExitCode(ctx); err != nil {
return err
}
c, err = container.MountCurrent(ctx, client, c, "/src")
if err != nil {
return err
}
c = container.Workdir(c, "/src")
if bin, err = rustbin.Build(ctx, c, opts.BinName); err != nil {
return err
}
return err
},
},
).
Step(
"create-production-image",
byg.Step{
Execute: func(_ byg.Context) error {
if opts.BaseImage == "" {
opts.BaseImage = "harbor.front.kjuulh.io/docker-proxy/library/alpine"
}
binpath := "/usr/bin"
usrbin := path.Join(binpath, opts.BinName)
c := container.LoadImage(client, opts.BaseImage)
c = c.Exec(dagger.ContainerExecOpts{
Args: []string{"mkdir", "-p", binpath},
})
_, err := c.ExitCode(ctx)
if err != nil {
return err
}
c, err = container.MountFileFromLoaded(ctx, c, bin, usrbin)
if err != nil {
return err
}
finalImage = c
return nil
},
},
).
Step(
"upload-image",
byg.Step{
Execute: func(_ byg.Context) error {
if opts.ImageTag == "" {
opts.ImageTag = strconv.FormatInt(time.Now().UTC().UnixMilli(), 10)
}
tag := fmt.Sprintf("harbor.front.kjuulh.io/kjuulh/%s:%s", opts.ImageName, opts.ImageTag)
_, err := finalImage.Publish(ctx, tag)
return err
},
},
)
p.add(pipeline)
return p
}

View File

@ -21,7 +21,12 @@ func MountCurrent(ctx context.Context, client *dagger.Client, container *dagger.
return container.WithMountedDirectory(into, src), nil
}
func MountFileFromLoaded(container *dagger.Container, bin dagger.FileID, path string) *dagger.Container {
func MountFileFromLoaded(ctx context.Context, container *dagger.Container, bin dagger.FileID, path string) (*dagger.Container, error) {
log.Printf("mounting binary into container: into (path=%s)", path)
return container.WithMountedFile(path, bin)
newFs, err := container.FS().WithCopiedFile(path, bin).ID(ctx)
if err != nil {
return nil, err
}
return container.WithFS(newFs), nil
}

View File

@ -0,0 +1,31 @@
package rustbin
import (
"context"
"fmt"
"log"
"dagger.io/dagger"
)
func Build(ctx context.Context, container *dagger.Container, binName string) (dagger.FileID, error) {
log.Printf("building binary: (binName=%s)", binName)
c := container.Exec(dagger.ContainerExecOpts{
Args: []string{
"cargo",
"build",
"--release",
"--target=x86_64-unknown-linux-musl",
},
})
if _, err := c.ExitCode(ctx); err != nil {
return "", err
}
bin, err := c.File(fmt.Sprintf("target/x86_64-unknown-linux-musl/release/%s", binName)).ID(ctx)
if err != nil {
return "", err
}
return bin, nil
}

3
renovate.json Normal file
View File

@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View File

@ -0,0 +1,40 @@
type: docker
kind: pipeline
name: "drone-dagger-test"
steps:
- name: "build"
image: harbor.front.kjuulh.io/kjuulh/bust:1667250488156
volumes:
- name: dockersock
path: /var/run
environment:
DOCKER_BUILDKIT: 1
HARBOR_DOCKER_HOST: "harbor.front.kjuulh.io"
HARBOR_DOCKER_USERNAME:
from_secret: "harbor_docker_username"
HARBOR_DOCKER_PASSWORD:
from_secret: "harbor_docker_password"
commands:
- sleep 5
- >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
--password-stdin
--username="$${HARBOR_DOCKER_USERNAME}"
"$${HARBOR_DOCKER_HOST}"
- bust build default
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
image_pull_secrets:
- dockerconfig

View File

@ -4,7 +4,7 @@ name: "drone-dagger-test"
steps:
- name: "build"
image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667159344332
image: harbor.front.kjuulh.io/kjuulh/bust:1667250488156
volumes:
- name: dockersock
path: /var/run
@ -17,7 +17,12 @@ steps:
from_secret: "harbor_docker_password"
commands:
- sleep 5
- sh -c "/dagger-go build golangbin"
- >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
--password-stdin
--username="$${HARBOR_DOCKER_USERNAME}"
"$${HARBOR_DOCKER_HOST}"
- bust build docker
services:
- name: docker

View File

@ -0,0 +1,40 @@
type: docker
kind: pipeline
name: "drone-dagger-test"
steps:
- name: "build"
image: harbor.front.kjuulh.io/kjuulh/bust:1667244085545
volumes:
- name: dockersock
path: /var/run
environment:
DOCKER_BUILDKIT: 1
HARBOR_DOCKER_HOST: "harbor.front.kjuulh.io"
HARBOR_DOCKER_USERNAME:
from_secret: "harbor_docker_username"
HARBOR_DOCKER_PASSWORD:
from_secret: "harbor_docker_password"
commands:
- sleep 5
- >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
--password-stdin
--username="$${HARBOR_DOCKER_USERNAME}"
"$${HARBOR_DOCKER_HOST}"
- bust build golangbin
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
image_pull_secrets:
- dockerconfig

View File

@ -18,16 +18,16 @@ steps:
commands:
- sleep 5
- apk add git
- mkdir -p tmp/dagger-go
- git clone "https://git.front.kjuulh.io/kjuulh/dagger-go.git" tmp/dagger-go
- mkdir -p tmp/bust
- git clone "https://git.front.kjuulh.io/kjuulh/bust.git" tmp/bust
- >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
--password-stdin
--username="$${HARBOR_DOCKER_USERNAME}"
"$${HARBOR_DOCKER_HOST}"
- >
docker pull harbor.front.kjuulh.io/kjuulh/dagger-go-builder:${DRONE_COMMIT} ||
(docker build -t harbor.front.kjuulh.io/kjuulh/dagger-go-builder:${DRONE_COMMIT} -f tmp/dagger-go/Dockerfile . && docker push harbor.front.kjuulh.io/kjuulh/dagger-go-builder:${DRONE_COMMIT})
docker pull harbor.front.kjuulh.io/kjuulh/bust-builder:${DRONE_COMMIT} ||
(docker build -t harbor.front.kjuulh.io/kjuulh/bust-builder:${DRONE_COMMIT} -f tmp/bust/Dockerfile . && docker push harbor.front.kjuulh.io/kjuulh/bust-builder:${DRONE_COMMIT})
- >
docker run
-e DRONE_REPO_NAME="${DRONE_REPO_NAME}"
@ -36,12 +36,12 @@ steps:
-e HARBOR_DOCKER_PASSWORD=$${HARBOR_DOCKER_PASSWORD}
-v "$PWD/:/src/"
-v /var/run/docker.sock:/var/run/docker.sock
harbor.front.kjuulh.io/kjuulh/dagger-go-builder:${DRONE_COMMIT}
harbor.front.kjuulh.io/kjuulh/bust-builder:${DRONE_COMMIT}
sh -c 'echo "$$HARBOR_DOCKER_PASSWORD" | docker login
--password-stdin
--username="$$HARBOR_DOCKER_USERNAME"
"$${HARBOR_DOCKER_HOST}"
&& dagger-go build golangbin'
&& bust build golangbin'
services:
- name: docker

View File

@ -0,0 +1,34 @@
type: docker
kind: pipeline
name: "drone-dagger-test"
steps:
- name: "build"
image: harbor.front.kjuulh.io/kjuulh/bust:1667748107856
volumes:
- name: dockersock
path: /var/run
environment:
DOCKER_BUILDKIT: 1
HARBOR_DOCKER_HOST: "harbor.front.kjuulh.io"
HARBOR_DOCKER_USERNAME:
from_secret: "harbor_docker_username"
HARBOR_DOCKER_PASSWORD:
from_secret: "harbor_docker_password"
commands:
- sleep 5
- >
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login --password-stdin --username="$${HARBOR_DOCKER_USERNAME}" "$${HARBOR_DOCKER_HOST}"
- bust build rustbin --bin-name {{ .input.binName }}
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
image_pull_secrets:
- dockerconfig

View File

@ -7,7 +7,8 @@ function add_template() {
drone template update --namespace "${namespace}" --name "${name}" --data "@${name}"
}
add_template kjuulh dagger_go_template.yaml
add_template kjuulh gobin_default_template.yaml
add_template kjuulh bust_default_template.yaml
add_template kjuulh bust_docker_template.yaml
add_template kjuulh bust_gobin_template.yaml
add_template kjuulh bust_gobin_default_template.yaml
add_template kjuulh bust_rustbin_default_template.yaml