Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
8cf6173a69 | |||
986ab429b7 | |||
6fe0d0677c | |||
5aed38a484 | |||
58f331b9ec | |||
3de2001d7e | |||
0dfa3b350b | |||
9c8a3719ce | |||
4e10b5c543 | |||
b2e9b54245 | |||
6c885ec33c | |||
c6c42c4d08 | |||
aa7036f10f | |||
a663931ce4 | |||
aef05e5fee | |||
f62519e9cd | |||
c990e50622 | |||
f44ef84c89 | |||
03fb65a9b4 | |||
b9d4260597 | |||
d50776d172 | |||
59249886ad | |||
e67569e776 | |||
c4663856c4 | |||
217e9c5a4d | |||
4c1eff5988 | |||
478e3662bc | |||
4ceceae6a7 | |||
9583c9fa5e | |||
b1f64fdd74 | |||
49dab03d9e | |||
50204fd54f | |||
cc2aea8c43 | |||
e9e5d1e958 | |||
cb789bfa2e | |||
d5b0d6b25d | |||
45d63c2f90 | |||
d90cbb8ff4 | |||
b06ed52413 | |||
3bf5168347 | |||
050c50f6c7 | |||
0376578c61 | |||
98a08fc3ef | |||
a83a28f40d | |||
20298898fb | |||
064cec5742 | |||
33b60cea3b | |||
9ffb6b71bd |
42
'
42
'
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
kind: template
|
kind: template
|
||||||
load: dagger_go_template.yaml
|
load: bust_gobin_template.yaml
|
||||||
name: dagger-go
|
name: bust
|
||||||
data: {}
|
data: {}
|
||||||
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
main
|
||||||
|
ci/ci
|
@ -4,10 +4,10 @@ WORKDIR /src/builder
|
|||||||
|
|
||||||
COPY ci/. .
|
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
|
FROM harbor.front.kjuulh.io/docker-proxy/library/docker:dind
|
||||||
|
|
||||||
WORKDIR /src
|
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
14
README.md
Normal 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.
|
@ -2,7 +2,7 @@ module ci
|
|||||||
|
|
||||||
go 1.19
|
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 (
|
require (
|
||||||
dagger.io/dagger v0.3.1 // indirect
|
dagger.io/dagger v0.3.1 // indirect
|
||||||
|
12
ci/go.sum
12
ci/go.sum
@ -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 h1:JjUTPyDSrs+pDPmopVfhYAldHS4Rxn3XechACUlmTHQ=
|
||||||
dagger.io/dagger v0.3.1/go.mod h1:+p5s9Itrr/KT4UttGNpeUTNtVQUI2z9LDIOH9wBzu8g=
|
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=
|
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 h1:0ZDkRj1R2lvbWUQO5GjWJum9zpVMej6l8ZXn5YNmBNE=
|
||||||
git.front.kjuulh.io/kjuulh/byg v0.0.7/go.mod h1:8Vg5Mgqzva5fzHGeMlxjp/DMLbUy9uaKFxMNB34yYuA=
|
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/99designs/gqlgen v0.17.2/go.mod h1:K5fzLKwtph+FFgh9j7nFbRUdBKvTcGnsta51fsMTn3o=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
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=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
|
13
ci/main.go
13
ci/main.go
@ -4,13 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Printf("building dagger-go")
|
log.Printf("building bust")
|
||||||
|
|
||||||
err := cli.NewCustomGoBuild("golangbin", func(ctx context.Context) error {
|
err := cli.NewCustomGoBuild("golangbin", func(ctx context.Context) error {
|
||||||
builder, err := builder.New(ctx)
|
builder, err := builder.New(ctx)
|
||||||
@ -22,11 +22,12 @@ func main() {
|
|||||||
New(builder).
|
New(builder).
|
||||||
WithGolangBin(&pipelines.GolangBinOpts{
|
WithGolangBin(&pipelines.GolangBinOpts{
|
||||||
DockerImageOpt: &pipelines.DockerImageOpt{
|
DockerImageOpt: &pipelines.DockerImageOpt{
|
||||||
ImageName: "dagger-go",
|
ImageName: "bust",
|
||||||
},
|
},
|
||||||
BuildPath: "main.go",
|
BuildPath: "main.go",
|
||||||
BinName: "main",
|
BinName: "bust",
|
||||||
BaseImage: "harbor.front.kjuulh.io/docker-proxy/library/docker:dind",
|
BaseImage: "harbor.front.kjuulh.io/docker-proxy/library/docker:dind",
|
||||||
|
CGOEnabled: true,
|
||||||
}).
|
}).
|
||||||
Execute(ctx)
|
Execute(ctx)
|
||||||
|
|
||||||
|
@ -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/
|
|
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
1
example/rust-bin/.dockerignore
Normal file
1
example/rust-bin/.dockerignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
target/
|
1
example/rust-bin/.gitignore
vendored
Normal file
1
example/rust-bin/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target/
|
7
example/rust-bin/Cargo.lock
generated
Normal file
7
example/rust-bin/Cargo.lock
generated
Normal 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"
|
8
example/rust-bin/Cargo.toml
Normal file
8
example/rust-bin/Cargo.toml
Normal 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
34
example/rust-bin/main.go
Normal 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)
|
||||||
|
}
|
3
example/rust-bin/src/main.rs
Normal file
3
example/rust-bin/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
6
go.mod
6
go.mod
@ -1,14 +1,15 @@
|
|||||||
module git.front.kjuulh.io/kjuulh/dagger-go
|
module git.front.kjuulh.io/kjuulh/bust
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
dagger.io/dagger v0.3.1
|
dagger.io/dagger v0.3.1
|
||||||
|
git.front.kjuulh.io/kjuulh/byg v0.0.7
|
||||||
github.com/spf13/cobra v1.6.1
|
github.com/spf13/cobra v1.6.1
|
||||||
|
golang.org/x/sync v0.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.front.kjuulh.io/kjuulh/byg v0.0.7 // indirect
|
|
||||||
github.com/Khan/genqlient v0.5.0 // indirect
|
github.com/Khan/genqlient v0.5.0 // indirect
|
||||||
github.com/Microsoft/go-winio v0.5.2 // indirect
|
github.com/Microsoft/go-winio v0.5.2 // indirect
|
||||||
github.com/agext/levenshtein v1.2.3 // indirect
|
github.com/agext/levenshtein v1.2.3 // indirect
|
||||||
@ -69,7 +70,6 @@ require (
|
|||||||
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
|
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
|
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
|
||||||
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 // 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/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
|
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -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 h1:JjUTPyDSrs+pDPmopVfhYAldHS4Rxn3XechACUlmTHQ=
|
||||||
dagger.io/dagger v0.3.1/go.mod h1:+p5s9Itrr/KT4UttGNpeUTNtVQUI2z9LDIOH9wBzu8g=
|
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=
|
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 h1:0ZDkRj1R2lvbWUQO5GjWJum9zpVMej6l8ZXn5YNmBNE=
|
||||||
git.front.kjuulh.io/kjuulh/byg v0.0.7/go.mod h1:8Vg5Mgqzva5fzHGeMlxjp/DMLbUy9uaKFxMNB34yYuA=
|
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=
|
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-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-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-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 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
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-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
2
main.go
2
main.go
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/cli"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,7 +9,11 @@ func Build() *cobra.Command {
|
|||||||
Use: "build",
|
Use: "build",
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(BuildGolangBin())
|
cmd.AddCommand(
|
||||||
|
BuildRustBin(),
|
||||||
|
BuildGolangBin(),
|
||||||
|
BuildDocker(),
|
||||||
|
)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
40
pkg/cli/build_docker.go
Normal file
40
pkg/cli/build_docker.go
Normal 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
|
||||||
|
}
|
@ -2,11 +2,10 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/pipelines"
|
"git.front.kjuulh.io/kjuulh/bust/pkg/pipelines"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +17,6 @@ func BuildGolangBin() *cobra.Command {
|
|||||||
if repoName == "" {
|
if repoName == "" {
|
||||||
return errors.New("could not find DRONE_REPO_NAME")
|
return errors.New("could not find DRONE_REPO_NAME")
|
||||||
}
|
}
|
||||||
imageTag := fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
|
|
||||||
|
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
@ -32,10 +30,12 @@ func BuildGolangBin() *cobra.Command {
|
|||||||
New(builder).
|
New(builder).
|
||||||
WithGolangBin(&pipelines.GolangBinOpts{
|
WithGolangBin(&pipelines.GolangBinOpts{
|
||||||
DockerImageOpt: &pipelines.DockerImageOpt{
|
DockerImageOpt: &pipelines.DockerImageOpt{
|
||||||
ImageName: imageTag,
|
ImageName: repoName,
|
||||||
},
|
},
|
||||||
BuildPath: "main.go",
|
BuildPath: "main.go",
|
||||||
BinName: "main",
|
BinName: "main",
|
||||||
|
CGOEnabled: false,
|
||||||
|
ExecuteOnEntrypoint: false,
|
||||||
}).
|
}).
|
||||||
Execute(ctx)
|
Execute(ctx)
|
||||||
},
|
},
|
||||||
|
52
pkg/cli/build_rust_bin.go
Normal file
52
pkg/cli/build_rust_bin.go
Normal 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
|
||||||
|
}
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func NewCustomGoBuild(command string, runf func(ctx context.Context) error) error {
|
func NewCustomGoBuild(command string, runf func(ctx context.Context) error) error {
|
||||||
cmd := &cobra.Command{
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runf(cmd.Context())
|
return runf(cmd.Context())
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package cli
|
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 {
|
func NewCli() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "dagger",
|
Use: "bust",
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(Build())
|
cmd.AddCommand(Build())
|
||||||
|
cmd.AddCommand(templatecmd.NewTemplateCmd())
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
99
pkg/cli/templatecmd/init.go
Normal file
99
pkg/cli/templatecmd/init.go
Normal 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
23
pkg/cli/templatecmd/ls.go
Normal 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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
16
pkg/cli/templatecmd/template.go
Normal file
16
pkg/cli/templatecmd/template.go
Normal 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
|
||||||
|
}
|
4
pkg/cli/templatecmd/templates/default/.drone.yml
Normal file
4
pkg/cli/templatecmd/templates/default/.drone.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
kind: template
|
||||||
|
load: bust_default_template.yaml
|
||||||
|
name: [[.Name]]
|
||||||
|
data: {}
|
4
pkg/cli/templatecmd/templates/docker/.drone.yml
Normal file
4
pkg/cli/templatecmd/templates/docker/.drone.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
kind: template
|
||||||
|
load: bust_docker_template.yaml
|
||||||
|
name: [[.Name]]
|
||||||
|
data: {}
|
4
pkg/cli/templatecmd/templates/gobin_default/.drone.yml
Normal file
4
pkg/cli/templatecmd/templates/gobin_default/.drone.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
kind: template
|
||||||
|
load: bust_gobin_default_template.yaml
|
||||||
|
name: [[.Name]]
|
||||||
|
data: {}
|
5
pkg/cli/templatecmd/templates/rustbin_default/.drone.yml
Normal file
5
pkg/cli/templatecmd/templates/rustbin_default/.drone.yml
Normal 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
70
pkg/pipelines/docker.go
Normal 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
|
||||||
|
}
|
@ -4,14 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"dagger.io/dagger"
|
"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/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 {
|
type DockerImageOpt struct {
|
||||||
@ -24,6 +25,8 @@ type GolangBinOpts struct {
|
|||||||
BuildPath string
|
BuildPath string
|
||||||
BinName string
|
BinName string
|
||||||
BaseImage string
|
BaseImage string
|
||||||
|
ExecuteOnEntrypoint bool
|
||||||
|
CGOEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
|
func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
|
||||||
@ -52,6 +55,12 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
|
|||||||
}
|
}
|
||||||
c = container.Workdir(c, "/src")
|
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)
|
build, err = golang.Cache(ctx, client, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -69,21 +78,31 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
|
|||||||
Step(
|
Step(
|
||||||
"create-production-image",
|
"create-production-image",
|
||||||
byg.Step{
|
byg.Step{
|
||||||
Execute: func(ctx byg.Context) error {
|
Execute: func(_ byg.Context) error {
|
||||||
if opts.BaseImage == "" {
|
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 := container.LoadImage(client, opts.BaseImage)
|
||||||
c = c.Exec(dagger.ContainerExecOpts{
|
c = c.Exec(dagger.ContainerExecOpts{
|
||||||
Args: []string{"mkdir", "-p", "/tmp/bin/", "/usr/bin/"},
|
Args: []string{"mkdir", "-p", binpath},
|
||||||
})
|
|
||||||
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},
|
|
||||||
})
|
})
|
||||||
|
_, 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})
|
finalImage = c.WithEntrypoint([]string{usrbin})
|
||||||
|
} else {
|
||||||
|
finalImage = c
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -3,8 +3,8 @@ package pipelines
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.front.kjuulh.io/kjuulh/bust/pkg/builder"
|
||||||
"git.front.kjuulh.io/kjuulh/byg"
|
"git.front.kjuulh.io/kjuulh/byg"
|
||||||
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/builder"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
134
pkg/pipelines/rust-bin.go
Normal file
134
pkg/pipelines/rust-bin.go
Normal 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
|
||||||
|
}
|
@ -21,7 +21,12 @@ func MountCurrent(ctx context.Context, client *dagger.Client, container *dagger.
|
|||||||
return container.WithMountedDirectory(into, src), nil
|
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)
|
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
|
||||||
}
|
}
|
||||||
|
31
pkg/tasks/rust-bin/build.go
Normal file
31
pkg/tasks/rust-bin/build.go
Normal 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
3
renovate.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
|
}
|
40
templates/bust_default_template.yaml
Normal file
40
templates/bust_default_template.yaml
Normal 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
|
@ -4,7 +4,7 @@ name: "drone-dagger-test"
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: "build"
|
- name: "build"
|
||||||
image: harbor.front.kjuulh.io/kjuulh/dagger-go:1667159344332
|
image: harbor.front.kjuulh.io/kjuulh/bust:1667250488156
|
||||||
volumes:
|
volumes:
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
path: /var/run
|
path: /var/run
|
||||||
@ -17,7 +17,12 @@ steps:
|
|||||||
from_secret: "harbor_docker_password"
|
from_secret: "harbor_docker_password"
|
||||||
commands:
|
commands:
|
||||||
- sleep 5
|
- 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:
|
services:
|
||||||
- name: docker
|
- name: docker
|
40
templates/bust_gobin_default_template.yaml
Normal file
40
templates/bust_gobin_default_template.yaml
Normal 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
|
@ -18,16 +18,16 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- sleep 5
|
- sleep 5
|
||||||
- apk add git
|
- apk add git
|
||||||
- mkdir -p tmp/dagger-go
|
- mkdir -p tmp/bust
|
||||||
- git clone "https://git.front.kjuulh.io/kjuulh/dagger-go.git" tmp/dagger-go
|
- git clone "https://git.front.kjuulh.io/kjuulh/bust.git" tmp/bust
|
||||||
- >
|
- >
|
||||||
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
|
echo "$${HARBOR_DOCKER_PASSWORD}" | docker login
|
||||||
--password-stdin
|
--password-stdin
|
||||||
--username="$${HARBOR_DOCKER_USERNAME}"
|
--username="$${HARBOR_DOCKER_USERNAME}"
|
||||||
"$${HARBOR_DOCKER_HOST}"
|
"$${HARBOR_DOCKER_HOST}"
|
||||||
- >
|
- >
|
||||||
docker pull 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/dagger-go-builder:${DRONE_COMMIT} -f tmp/dagger-go/Dockerfile . && docker push harbor.front.kjuulh.io/kjuulh/dagger-go-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
|
docker run
|
||||||
-e DRONE_REPO_NAME="${DRONE_REPO_NAME}"
|
-e DRONE_REPO_NAME="${DRONE_REPO_NAME}"
|
||||||
@ -36,12 +36,12 @@ steps:
|
|||||||
-e HARBOR_DOCKER_PASSWORD=$${HARBOR_DOCKER_PASSWORD}
|
-e HARBOR_DOCKER_PASSWORD=$${HARBOR_DOCKER_PASSWORD}
|
||||||
-v "$PWD/:/src/"
|
-v "$PWD/:/src/"
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock
|
-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
|
sh -c 'echo "$$HARBOR_DOCKER_PASSWORD" | docker login
|
||||||
--password-stdin
|
--password-stdin
|
||||||
--username="$$HARBOR_DOCKER_USERNAME"
|
--username="$$HARBOR_DOCKER_USERNAME"
|
||||||
"$${HARBOR_DOCKER_HOST}"
|
"$${HARBOR_DOCKER_HOST}"
|
||||||
&& dagger-go build golangbin'
|
&& bust build golangbin'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: docker
|
- name: docker
|
34
templates/bust_rustbin_default_template.yaml
Normal file
34
templates/bust_rustbin_default_template.yaml
Normal 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
|
@ -7,7 +7,8 @@ function add_template() {
|
|||||||
drone template update --namespace "${namespace}" --name "${name}" --data "@${name}"
|
drone template update --namespace "${namespace}" --name "${name}" --data "@${name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_template kjuulh dagger_go_template.yaml
|
add_template kjuulh bust_default_template.yaml
|
||||||
add_template kjuulh gobin_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
|
Loading…
x
Reference in New Issue
Block a user