From 71cd8de13ead642d7d4b9ed65d3f9f8cb2001efa Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 11 Feb 2024 16:29:28 +0000 Subject: [PATCH] chore: Simplify coverage dockerfile. 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). --- .github/workflows/post-submit.yml | 5 ---- other/docker/coverage/coverage.Dockerfile | 8 +++--- .../coverage/coverage.Dockerfile.dockerignore | 25 +++++++++++++++++++ other/docker/coverage/dockerignore | 2 ++ other/docker/coverage/run | 7 ++---- other/docker/coverage/serve | 8 +++--- other/docker/doxygen/run | 2 +- 7 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 other/docker/coverage/coverage.Dockerfile.dockerignore create mode 100644 other/docker/coverage/dockerignore diff --git a/.github/workflows/post-submit.yml b/.github/workflows/post-submit.yml index 540829e42f..84a77a2dda 100644 --- a/.github/workflows/post-submit.yml +++ b/.github/workflows/post-submit.yml @@ -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: diff --git a/other/docker/coverage/coverage.Dockerfile b/other/docker/coverage/coverage.Dockerfile index 8d6649af66..ae99c3661f 100644 --- a/other/docker/coverage/coverage.Dockerfile +++ b/other/docker/coverage/coverage.Dockerfile @@ -1,4 +1,3 @@ -FROM toxchat/c-toxcore:sources AS sources FROM ubuntu:20.04 AS build SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -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) \ @@ -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 diff --git a/other/docker/coverage/coverage.Dockerfile.dockerignore b/other/docker/coverage/coverage.Dockerfile.dockerignore new file mode 100644 index 0000000000..4741f66a51 --- /dev/null +++ b/other/docker/coverage/coverage.Dockerfile.dockerignore @@ -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 diff --git a/other/docker/coverage/dockerignore b/other/docker/coverage/dockerignore new file mode 100644 index 0000000000..f539d447d2 --- /dev/null +++ b/other/docker/coverage/dockerignore @@ -0,0 +1,2 @@ +# ===== custom ===== +!other/docker/coverage/run_mallocfail diff --git a/other/docker/coverage/run b/other/docker/coverage/run index e4f5133914..920b367bb2 100755 --- a/other/docker/coverage/run +++ b/other/docker/coverage/run @@ -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 -- "$(dirname "${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 diff --git a/other/docker/coverage/serve b/other/docker/coverage/serve index e5da11d5ff..df9a9eab72 100755 --- a/other/docker/coverage/serve +++ b/other/docker/coverage/serve @@ -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 -- "$(dirname "${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" diff --git a/other/docker/doxygen/run b/other/docker/doxygen/run index 2c038325e2..8ce6499f3b 100755 --- a/other/docker/doxygen/run +++ b/other/docker/doxygen/run @@ -1,4 +1,4 @@ #!/usr/bin/env bash -. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh" +. "$(realpath -- "$(dirname "${BASH_SOURCE[0]}")/../sources/run.sh")" docker run --name toxcore-doxygen --rm -it -p "28192:80" "toxchat/c-toxcore:$BUILD"