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

cmd/osbuild-worker-executor: add oaas as worker executor #4189

Merged
merged 8 commits into from
Jun 5, 2024
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ issues:

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
exclude-rules:
- path: ^cmd/osbuild-worker-executor/.*_test\.go$
linters: ["gosec"]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ man: $(MANPAGES_TROFF)
build: $(BUILDDIR)/bin/
go build -o $<osbuild-composer ./cmd/osbuild-composer/
go build -o $<osbuild-worker ./cmd/osbuild-worker/
go build -o $<osbuild-worker-executor ./cmd/osbuild-worker-executor/
go build -o $<osbuild-upload-azure ./cmd/osbuild-upload-azure/
go build -o $<osbuild-upload-aws ./cmd/osbuild-upload-aws/
go build -o $<osbuild-upload-gcp ./cmd/osbuild-upload-gcp/
Expand Down
37 changes: 37 additions & 0 deletions cmd/osbuild-worker-executor/build_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"os"
"path/filepath"
)

type buildResult struct {
resultGood string
resultBad string
}

func newBuildResult(config *Config) *buildResult {
return &buildResult{
resultGood: filepath.Join(config.BuildDirBase, "result.good"),
resultBad: filepath.Join(config.BuildDirBase, "result.bad"),
}
}

func (br *buildResult) Mark(err error) error {
if err == nil {
return os.WriteFile(br.resultGood, nil, 0600)
} else {
return os.WriteFile(br.resultBad, nil, 0600)
}
}

// todo: switch to (Good, Bad, Unknown)
func (br *buildResult) Good() bool {
_, err := os.Stat(br.resultGood)
return err == nil
}

func (br *buildResult) Bad() bool {
_, err := os.Stat(br.resultBad)
return err == nil
}
25 changes: 25 additions & 0 deletions cmd/osbuild-worker-executor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"flag"
)

type Config struct {
Host string
Port string

BuildDirBase string
}

func newConfigFromCmdline(args []string) (*Config, error) {
var config Config

fs := flag.NewFlagSet("worker-executor", flag.ContinueOnError)
fs.StringVar(&config.Host, "host", "localhost", "host to listen on")
fs.StringVar(&config.Port, "port", "8001", "port to listen on")
fs.StringVar(&config.BuildDirBase, "build-path", "/var/tmp/worker-executor", "base dir to run the builds in")
if err := fs.Parse(args); err != nil {
return nil, err
}
return &config, nil
}
46 changes: 46 additions & 0 deletions cmd/osbuild-worker-executor/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"os"
"path/filepath"
"testing"

"github.com/sirupsen/logrus"
logrusTest "github.com/sirupsen/logrus/hooks/test"
)

var (
Run = run

HandleIncludedSources = handleIncludedSources
)

func MockLogger() (hook *logrusTest.Hook, restore func()) {
saved := logrusNew
logger, hook := logrusTest.NewNullLogger()
logrusNew = func() *logrus.Logger {
return logger
}
logger.SetLevel(logrus.DebugLevel)

return hook, func() {
logrusNew = saved
}
}

func MockOsbuildBinary(t *testing.T, new string) (restore func()) {
t.Helper()

saved := osbuildBinary

tmpdir := t.TempDir()
osbuildBinary = filepath.Join(tmpdir, "fake-osbuild")
/* #nosec G306 */
if err := os.WriteFile(osbuildBinary, []byte(new), 0755); err != nil {
t.Fatal(err)
}

return func() {
osbuildBinary = saved
}
}
Loading
Loading