Skip to content

Commit

Permalink
refactor: move webhook and api to http folder
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <[email protected]>
  • Loading branch information
bluebrown committed Jan 20, 2024
1 parent 5108830 commit 791d880
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 105 deletions.
8 changes: 8 additions & 0 deletions .github/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -o nounset -o errexit -o errtrace -o pipefail

go mod tidy
go generate ./...
go fmt ./...
git diff --exit-code
go test -vet=all ./...
15 changes: 2 additions & 13 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: check
on:
workflow_dispatch: {}
pull_request: {}
push:
branches:
- main
push: {}
permissions:
contents: read
pull-requests: read
Expand All @@ -18,13 +16,4 @@ jobs:
with:
go-version: '1.21.5'
cache: false
- name: install deps
run: go mod download
- name: run checks
run: make check
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
only-new-issues: true
install-mode: "binary"
- run: bash .github/check.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.artifacts/
.local/
.tmp/
27 changes: 3 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
.SILENT:
.PHONY: install check lint test vet generate testinfra dev

bin=.local/bin
INSTALL_DIR ?= $(CURDIR)/$(bin)

RELEASE_TAG ?= $(shell git describe --tags --always --dirty)

image:
docker build -t docker.io/bluebrown/kobold:$(RELEASE_TAG) -f build/Dockerfile .

install:
GOBIN=$(INSTALL_DIR) go install -ldflags '-w -s' ./cmd/...
export RELEASE_TAG ?= $(shell git describe --tags --always --dirty)

check:
go mod tidy
$(MAKE) generate
go fmt ./...
git diff --exit-code
go vet ./...
go test ./...

generate:
go generate ./...

dbshell:
docker run --rm -ti -v /home/blue/.config/kobold:/tmp \
--entrypoint sqlite3 kobold /tmp/kobold.sqlite3
artifacts:
bash build/artifacts.sh

testinfra: $(bin)/skaffold
bash -x e2e/kind/up.sh
Expand All @@ -38,4 +18,3 @@ $(bin)/skaffold:
mkdir -p $(bin)
curl -fsSL https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 \
| install /dev/stdin $(bin)/skaffold

2 changes: 1 addition & 1 deletion build/.swaggo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
replace github.com/volatiletech/null/v8.String string
replace git.GitPackageURI string
replace git.PackageURI string
10 changes: 10 additions & 0 deletions build/artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ out="${1:-.artifacts}"
out="${out%/}"
tag="${RELEASE_TAG:-dev}"

echo "Building artifacts in $out" >&2

script_dir="$(dirname "$(readlink -f "$0")")"
cd "$script_dir/.."

Expand All @@ -14,6 +16,8 @@ td="build/.tmp"
trap 'rm -rf "$td"' EXIT
mkdir -p "$td" && rm -rf "${td:?}"/*

echo "Building manifests..." >&2

cd "$td"
kustomize create
kustomize edit add resource "../kube"
Expand All @@ -23,9 +27,13 @@ kustomize edit set label "app.kubernetes.io/version:$tag"
cd -
kustomize build "$td" >"$out/manifests.yaml"

echo "Building OCI image..." >&2

docker build -f build/Dockerfile -t "docker.io/bluebrown/kobold:$tag" .
docker save "docker.io/bluebrown/kobold:$tag" >"$out/oci.tar"

echo "Building binaries..." >&2

GOBIN="$script_dir/../$out" go install ./cmd/...

for f in $out/*; do
Expand All @@ -36,3 +44,5 @@ for f in $out/*; do
mv "$f" "$out/kobold-${f##*/}"
fi
done

echo "Done" >&2
2 changes: 1 addition & 1 deletion build/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
package build

//go:generate go run github.com/sqlc-dev/sqlc/cmd/sqlc generate
//go:generate go run github.com/swaggo/swag/cmd/swag init --dir ../api/ --output ../api/docs/ --generalInfo handler.go --parseDependency github.com/bluebrown/kobold/store
//go:generate go run github.com/swaggo/swag/cmd/swag init --dir ../http/api/ --output ../http/api/docs/ --generalInfo handler.go --parseDependency github.com/bluebrown/kobold/store/model
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"golang.org/x/sync/errgroup"
_ "modernc.org/sqlite"

