cardboardci/bats
cardboardci/bats is a Docker image built with continuous integration builds in mind. Each tag contains any binaries and tools that are required for builds to complete successfully in a continuous integration environment. This includes jq
, curl
, bash
and utilities for orchestrating Bash testing.
Bats is a TAP-compliant testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected.
A Bats test file is a Bash script with special syntax for defining test cases. Under the hood, each test case is just a function with a description.
#!/usr/bin/env bats
@test "addition using bc" {
result="$(echo 2+2 | bc)"
[ "$result" -eq 4 ]
}
@test "addition using dc" {
result="$(echo 2 2+p | dc)"
[ "$result" -eq 4 ]
}
You can see the source repository here.
Getting Started
This image can be used with the docker type for different types of continuous integration platforms. For example:
# GitHub Actions
jobs:
my_first_job:
steps:
- name: My first step
uses: docker://ghcr.io/cardboardci/bats:edge
with:
args: "bats --version"
Pull latest image
The edge or latest version of the image is available with the tag edge
. This isn't intended to long term use, but for working with the latest version of the image. To pull the latest image, run the following:
docker pull ghcr.io/cardboardci/bats:edge
Test interactively
Sometimes it can be useful to run the image in an interactive shell for experimentation. To shell into an image, run the following:
docker run -it ghcr.io/cardboardci/bats:edge /bin/bash
Run a basic command
To run a single command from the context of the docker image, run the following:
docker run -it -v `pwd`:/workspace ghcr.io/cardboardci/bats:edge bats --version
Fundamentals
All images in the CardboardCI namespace are built from cardboardci/base. This image is intended to provide a common set of dependencies and expectations about how the images will behave. The image will always be built from the base image, to ensure any changes seen in the base are included in the downstream image.