diff --git a/.data/.dive-ci b/.data/.dive-ci index 27b426fbe..7b3545eb5 100644 --- a/.data/.dive-ci +++ b/.data/.dive-ci @@ -10,6 +10,6 @@ rules: highestWastedBytes: 20Mb # If the amount of wasted space makes up for X% of the image, mark as failed. (fail if the threshold is met or crossed; expressed as a percentage between 0-1) - highestUserWastedPercent: 0.10 + highestUserWastedPercent: 0.5 plugin1/rule1: error diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 373b3036b..5186599a5 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,5 +1,5 @@ name: 'app-pipeline' -on: [ push, pull_request ] +on: [ push ] env: DOCKER_CLI_VERSION: "19.03.1" jobs: @@ -84,8 +84,63 @@ jobs: name: artifacts path: dist + + test-linux-artifacts: + needs: [ build-artifacts ] + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@master + + - uses: actions/download-artifact@master + with: + name: artifacts + path: dist + + - name: Test linux run + run: make ci-test-linux-run + + - name: Test DEB package installation + run: make ci-test-deb-package-install + + - name: Test RPM package installation + run: make ci-test-rpm-package-install + + + test-mac-artifacts: + needs: [ build-artifacts ] + runs-on: macos-latest + steps: + + - uses: actions/checkout@master + + - uses: actions/download-artifact@master + with: + name: artifacts + path: dist + + - name: Test darwin run + run: make ci-test-mac-run + + + test-windows-artifacts: + needs: [ build-artifacts ] + runs-on: windows-latest + steps: + + - uses: actions/checkout@master + + - uses: actions/download-artifact@master + with: + name: artifacts + path: dist + + - name: Test windows run + run: make ci-test-windows-run + + release: - needs: [ build-artifacts, unit-test ] + needs: [ unit-test, build-artifacts, test-linux-artifacts, test-mac-artifacts, test-windows-artifacts ] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') steps: diff --git a/Makefile b/Makefile index 0ace2e15f..26043e8d4 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,53 @@ ci-test-production-image: '${TEST_IMAGE}' \ --ci +ci-test-deb-package-install: + docker run \ + -v //var/run/docker.sock://var/run/docker.sock \ + -v /${PWD}://src \ + -w //src \ + ubuntu:latest \ + /bin/bash -x -c "\ + apt update && \ + apt install -y curl && \ + curl -L 'https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz' | \ + tar -vxzf - docker/docker --strip-component=1 && \ + mv docker /usr/local/bin/ &&\ + docker version && \ + apt install ./dist/dive_*_linux_amd64.deb -y && \ + dive --version && \ + dive '${TEST_IMAGE}' --ci \ + " + +ci-test-rpm-package-install: + docker run \ + -v //var/run/docker.sock://var/run/docker.sock \ + -v /${PWD}://src \ + -w //src \ + fedora:latest \ + /bin/bash -x -c "\ + curl -L 'https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz' | \ + tar -vxzf - docker/docker --strip-component=1 && \ + mv docker /usr/local/bin/ &&\ + docker version && \ + dnf install ./dist/dive_*_linux_amd64.rpm -y && \ + dive --version && \ + dive '${TEST_IMAGE}' --ci \ + " + +ci-test-linux-run: + ./dist/dive_linux_amd64/dive '${TEST_IMAGE}' --ci + +# we're not attempting to test docker, just our ability to run on these systems. This avoids setting up docker in CI. +ci-test-mac-run: + chmod 755 ./dist/dive_darwin_amd64/dive && \ + ./dist/dive_darwin_amd64/dive --source docker-archive .data/test-docker-image.tar --ci --ci-config .data/.dive-ci + +# we're not attempting to test docker, just our ability to run on these systems. This avoids setting up docker in CI. +ci-test-windows-run: + ./dist/dive_windows_amd64/dive --source docker-archive .data/test-docker-image.tar --ci --ci-config .data/.dive-ci + + ## For development @@ -65,6 +112,9 @@ build: generate-test-data: docker build -t dive-test:latest -f .data/Dockerfile.test-image . && docker image save -o .data/test-docker-image.tar dive-test:latest && echo 'Exported test data!' +test: + ./.scripts/test-coverage.sh + dev: docker run -ti --rm -v $(PWD):/app -w /app -v dive-pkg:/go/pkg/ golang:1.13 bash diff --git a/runtime/run.go b/runtime/run.go index 0c8d08af2..14c42af1b 100644 --- a/runtime/run.go +++ b/runtime/run.go @@ -71,9 +71,9 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev } if options.Ci { - events.message(fmt.Sprintf(" efficiency: %2.4f %%\n", analysis.Efficiency*100)) - events.message(fmt.Sprintf(" wastedBytes: %d bytes (%s)\n", analysis.WastedBytes, humanize.Bytes(analysis.WastedBytes))) - events.message(fmt.Sprintf(" userWastedPercent: %2.4f %%\n", analysis.WastedUserPercent*100)) + events.message(fmt.Sprintf(" efficiency: %2.4f %%", analysis.Efficiency*100)) + events.message(fmt.Sprintf(" wastedBytes: %d bytes (%s)", analysis.WastedBytes, humanize.Bytes(analysis.WastedBytes))) + events.message(fmt.Sprintf(" userWastedPercent: %2.4f %%", analysis.WastedUserPercent*100)) evaluator := ci.NewCiEvaluator(options.CiConfig) pass := evaluator.Evaluate(analysis) diff --git a/runtime/run_test.go b/runtime/run_test.go index b188e2243..faca37964 100644 --- a/runtime/run_test.go +++ b/runtime/run_test.go @@ -189,9 +189,9 @@ func TestRun(t *testing.T) { events: []testEvent{ {stdout: "Building image...", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "Analyzing image...", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " efficiency: 98.4421 %\n", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " wastedBytes: 32025 bytes (32 kB)\n", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " userWastedPercent: 48.3491 %\n", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " efficiency: 98.4421 %", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " wastedBytes: 32025 bytes (32 kB)", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " userWastedPercent: 48.3491 %", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "Inefficient Files:\nCount Wasted Space File Path\n 2 13 kB /root/saved.txt\n 2 13 kB /root/example/somefile1.txt\n 2 6.4 kB /root/example/somefile3.txt\nResults:\n FAIL: highestUserWastedPercent: too many bytes wasted, relative to the user bytes added (%-user-wasted-bytes=0.4834911001404049 > threshold=0.1)\n FAIL: highestWastedBytes: too many bytes wasted (wasted-bytes=32025 > threshold=1000)\n PASS: lowestEfficiency\nResult:FAIL [Total:3] [Passed:1] [Failed:2] [Warn:0] [Skipped:0]\n", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "", stderr: "", errorOnExit: true, errMessage: ""}, }, @@ -209,9 +209,9 @@ func TestRun(t *testing.T) { events: []testEvent{ {stdout: "Building image...", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "Analyzing image...", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " efficiency: 98.4421 %\n", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " wastedBytes: 32025 bytes (32 kB)\n", stderr: "", errorOnExit: false, errMessage: ""}, - {stdout: " userWastedPercent: 48.3491 %\n", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " efficiency: 98.4421 %", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " wastedBytes: 32025 bytes (32 kB)", stderr: "", errorOnExit: false, errMessage: ""}, + {stdout: " userWastedPercent: 48.3491 %", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "Inefficient Files:\nCount Wasted Space File Path\nNone\nResults:\n MISCONFIGURED: highestUserWastedPercent: invalid config value (''): strconv.ParseFloat: parsing \"\": invalid syntax\n MISCONFIGURED: highestWastedBytes: invalid config value (''): strconv.ParseFloat: parsing \"\": invalid syntax\n MISCONFIGURED: lowestEfficiency: invalid config value (''): strconv.ParseFloat: parsing \"\": invalid syntax\nCI Misconfigured\n", stderr: "", errorOnExit: false, errMessage: ""}, {stdout: "", stderr: "", errorOnExit: true, errMessage: ""}, },