"github.com/bluebrown/kobold/api"
"github.com/bluebrown/kobold/config"
"github.com/bluebrown/kobold/http/api"
"github.com/bluebrown/kobold/http/webhook"
"github.com/bluebrown/kobold/store"
"github.com/bluebrown/kobold/store/schema"
"github.com/bluebrown/kobold/task"
"github.com/bluebrown/kobold/webhook"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion git/pkguri.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (uri *PackageURI) Scan(value interface{}) error {
case []byte:
b = v
default:
return fmt.Errorf("cannot convert %T to GitPackageURI", value)
return fmt.Errorf("cannot convert %T to PackageURI", value)
}
return uri.UnmarshalText(b)
}
Expand Down
22 changes: 4 additions & 18 deletions api/docs/docs.go → http/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,6 @@ const docTemplate = `{
}
}
},
"git.PackageURI": {
"type": "object",
"properties": {
"pkg": {
"type": "string"
},
"ref": {
"type": "string"
},
"repo": {
"type": "string"
}
}
},
"model.Channel": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -556,7 +542,7 @@ const docTemplate = `{
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
}
}
},
Expand All @@ -583,7 +569,7 @@ const docTemplate = `{
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -631,7 +617,7 @@ const docTemplate = `{
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -667,7 +653,7 @@ const docTemplate = `{
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down
22 changes: 4 additions & 18 deletions api/docs/swagger.json → http/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,20 +487,6 @@
}
}
},
"git.PackageURI": {
"type": "object",
"properties": {
"pkg": {
"type": "string"
},
"ref": {
"type": "string"
},
"repo": {
"type": "string"
}
}
},
"model.Channel": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -545,7 +531,7 @@
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
}
}
},
Expand All @@ -572,7 +558,7 @@
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -620,7 +606,7 @@
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -656,7 +642,7 @@
"type": "string"
},
"repo_uri": {
"$ref": "#/definitions/git.PackageURI"
"type": "string"
},
"status": {
"type": "string"
Expand Down
17 changes: 4 additions & 13 deletions api/docs/swagger.yaml → http/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ definitions:
message:
type: string
type: object
git.PackageURI:
properties:
pkg:
type: string
ref:
type: string
repo:
type: string
type: object
model.Channel:
properties:
decoder_name:
Expand Down Expand Up @@ -44,7 +35,7 @@ definitions:
post_hook_name:
type: string
repo_uri:
$ref: '#/definitions/git.PackageURI'
type: string
type: object
model.PipelineRunListRow:
properties:
Expand All @@ -62,7 +53,7 @@ definitions:
post_hook:
type: string
repo_uri:
$ref: '#/definitions/git.PackageURI'
type: string
status:
type: string
timestamp: {}
Expand Down Expand Up @@ -94,7 +85,7 @@ definitions:
post_hook:
type: string
repo_uri:
$ref: '#/definitions/git.PackageURI'
type: string
status:
type: string
timestamp: {}
Expand All @@ -118,7 +109,7 @@ definitions:
post_hook_name:
type: string
repo_uri:
$ref: '#/definitions/git.PackageURI'
type: string
status:
type: string
task_group_fingerprint:
Expand Down
2 changes: 1 addition & 1 deletion api/handler.go → http/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/schema"
httpSwagger "github.com/swaggo/http-swagger/v2"

"github.com/bluebrown/kobold/api/docs"
"github.com/bluebrown/kobold/http/api/docs"
"github.com/bluebrown/kobold/store/model"
)

Expand Down
File renamed without changes.
15 changes: 2 additions & 13 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ would be more solid, if we didnt have to rely on the user to do this.

## starlark files

store starlark scripts in file instead of db
store starlark scripts in file instead of db? This would make it more easy to mount
custom scripts into the container

## generic pipeline handler

Expand All @@ -34,15 +35,3 @@ allow to configure the commit and pr messages
some tools split image references across fields (e.g. image and tag). This
should be supported by kobold. There could be another option tag to specify what
part of the image ref should be set.

## option to truncate tables

when the config file is reads, the tables will be updated. But it will never
delete entries that are not present in the config file. This could lead to
unwanted pipelines runs. There should be an option to truncate the tables before
updating them.

## track noop changes

not every pipeline run leads to actual changes in a git repo. This could be
tracked as additional field in the database and as prometheus metric.

0 comments on commit 791d880

Please sign in to comment.