Skip to content

Commit

Permalink
feat: publish node, golang and golangci-lint modules
Browse files Browse the repository at this point in the history
Signed-off-by: Vasek - Tom C <[email protected]>
  • Loading branch information
TomChv committed Oct 14, 2023
1 parent 0c8ed6d commit 730f7c0
Show file tree
Hide file tree
Showing 32 changed files with 639 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DAGGER_SRC_ROOT=$(cd ../../DAGGER/dagger && pwd)
export _EXPERIMENTAL_DAGGER_CLI_BIN=$DAGGER_SRC_ROOT/bin/dagger
export _EXPERIMENTAL_DAGGER_RUNNER_HOST=docker-container://dagger-engine.dev
export PATH=$DAGGER_SRC_ROOT/bin:$PATH
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
name: Lint project
runs-on: ubuntu-latest
env:
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Dagger Zenith
run: |
cd /usr/local/bin && { sudo curl -L https://github.com/jpadams/shykes-dagger-zenith-builder/releases/download/nightly/dagger-zenith-linux-amd64 -o dagger; sudo chmod +x dagger; cd -; }
dagger version
- name: Run lint
run: |
cd ci
dagger query --doc lint.gql
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Jetbrains
.idea/

# Env
*.env
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run:
modules-download-mode: readonly
go: '1.21.3'
timeout: 5m

linters:
disable-all: true
enable:
- gofmt
- goimports
- goprintffuncname
- typecheck
- unconvert
- unused
- whitespace
3 changes: 3 additions & 0 deletions ci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
63 changes: 63 additions & 0 deletions ci/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"context"
"fmt"
"golang.org/x/sync/errgroup"
)

type Ci struct{}

func source() *Directory {
return dag.Host().Directory(".", HostDirectoryOpts{
Include: []string{"**/*.go", "**.*go.mod", "**/*go.sum"},
})
}

func (m *Ci) Lint(ctx context.Context) error {
lintCtr := dag.
GolangciLint().
WithVersion("v1.54-alpine")

ctr := dag.
Golang().
WithContainer(lintCtr).
WithSource(source())

eg, gctx := errgroup.WithContext(ctx)

eg.Go(func() error {
out, err := ctr.Exec([]string{"run", "-v", "golang/*.go"}).Stdout(gctx)
if err != nil {
return err
}

fmt.Println(out)

return nil
})

eg.Go(func() error {
out, err := ctr.Exec([]string{"run", "-v", "golangci-lint/*.go"}).Stdout(gctx)
if err != nil {
return err
}

fmt.Println(out)

return nil
})

eg.Go(func() error {
out, err := ctr.Exec([]string{"run", "-v", "node/*.go"}).Stdout(gctx)
if err != nil {
return err
}

fmt.Println(out)

return nil
})

return nil
}
11 changes: 11 additions & 0 deletions ci/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ci",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:f239c6f6c3ceaa1f760b589fac43b1d0704e45d3@sha256:915f41b414b12a878c60d96869f8ff8155e6ce122b1849303b995b65a343591f",
"root": "..",
"dependencies": [
"../golang",
"../golangci-lint",
"../node"
]
}
14 changes: 14 additions & 0 deletions ci/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module ci

go 1.21.3

require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/sync v0.3.0
)

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
)
33 changes: 33 additions & 0 deletions ci/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
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.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 5 additions & 0 deletions ci/lint.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
ci {
lint
}
}
3 changes: 3 additions & 0 deletions golang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
13 changes: 13 additions & 0 deletions golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Golang

A golang container module made to be extended to match your needs.

## Features

| Command | Done |
|--------------------------------------------|------|
| Setup a Golang environment ||
| Run command (Test, Build, Install...) ||
| Extends current package to match your need ||

Made with ❤️ by Quartz.
50 changes: 50 additions & 0 deletions golang/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

// Exec returns the container with the given command set.
func (g *Golang) Exec(args []string) *Container {
return g.Ctr.WithExec(args)
}

// Run returns the container with the run command executed.
func (g *Golang) Run(file string) *Container {
return g.Exec([]string{"run", file})
}

// Test returns the container with the test executed.
func (g *Golang) Test() *Container {
return g.Exec([]string{"test"})
}

type BuildOpts struct {
Output string `doc:"Path to write the built binary"`
}

// Build returns the container with the built artifact.
func (g *Golang) Build(opts BuildOpts) *Container {
cmd := []string{"build"}

if opts.Output != "" {
cmd = append(cmd, "-o", opts.Output)
}

return g.Exec(cmd)
}

// Download installs dependencies written in the source directory.
func (g *Golang) Download() *Golang {
return g.WithContainer(g.Exec([]string{"mod", "download"}))
}

// Get returns the container with given packages downloaded.
func (g *Golang) Get(packages []string) *Golang {
cmd := append([]string{"get", "-u"}, packages...)

return g.WithContainer(g.Exec(cmd))
}

// Install returns the container with given packages installed.
func (g *Golang) Install(packages []string) *Golang {
cmd := append([]string{"install"}, packages...)

return g.WithContainer(g.Exec(cmd))
}
5 changes: 5 additions & 0 deletions golang/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "golang",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:f239c6f6c3ceaa1f760b589fac43b1d0704e45d3@sha256:915f41b414b12a878c60d96869f8ff8155e6ce122b1849303b995b65a343591f"
}
14 changes: 14 additions & 0 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module golang

go 1.21.3

require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/sync v0.3.0
)

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
)
33 changes: 33 additions & 0 deletions golang/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
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.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
48 changes: 48 additions & 0 deletions golang/golang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import "fmt"

type Golang struct {
Ctr *Container
}

// WithVersion returns Golang container with given image version.
//
// The container is configured with cache for packages and build artifacts.
// The default entrypoint is set to `go`.
func (g *Golang) WithVersion(version string) *Golang {
if g.Ctr == nil {
g.Ctr = dag.Container()
}

g.Ctr = g.Ctr.
From(fmt.Sprintf("golang:%s", version)).
WithEntrypoint([]string{"go"}).
WithMountedCache("/go/pkg/mod", dag.CacheVolume("gomod")).
WithMountedCache("/root/.cache/go-build", dag.CacheVolume("gobuild"))

return g
}

// WithContainer returns Golang container set with the given container.
func (g *Golang) WithContainer(ctr *Container) *Golang {
g.Ctr = ctr

return g
}

// Container returns Golang container.
func (g *Golang) Container() *Container {
return g.Ctr
}

// WithSource returns the Golang container with given source mounted to `/src`.
func (g *Golang) WithSource(source *Directory) *Golang {
workdir := "/src"

g.Ctr = g.Ctr.
WithWorkdir(workdir).
WithMountedDirectory(workdir, source)

return g
}
3 changes: 3 additions & 0 deletions golangci-lint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
6 changes: 6 additions & 0 deletions golangci-lint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Golangci-lint

A simplistic module to configure [golangci-lint](https://golangci-lint.run/) in a container.

💡This module is closely bind to [Golang module](../golang), please make sure you read this module doc to understand
how to use this one.
9 changes: 9 additions & 0 deletions golangci-lint/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "golangci-lint",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:f239c6f6c3ceaa1f760b589fac43b1d0704e45d3@sha256:915f41b414b12a878c60d96869f8ff8155e6ce122b1849303b995b65a343591f",
"root": "..",
"dependencies": [
"../golang"
]
}
Loading

0 comments on commit 730f7c0

Please sign in to comment.