Skip to content

Commit

Permalink
docs: document Docker advanced setup
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jul 15, 2024
1 parent ae97cef commit d7033a6
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions doc/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,80 @@ kcov needs access the following system calls:
- [`personality`](https://linux.die.net/man/2/personality)

You may need to use `--security-opt seccomp=unconfined` as a docker run option to attach to processes.

## Copy into your image

You may want to copy kcov into your image to avoid building it.

```Dockerfile
# Copy kcov (use kcov/kcov:latest-alpine for Alpine based images)
COPY --from=kcov/kcov:latest /usr/local/bin/kcov* /usr/local/bin/
# If you need documentation
COPY --from=kcov/kcov:latest /usr/local/share/doc/kcov /usr/local/share/doc/kcov
```

### Python + bats example

```Dockerfile
# The base layer of your image
FROM python:3.11-slim-bookworm

# Install kcov run-time dependencies and bats.
RUN apt-get update && \
apt-get install --yes --no-install-suggests --no-install-recommends \
libbfd-dev \
libcurl4 \
libdw1 \
zlib1g \
bats \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy kcov (use kcov/kcov:latest-alpine for Alpine based images)
COPY --from=kcov/kcov:latest /usr/local/bin/kcov* /usr/local/bin/
COPY --from=kcov/kcov:latest /usr/local/share/doc/kcov /usr/local/share/doc/kcov

WORKDIR /code

CMD ["bats"]
```

#### Test it

##### `test.sh`

```sh
#!/usr/bin/env bats

source script.sh

@test "test outputNumber function" {
result="$( outputNumber )"
[ "$result" -eq 7 ]
}

@test "kcov version" {
kcov --version | grep -q -c -F "v"
[ "$?" -eq 0 ]
}
```

##### `script.sh`

```sh
outputNumber() {
echo 7
}
```

##### Run tests

```sh
# build our image
docker build ./ -t py-bats
# test the built image
docker run --rm -it -v $PWD:/code py-bats kcov --include-path=/code --dump-summary ./coverage bats ./test.sh
# See the coverage result in ./coverage
# Browse file:///tmp/kcov/coverage/index.html in your browser
```

0 comments on commit d7033a6

Please sign in to comment.