add package install tests + basic execution of dive

This commit is contained in:
Alex Goodman 2019-11-09 15:11:58 -05:00
parent 9e4fec25ed
commit ba7b39c52f
No known key found for this signature in database
GPG key ID: 98AF011C5C78EB7E
5 changed files with 124 additions and 23 deletions

View file

@ -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

View file

@ -1,5 +1,5 @@
name: 'app-pipeline'
on: [ push, pull_request ]
on: [ push ]
env:
DOCKER_CLI_VERSION: "19.03.1"
jobs:
@ -26,9 +26,8 @@ jobs:
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Install go dependencies
if: steps.unit-cache-go-dependencies.outputs.cache-hit != 'true'
@ -54,9 +53,8 @@ jobs:
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
key: ${{ runner.os }}-go-prod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-prod-
- name: Install dependencies
if: steps.package-cache-go-dependencies.outputs.cache-hit != 'true'
@ -70,8 +68,6 @@ jobs:
with:
version: latest
args: release --snapshot --skip-publish --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: docker images wagoodman/dive
@ -84,8 +80,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:
@ -101,9 +152,8 @@ jobs:
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
key: ${{ runner.os }}-go-prod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-prod-
- name: Install dependencies
if: steps.release-cache-go-dependencies.outputs.cache-hit != 'true'

View file

@ -40,6 +40,54 @@ 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:
chmod 755 ./dist/dive_linux_amd64/dive && \
./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 +113,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

View file

@ -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)

View file

@ -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: ""},
},