From f502d1684a78f2232d5612329e1698f66be85642 Mon Sep 17 00:00:00 2001 From: Michael Sauter Date: Mon, 9 Oct 2023 09:04:40 +0200 Subject: [PATCH] Fix various smaller errors due to refactoring --- .github/workflows/release.yaml | 7 +- deploy/chart/templates/task-finish.yaml | 2 +- deploy/chart/templates/task-start.yaml | 2 +- docs/repository-layout.adoc | 2 +- test/scripts/download-aqua-scanner_test.go | 146 --------------------- 5 files changed, 6 insertions(+), 153 deletions(-) delete mode 100644 test/scripts/download-aqua-scanner_test.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1a137ef6..93aeb054 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -28,12 +28,11 @@ jobs: strategy: fail-fast: true matrix: - image: ["aqua-scan", "finish", "go-toolset", "gradle-toolset", "helm", "node16-npm-toolset", "node18-npm-toolset", "package-image", "pipeline-manager", "python-toolset", "sonar", "start"] + image: ["finish", "pipeline-manager", "start"] permissions: contents: read packages: write id-token: write - steps: - name: Checkout uses: actions/checkout@v4 @@ -58,9 +57,9 @@ jobs: uses: docker/build-push-action@v3 with: context: . - file: build/package/Dockerfile.${{ matrix.image }} + file: build/images/Dockerfile.${{ matrix.image }} push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/ods-${{ matrix.image }}:${{ needs.setup.outputs.imageTag }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/${{ matrix.image }}:${{ needs.setup.outputs.imageTag }} release-chart: runs-on: ubuntu-latest diff --git a/deploy/chart/templates/task-finish.yaml b/deploy/chart/templates/task-finish.yaml index 1dc3cbab..b33ac61c 100644 --- a/deploy/chart/templates/task-finish.yaml +++ b/deploy/chart/templates/task-finish.yaml @@ -19,7 +19,7 @@ spec: default: '' steps: - name: finish - # Image is built from build/package/Dockerfile.finish. + # Image is built from build/images/Dockerfile.finish. image: '{{.Values.imageRepository}}/finish:{{.Values.imageTag | default .Chart.AppVersion}}' env: - name: HOME diff --git a/deploy/chart/templates/task-start.yaml b/deploy/chart/templates/task-start.yaml index 4f2e4627..394c379e 100644 --- a/deploy/chart/templates/task-start.yaml +++ b/deploy/chart/templates/task-start.yaml @@ -75,7 +75,7 @@ spec: name: url steps: - name: start - # Image is built from build/package/Dockerfile.start. + # Image is built from build/images/Dockerfile.start. image: '{{.Values.imageRepository}}/start:{{.Values.imageTag | default .Chart.AppVersion}}' env: - name: HOME diff --git a/docs/repository-layout.adoc b/docs/repository-layout.adoc index d74a4781..4915013c 100644 --- a/docs/repository-layout.adoc +++ b/docs/repository-layout.adoc @@ -6,7 +6,7 @@ The most important pieces are: * **build/images**: `Dockerfile`s for the various container images in use. These images back Tekton tasks or the pipeline manager. * **cmd**: Main executables. These are installed (in different combinations) into the container images. -* **deploy**: OpenShift/K8S resource definitions, such as `Task` resources. The tasks make use of the images built via `build/package` and released to ghcr.io. Their `script` calls an executables built from the `cmd` folder. +* **deploy**: OpenShift/K8S resource definitions, such as `Task` resources. The tasks make use of the images built via `build/images` and released to ghcr.io. Their `script` calls an executables built from the `cmd` folder. * **docs**: Design and user documents * **internal/manager**: Implementation of the webhook receiver and pipeline manager - it creates and modifies the actual Tekton pipelines on the fly based on the config found in the repository triggering the webhook request. * **pkg**: Packages shared by the various main executables and the pipeline manager. These packages are the public interface and may be used outside this repo (e.g. by custom tasks). Example of packages are `bitbucket` (a Bitbucket Server API v1.0 client), `sonar` (a SonarQube client exposing API endpoints, scanner CLI and report CLI in one unified interface), `nexus` (a Nexus client for uploading, downloading and searching for assets) and `config` (the ODS configuration specification). diff --git a/test/scripts/download-aqua-scanner_test.go b/test/scripts/download-aqua-scanner_test.go deleted file mode 100644 index 11803f82..00000000 --- a/test/scripts/download-aqua-scanner_test.go +++ /dev/null @@ -1,146 +0,0 @@ -package scripts_test - -import ( - "errors" - "flag" - "fmt" - "net/http" - "net/http/httptest" - "os" - "testing" - - "github.com/opendevstack/ods-pipeline/internal/command" -) - -const ( - downloadAquaScannerScript = "../../build/package/scripts/download-aqua-scanner.sh" - fakeScannerBinary = `#!/bin/bash -echo 1.7.3` -) - -var md5Bin = flag.String("md5bin", "md5", "md5 binary to use") - -func TestCachedDownload(t *testing.T) { - hits := 0 - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - hits++ - fmt.Fprintln(w, fakeScannerBinary) - })) - defer ts.Close() - dir, cleanupDir := tmpDir(t) - defer cleanupDir() - - t.Log("Fresh run -> download") - runScriptOrFatal(t, dir, fmt.Sprintf("%s/foo", ts.URL)) - if hits != 1 { - t.Error("Wanted hit, got none") - } - fileExistsInDir(t, dir, "aquasec", ".md5-aquasec") - - t.Log("Second run for same URL -> no download") - runScriptOrFatal(t, dir, fmt.Sprintf("%s/foo", ts.URL)) - if hits > 1 { - t.Error("Wanted no further hit, got more") - } - fileExistsInDir(t, dir, "aquasec", ".md5-aquasec") - - t.Log("Third run for different URL -> download") - runScriptOrFatal(t, dir, fmt.Sprintf("%s/bar", ts.URL)) - if hits != 2 { - t.Error("Wanted further hit, got none") - } - fileExistsInDir(t, dir, "aquasec", ".md5-aquasec") -} - -func TestSkipDownload(t *testing.T) { - dir, cleanupDir := tmpDir(t) - defer cleanupDir() - - t.Log("No URL") - runScriptOrFatal(t, dir, "") - fileDoesNotExistInDir(t, dir, "aquasec", ".md5-aquasec") - - t.Log("URL set to 'none'") - runScriptOrFatal(t, dir, "none") - fileDoesNotExistInDir(t, dir, "aquasec", ".md5-aquasec") -} - -func TestBrokenDownload(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "") - })) - defer ts.Close() - dir, cleanupDir := tmpDir(t) - defer cleanupDir() - - t.Log("Download") - err := runScript(t, dir, fmt.Sprintf("%s/foo", ts.URL)) - if err == nil { - t.Fatal("script should error on broken download") - } - fileDoesNotExistInDir(t, dir, "aquasec", ".md5-aquasec") -} - -// runScriptOrFatal calls runScript, then t.Fatal on error. -func runScriptOrFatal(t *testing.T, dir, url string) { - if err := runScript(t, dir, url); err != nil { - t.Fatal(err) - } -} - -// runScript runs the download script against given url -// and places the downloaded file into dir. -func runScript(t *testing.T, dir, url string) error { - return command.Run( - downloadAquaScannerScript, - []string{ - fmt.Sprintf("--bin-dir=%s", dir), - fmt.Sprintf("--aqua-scanner-url=%s", url), - }, []string{fmt.Sprintf("MD5_BIN=%s", *md5Bin)}, - &testingLogWriter{t}, - &testingLogWriter{t}, - ) -} - -// fileExistsInDir checks if file(s) exist in dir or errors. -func fileExistsInDir(t *testing.T, dir string, files ...string) { - for _, file := range files { - f := fmt.Sprintf("%s/%s", dir, file) - if _, err := os.Stat(f); errors.Is(err, os.ErrNotExist) { - t.Errorf("Want file %s, got %s", f, err) - } - } -} - -// fileDoesNotExistInDir checks if file(s) exist in dir or errors. -func fileDoesNotExistInDir(t *testing.T, dir string, files ...string) { - for _, file := range files { - f := fmt.Sprintf("%s/%s", dir, file) - if _, err := os.Stat(f); err == nil { - t.Errorf("Did not want file %s", f) - } - } -} - -// tmpDir creates a temp dir or fails. -func tmpDir(t *testing.T) (string, func()) { - t.Helper() - dir, err := os.MkdirTemp(".", "download-aqua-scanner-") - if err != nil { - t.Fatal(err) - } - return dir, func() { os.RemoveAll(dir) } -} - -// testingLogWriter implements io.Writer so that -// it can proxy to t.Log when an io.Writer is required. -type testingLogWriter struct { - t *testing.T -} - -// Write proxies to t.Logf. -func (f *testingLogWriter) Write(p []byte) (n int, err error) { - f.t.Helper() - f.t.Logf("%s", string(p)) - return len(p), nil -}