Skip to content

Commit

Permalink
chore: Simplify coverage dockerfile.
Browse files Browse the repository at this point in the history
Use per-dockerfile dockerignore instead of sources for coverage. It's a
bit more duplication (dockerignore is copied out of the sources one),
but it's a bit more efficient and works in more situations (e.g. one
where you can only build 1 dockerfile such as on render.com).
  • Loading branch information
iphydf committed Feb 11, 2024
1 parent 8201019 commit a6518b4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/post-submit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build toxchat/c-toxcore:sources
uses: docker/build-push-action@v4
with:
file: other/docker/sources/sources.Dockerfile
tags: toxchat/c-toxcore:sources
- name: Build and push
uses: docker/build-push-action@v4
with:
Expand Down
8 changes: 3 additions & 5 deletions other/docker/coverage/coverage.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:20.04 AS build

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand Down Expand Up @@ -41,10 +40,10 @@ ENV CC=clang-17 \
PYTHONUNBUFFERED=1 \
PATH=$PATH:/usr/lib/go-1.18/bin

COPY --from=sources /src/ /work/
COPY . /work/

WORKDIR /work
RUN git clone --depth=1 https://github.com/TokTok/toktok-fuzzer /work/testing/fuzzing/toktok-fuzzer
RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/toktok-fuzzer", "/work/testing/fuzzing/toktok-fuzzer"]
RUN source .github/scripts/flags-coverage.sh \
&& go version \
&& (cd other/proxy && go get github.com/things-go/go-socks5 && go build proxy_server.go) \
Expand Down Expand Up @@ -76,8 +75,7 @@ RUN clang-17 -fuse-ld=lld -fPIC -shared -O2 -g3 -Wall -I/usr/lib/llvm-17/include
&& install mallocfail.so /usr/local/lib/mallocfail.so

WORKDIR /work/_build
COPY other/docker/coverage/run_mallocfail /usr/local/bin/
RUN ["run_mallocfail", "--ctest=1", "--jobs=8"]
RUN ["/work/other/docker/coverage/run_mallocfail", "--ctest=1", "--jobs=8"]
RUN llvm-profdata-17 merge -sparse $(find . -name "*.profraw") -o toxcore.profdata
RUN llvm-cov-17 show -format=text -instr-profile=toxcore.profdata -sources $(cmake --build . --target help | grep -o '[^:]*_test:' | grep -o '[^:]*' | xargs -n1 find . -type f -name | awk '{print "-object "$1}') > coverage.txt
RUN llvm-cov-17 show -format=html -instr-profile=toxcore.profdata -sources $(cmake --build . --target help | grep -o '[^:]*_test:' | grep -o '[^:]*' | xargs -n1 find . -type f -name | awk '{print "-object "$1}') -output-dir=html
Expand Down
25 changes: 25 additions & 0 deletions other/docker/coverage/coverage.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ===== common =====
# Ignore everything ...
**/*
# ... except sources
!**/*.[ch]
!**/*.cc
!**/*.hh
!CHANGELOG.md
!LICENSE
!README.md
!auto_tests/data/*
!other/bootstrap_daemon/bash-completion/**
!other/bootstrap_daemon/tox-bootstrapd.*
!other/proxy/*.mod
!other/proxy/*.sum
!other/proxy/*.go
# ... and CMake build files (used by most builds).
!**/CMakeLists.txt
!.github/scripts/flags*.sh
!cmake/*.cmake
!other/pkgconfig/*
!other/rpm/*
!so.version
# ===== custom =====
!other/docker/coverage/run_mallocfail
2 changes: 2 additions & 0 deletions other/docker/coverage/dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ===== custom =====
!other/docker/coverage/run_mallocfail
7 changes: 2 additions & 5 deletions other/docker/coverage/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ set -eux

read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))"

BUILD=coverage
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov
. "$(realpath -- "${BASH_SOURCE[0]}/../../sources/run.sh")"
docker run "${ci_env[@]}" -e CI=true --name "toxcore-$BUILD" --rm -t "toxchat/c-toxcore:$BUILD" /usr/local/bin/codecov
8 changes: 3 additions & 5 deletions other/docker/coverage/serve
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

set -eux

BUILD=coverage
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .
. "$(realpath -- "${BASH_SOURCE[0]}/../../sources/run.sh")"

docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/nginx.Dockerfile other/docker/coverage
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage-nginx
docker build -t "toxchat/c-toxcore:$BUILD-nginx" -f "$DOCKERDIR/nginx.Dockerfile" "$DOCKERDIR"
docker run --name "toxcore-$BUILD" --rm -it -p "28192:80" "toxchat/c-toxcore:$BUILD-nginx"
2 changes: 1 addition & 1 deletion other/docker/doxygen/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"
. "$(realpath -- "${BASH_SOURCE[0]}/../../sources/run.sh")"
docker run --name toxcore-doxygen --rm -it -p "28192:80" "toxchat/c-toxcore:$BUILD"

0 comments on commit a6518b4

Please sign in to comment.