Version v1.39 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

Container Structure Test

It’s common practice to validate built container images before deploying them to our cluster. To do this, Skaffold has an integrated testing phase between the build and deploy phases of the pipeline. Natively, Skaffold has support for running container-structure-tests on built images, which validate the structural integrity of container images. The container-structure-test binary must be installed to run these tests.

Structure tests are defined per image in the Skaffold config. Every time an artifact is rebuilt, Skaffold runs the associated structure tests on that image. If the tests fail, Skaffold will not continue on to the deploy stage. If frequent tests are prohibitive, long-running tests should be moved to a dedicated Skaffold profile. Users can opt out of running container structure tests by using the --skip-tests flag.

Example

This following example shows the test section from a skaffold.yaml. It instructs Skaffold to run all container structure tests in the structure-test folder relative to the Skaffold root directory:

test:
  - image: gcr.io/k8s-skaffold/skaffold-example
    structureTests:
      - './structure-test/*'

The files matched by the structureTests key are container-structure-test test configurations, such as:

schemaVersion: 2.0.0

fileExistenceTests:
  - name: 'no go binary'
    path: '/usr/bin/go'
    shouldExist: false

For a reference how to write container structure tests, see its documentation.

In order to restrict the executed structure tests, a profile section can override the file pattern:

profiles:
  - name: quickcheck
    test:
      - image: gcr.io/k8s-skaffold/skaffold-example
        structureTests:
          - './structure-test/profile_structure_test.yaml'

User can customize container-structure-test behavior by passing a list of configuration flags as a value of structureTestsArgs yaml property in skaffold.yaml, e.g.:

test:
  - image: gcr.io/k8s-skaffold/skaffold-example
    structureTests:
      - './structure-test/*'
    structureTestsArgs:
      - --driver=tar
      - -q
      - --no-color
      -  --test-report=TEST_REPORT_NAME

To execute the tests once, run skaffold test --profile quickcheck.