update action to dagger 0.2

- Remove AGE key setup
- Update README to use `dagger do`
- Update tests to dagger 0.2

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-03-09 12:07:13 -08:00
parent 64f8bd95de
commit 24d6bfd692
96 changed files with 15028 additions and 70 deletions

View file

@ -0,0 +1,51 @@
package go
import (
"dagger.io/dagger"
)
// Build a go binary
#Build: {
// Source code
source: dagger.#FS
// Target package to build
package: *"." | string
// Target architecture
arch: *"amd64" | string
// Target OS
os: *"linux" | string
// Build tags to use for building
tags: *"" | string
// LDFLAGS to use for linking
ldflags: *"" | string
env: [string]: string
container: #Container & {
"source": source
"env": {
env
GOOS: os
GOARCH: arch
}
command: {
args: [package]
flags: {
build: true
"-v": true
"-tags": tags
"-ldflags": ldflags
"-o": "/output/"
}
}
export: directories: "/output": _
}
// Directory containing the output of the build
output: container.export.directories."/output"
}

View file

@ -0,0 +1,41 @@
// Go operation
package go
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
// A standalone go environment to run go command
#Container: {
// Container app name
name: *"go_builder" | string
// Source code
source: dagger.#FS
// Use go image
_image: #Image
_sourcePath: "/src"
_cachePath: "/root/.cache/gocache"
docker.#Run & {
input: *_image.output | docker.#Image
workdir: "/src"
command: name: "go"
mounts: {
"source": {
dest: _sourcePath
contents: source
}
"go assets cache": {
contents: dagger.#CacheDir & {
id: "\(name)_assets"
}
dest: _cachePath
}
}
env: GOMODCACHE: _cachePath
}
}

View file

@ -0,0 +1,37 @@
package go
import (
"universe.dagger.io/docker"
)
// Go image default version
#DefaultVersion: "1.16"
// Build a go base image
#Image: {
version: *#DefaultVersion | string
packages: [pkgName=string]: version: string | *""
// FIXME Basically a copy of alpine.#Build with a different image
// Should we create a special definition?
docker.#Build & {
steps: [
docker.#Pull & {
source: "index.docker.io/golang:\(version)-alpine"
},
for pkgName, pkg in packages {
docker.#Run & {
command: {
name: "apk"
args: ["add", "\(pkgName)\(pkg.version)"]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
]
}
}

View file

@ -0,0 +1,17 @@
package go
// Test a go package
#Test: {
// Package to test
package: *"." | string
#Container & {
command: {
args: [package]
flags: {
test: true
"-v": true
}
}
}
}

View file

@ -0,0 +1,43 @@
package go
import (
"dagger.io/dagger"
"universe.dagger.io/go"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
client: filesystem: "./data/hello": read: contents: dagger.#FS
actions: tests: build: {
_baseImage: alpine.#Build
simple: {
build: go.#Build & {
source: client.filesystem."./data/hello".read.contents
}
exec: docker.#Run & {
input: _baseImage.output
command: {
name: "/bin/sh"
args: ["-c", "/bin/hello >> /output.txt"]
}
env: NAME: "dagger"
mounts: binary: {
dest: "/bin/hello"
contents: build.output
source: "/test"
}
}
verify: dagger.#ReadFile & {
input: exec.output.rootfs
path: "/output.txt"
} & {
contents: "Hi dagger!"
}
}
}
}

View file

@ -0,0 +1,30 @@
package go
import (
"dagger.io/dagger"
"universe.dagger.io/go"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: tests: container: {
_source: dagger.#Scratch & {}
simple: go.#Container & {
source: _source
command: args: ["version"]
}
override: {
base: alpine.#Build & {
packages: go: _
}
command: go.#Container & {
input: base.output
source: _source
command: args: ["version"]
}
}
}
}

View file

@ -0,0 +1,44 @@
package go
import (
"dagger.io/dagger"
"universe.dagger.io/go"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: tests: image: {
_source: dagger.#Scratch & {}
simple: {
_image: go.#Image & {}
verify: docker.#Run & {
input: _image.output
command: {
name: "/bin/sh"
args: ["-c", """
go version | grep "1.16"
"""]
}
}
}
custom: {
_image: go.#Image & {
version: "1.17"
packages: bash: _
}
verify: docker.#Run & {
input: _image.output
command: {
name: "/bin/bash"
args: ["-c", """
go version | grep "1.17"
"""]
}
}
}
}
}

View file

@ -0,0 +1,12 @@
setup() {
load '../../bats_helpers'
common_setup
}
@test "bash" {
dagger up ./build.cue
dagger up ./container.cue
dagger up ./image.cue
dagger up ./test.cue
}

View file

@ -0,0 +1,15 @@
package go
import (
"dagger.io/dagger"
"universe.dagger.io/go"
)
dagger.#Plan & {
client: filesystem: "./data/hello": read: contents: dagger.#FS
actions: tests: test: simple: go.#Test & {
source: client.filesystem."./data/hello".read.contents
package: "./greeting"
}
}