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

Dagger trial #3

Merged
merged 3 commits into from
Nov 17, 2023
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
13 changes: 4 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: make build

- name: Test
run: make test
uses: kpenfound/dagger-action@main
with:
args: build
module: ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
.vscode
.env
kubeconfig.yaml
Expand Down
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
.PHONY: build
export PATH := $(abspath bin/):${PATH}

.PHONY: build
build:
go build -o build/capacitor github.com/gimlet-io/capacitor/cmd/capacitor

.PHONY: dagger-build
dagger-build:
dagger call build

.PHONY: test
test:
go test -timeout 60s $(shell go list ./...)

.PHONY: build-ui
build-ui:
(cd web; npm install; npm run build)
rm -rf cmd/capacitor/web/build
mkdir -p cmd/capacitor/web/build
@rm -rf cmd/capacitor/web/build
@mkdir -p cmd/capacitor/web/build
@cp -r web/build/* cmd/capacitor/web/build

.PHONY: dagger-build-ui
dagger-build-ui:
dagger call buildUi
@rm -rf cmd/capacitor/web/build
@mkdir -p cmd/capacitor/web/build
@cp -r web/build/* cmd/capacitor/web/build

deps: bin/dagger
bin/dagger:
@mkdir -p bin
curl -L https://dl.dagger.io/dagger/install.sh | sh
@echo "🦄 🌈 🦄 🌈 🦄 🌈"
42 changes: 42 additions & 0 deletions ci/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"
"os"

"dagger.io/dagger"
)

func (m *Ci) Build() {
ctx := context.Background()

client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
panic(err)
}
defer client.Close()

source := client.Container().
From("golang:1.21").
WithDirectory(
"/src",
client.Host().Directory(root()),
dagger.ContainerWithDirectoryOpts{
Exclude: []string{"web"},
},
)

runner := source.WithWorkdir("/src")

runner = exec(runner, "go test -timeout 60s ./...")
_, err = runner.Stderr(ctx)
if err != nil {
panic(err)
}

runner = exec(runner, "go build -o build/capacitor github.com/gimlet-io/capacitor/cmd/capacitor")
_, err = runner.Stderr(ctx)
if err != nil {
panic(err)
}
}
49 changes: 49 additions & 0 deletions ci/buildUi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"context"
"os"
"path/filepath"

"dagger.io/dagger"
)

func (m *Ci) BuildUi() {
ctx := context.Background()

client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
panic(err)
}
defer client.Close()

source := client.Container().
From("node:16-slim").
WithDirectory(
"/src",
client.Host().Directory(filepath.Join(root(), "web")),
dagger.ContainerWithDirectoryOpts{
Exclude: []string{"../web/node_modules/", "../web/build/"},
},
)

runner := source.WithWorkdir("/src")

runner = exec(runner, "npm install")
_, err = runner.Stderr(ctx)
if err != nil {
panic(err)
}

runner = exec(runner, "npm run build")
_, err = runner.Stderr(ctx)
if err != nil {
panic(err)
}

buildDir := runner.Directory("./build")
_, err = buildDir.Export(ctx, filepath.Join(root(), "web", "build"))
if err != nil {
panic(err)
}
}
6 changes: 6 additions & 0 deletions ci/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

type Ci struct{}

func (m *Ci) CI() {
}
5 changes: 5 additions & 0 deletions ci/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "ci",
"root": "..",
"sdk": "go"
}
15 changes: 15 additions & 0 deletions ci/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module main

go 1.20

require (
dagger.io/dagger v0.9.3 // indirect
github.com/99designs/gqlgen v0.17.31 // indirect
github.com/Khan/genqlient v0.6.0 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
)
38 changes: 38 additions & 0 deletions ci/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
dagger.io/dagger v0.9.3 h1:igFU1d6R933Jn6741k5HI/TjAlkpb2/wiBTypNbE0Pw=
dagger.io/dagger v0.9.3/go.mod h1:1iiFzqKOri9kJxUDYUibthMpkfzaWP25B2kx7F/AXIk=
github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158=
github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4=
github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk=
github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU=
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 21 additions & 0 deletions ci/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"os"
"path/filepath"
"strings"

"dagger.io/dagger"
)

func root() string {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
return filepath.Join(wd, "..")
}

func exec(runner *dagger.Container, cmd string) *dagger.Container {
return runner.WithExec(strings.Split(cmd, " "))
}