From 8328449c1ad1beec56bd08ebf18e254c82aa0715 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 25 Jan 2024 15:32:17 +0000 Subject: [PATCH] chore: Speed up docker builds a bit by reducing layer count. This is especially noticeable on local builds (less so on the github workers). --- .github/workflows/ci.yml | 9 +++++- .github/workflows/docker.yml | 7 ----- auto_tests/save_compatibility_test.c | 1 + other/DHT_bootstrap.c | 4 +++ .../{Dockerfile => autotools.Dockerfile} | 8 ++++- .../autotools.Dockerfile.dockerignore | 12 ++++++++ other/docker/autotools/run | 3 +- .../{Dockerfile => clang-tidy.Dockerfile} | 5 +++- other/docker/clang-tidy/run | 3 +- .../{Dockerfile => compcert.Dockerfile} | 10 ++----- other/docker/compcert/run | 3 +- .../{Dockerfile => coverage.Dockerfile} | 4 +-- .../{Dockerfile.nginx => nginx.Dockerfile} | 0 other/docker/coverage/run | 6 ++-- other/docker/coverage/serve | 8 +++-- other/docker/cppcheck/Dockerfile | 30 ------------------- other/docker/cppcheck/cppcheck.Dockerfile | 23 ++++++++++++++ other/docker/cppcheck/run | 3 +- .../{Dockerfile => doxygen.Dockerfile} | 9 +++--- other/docker/doxygen/run | 6 ++-- .../{Dockerfile => goblint.Dockerfile} | 9 ++---- other/docker/goblint/run | 3 +- .../infer/{Dockerfile => infer.Dockerfile} | 6 ++-- other/docker/infer/run | 3 +- other/docker/misra/Makefile | 7 ++++- .../misra/{Dockerfile => misra.Dockerfile} | 6 ++-- other/docker/misra/run | 3 +- other/docker/sources/Dockerfile | 17 ----------- other/docker/sources/build | 5 ++++ other/docker/sources/sources.Dockerfile | 2 ++ .../sources/sources.Dockerfile.dockerignore | 22 ++++++++++++++ other/docker/tcc/run | 3 +- .../docker/tcc/{Dockerfile => tcc.Dockerfile} | 8 ++--- other/docker/tokstyle/run | 3 +- .../{Dockerfile => tokstyle.Dockerfile} | 14 +++++---- 35 files changed, 152 insertions(+), 113 deletions(-) rename other/docker/autotools/{Dockerfile => autotools.Dockerfile} (72%) create mode 100644 other/docker/autotools/autotools.Dockerfile.dockerignore rename other/docker/clang-tidy/{Dockerfile => clang-tidy.Dockerfile} (62%) rename other/docker/compcert/{Dockerfile => compcert.Dockerfile} (56%) rename other/docker/coverage/{Dockerfile => coverage.Dockerfile} (97%) rename other/docker/coverage/{Dockerfile.nginx => nginx.Dockerfile} (100%) delete mode 100644 other/docker/cppcheck/Dockerfile create mode 100644 other/docker/cppcheck/cppcheck.Dockerfile rename other/docker/doxygen/{Dockerfile => doxygen.Dockerfile} (71%) rename other/docker/goblint/{Dockerfile => goblint.Dockerfile} (70%) rename other/docker/infer/{Dockerfile => infer.Dockerfile} (89%) rename other/docker/misra/{Dockerfile => misra.Dockerfile} (60%) delete mode 100644 other/docker/sources/Dockerfile create mode 100755 other/docker/sources/build create mode 100644 other/docker/sources/sources.Dockerfile create mode 100644 other/docker/sources/sources.Dockerfile.dockerignore rename other/docker/tcc/{Dockerfile => tcc.Dockerfile} (87%) rename other/docker/tokstyle/{Dockerfile => tokstyle.Dockerfile} (51%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4af25ba..a410c0b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,17 @@ jobs: steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + driver: docker + - 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: Docker Build uses: docker/build-push-action@v4 with: - file: other/docker/${{ matrix.tool }}/Dockerfile + file: other/docker/${{ matrix.tool }}/${{ matrix.tool }}.Dockerfile coverage-linux: runs-on: ubuntu-latest diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3779621d..4d6527c0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -121,19 +121,12 @@ jobs: steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - with: - driver: docker - name: Login to DockerHub if: ${{ github.event_name == 'push' }} uses: docker/login-action@v3 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/Dockerfile - tags: toxchat/c-toxcore:sources - name: Build and push uses: docker/build-push-action@v4 with: diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index 74d7b51a..aa440e00 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c @@ -135,6 +135,7 @@ static void test_save_compatibility(const char *save_path) tox_kill(tox); } +// cppcheck-suppress constParameter int main(int argc, char *argv[]) { char base_path[4096] = {0}; diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index a99f7010..0e9392c4 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -170,6 +170,7 @@ int main(int argc, char *argv[]) if (!(onion && forwarding && onion_a)) { printf("Something failed to initialize.\n"); + // cppcheck-suppress resourceLeak return 1; } @@ -178,6 +179,7 @@ int main(int argc, char *argv[]) perror("Initialization"); if (!manage_keys(dht)) { + // cppcheck-suppress resourceLeak return 1; } printf("Public key: "); @@ -189,6 +191,7 @@ int main(int argc, char *argv[]) if (tcp_s == nullptr) { printf("TCP server failed to initialize.\n"); + // cppcheck-suppress resourceLeak return 1; } @@ -199,6 +202,7 @@ int main(int argc, char *argv[]) if (file == nullptr) { printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename); + // cppcheck-suppress resourceLeak return 1; } diff --git a/other/docker/autotools/Dockerfile b/other/docker/autotools/autotools.Dockerfile similarity index 72% rename from other/docker/autotools/Dockerfile rename to other/docker/autotools/autotools.Dockerfile index fc85f505..bbe7357f 100644 --- a/other/docker/autotools/Dockerfile +++ b/other/docker/autotools/autotools.Dockerfile @@ -1,5 +1,6 @@ ################################################ # autotools-linux +FROM toxchat/c-toxcore:sources AS sources FROM ubuntu:22.04 RUN apt-get update && \ @@ -24,7 +25,12 @@ USER builder WORKDIR /home/builder -# Copy the sources and run the build. +# Copy autotools-specific build scripts not present in the sources image. +# These change less frequently than the sources, thus are copied first. COPY --chown=builder:builder . /home/builder/c-toxcore/ + +# Copy the sources and run the build. +COPY --chown=builder:builder --from=sources /src/ /home/builder/c-toxcore/ + WORKDIR /home/builder/c-toxcore RUN CC=gcc .github/scripts/autotools-linux diff --git a/other/docker/autotools/autotools.Dockerfile.dockerignore b/other/docker/autotools/autotools.Dockerfile.dockerignore new file mode 100644 index 00000000..ddd22a5f --- /dev/null +++ b/other/docker/autotools/autotools.Dockerfile.dockerignore @@ -0,0 +1,12 @@ +**/* +!.github/scripts/autotools-linux +!m4/* +!configure.ac +!*.pc.in +!*.spec.in +!**/Makefile.am +!**/Makefile.inc +!docs/updates/* +!other/DHTnodes +!other/astyle/* +!other/tox.png diff --git a/other/docker/autotools/run b/other/docker/autotools/run index aadb1440..300465b0 100755 --- a/other/docker/autotools/run +++ b/other/docker/autotools/run @@ -2,4 +2,5 @@ set -eux BUILD=autotools -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/clang-tidy/Dockerfile b/other/docker/clang-tidy/clang-tidy.Dockerfile similarity index 62% rename from other/docker/clang-tidy/Dockerfile rename to other/docker/clang-tidy/clang-tidy.Dockerfile index eaf23f98..986bb9c4 100644 --- a/other/docker/clang-tidy/Dockerfile +++ b/other/docker/clang-tidy/clang-tidy.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM alpine:3.19.0 RUN ["apk", "add", "--no-cache", \ @@ -16,6 +17,8 @@ RUN ["apk", "add", "--no-cache", \ ENV CC=clang CXX=clang++ -COPY . /c-toxcore/ +COPY --from=sources /src/ /c-toxcore/ +COPY other/analysis/run-clang-tidy other/analysis/variants.sh /c-toxcore/other/analysis/ +COPY .clang-tidy /c-toxcore/ WORKDIR /c-toxcore RUN other/analysis/run-clang-tidy diff --git a/other/docker/clang-tidy/run b/other/docker/clang-tidy/run index 62036edf..ab830de0 100755 --- a/other/docker/clang-tidy/run +++ b/other/docker/clang-tidy/run @@ -2,4 +2,5 @@ set -eux BUILD=clang-tidy -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/compcert/Dockerfile b/other/docker/compcert/compcert.Dockerfile similarity index 56% rename from other/docker/compcert/Dockerfile rename to other/docker/compcert/compcert.Dockerfile index d5542f6a..d8b193c8 100644 --- a/other/docker/compcert/Dockerfile +++ b/other/docker/compcert/compcert.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM toxchat/compcert:latest RUN apt-get update && \ @@ -8,15 +9,10 @@ RUN apt-get update && \ && rm -rf /var/lib/apt/lists/* WORKDIR /work -COPY auto_tests/ /work/auto_tests/ -COPY testing/ /work/testing/ -COPY toxav/ /work/toxav/ -COPY toxcore/ /work/toxcore/ -COPY toxencryptsave/ /work/toxencryptsave/ -COPY third_party/ /work/third_party/ +COPY --from=sources /src/ /work/ SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY other/docker/compcert/Makefile /work/ RUN make "-j$(nproc)" -RUN ./send_message_test #| grep 'tox clients connected' +RUN ./send_message_test | grep 'tox clients connected' diff --git a/other/docker/compcert/run b/other/docker/compcert/run index 8b03c84c..885f811a 100755 --- a/other/docker/compcert/run +++ b/other/docker/compcert/run @@ -2,4 +2,5 @@ set -eux BUILD=compcert -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/coverage/Dockerfile b/other/docker/coverage/coverage.Dockerfile similarity index 97% rename from other/docker/coverage/Dockerfile rename to other/docker/coverage/coverage.Dockerfile index 8a289869..8d6649af 100644 --- a/other/docker/coverage/Dockerfile +++ b/other/docker/coverage/coverage.Dockerfile @@ -1,4 +1,4 @@ -FROM toxchat/c-toxcore:sources AS src +FROM toxchat/c-toxcore:sources AS sources FROM ubuntu:20.04 AS build SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -41,7 +41,7 @@ ENV CC=clang-17 \ PYTHONUNBUFFERED=1 \ PATH=$PATH:/usr/lib/go-1.18/bin -COPY --from=src /src/ /work/ +COPY --from=sources /src/ /work/ WORKDIR /work RUN git clone --depth=1 https://github.com/TokTok/toktok-fuzzer /work/testing/fuzzing/toktok-fuzzer diff --git a/other/docker/coverage/Dockerfile.nginx b/other/docker/coverage/nginx.Dockerfile similarity index 100% rename from other/docker/coverage/Dockerfile.nginx rename to other/docker/coverage/nginx.Dockerfile diff --git a/other/docker/coverage/run b/other/docker/coverage/run index aea7603c..e4f51339 100755 --- a/other/docker/coverage/run +++ b/other/docker/coverage/run @@ -4,6 +4,8 @@ set -eux read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))" -docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . -docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile . +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 diff --git a/other/docker/coverage/serve b/other/docker/coverage/serve index 94a09d15..e5da11d5 100755 --- a/other/docker/coverage/serve +++ b/other/docker/coverage/serve @@ -2,7 +2,9 @@ set -eux -docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . -docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile . -docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/Dockerfile.nginx other/docker/coverage +BUILD=coverage +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . + +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 diff --git a/other/docker/cppcheck/Dockerfile b/other/docker/cppcheck/Dockerfile deleted file mode 100644 index 34b516fb..00000000 --- a/other/docker/cppcheck/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM alpine:3.19.0 - -RUN ["apk", "add", "--no-cache", \ - "bash", \ - "cppcheck", \ - "findutils", \ - "libconfig-dev", \ - "libsodium-dev", \ - "libvpx-dev", \ - "linux-headers", \ - "make", \ - "opus-dev"] - -COPY other/bootstrap_daemon/ /src/workspace/c-toxcore/other/bootstrap_daemon/ -COPY other/bootstrap_node_packets.* /src/workspace/c-toxcore/other/ -COPY other/fun/ /src/workspace/c-toxcore/other/fun/ -COPY auto_tests/check_compat.h /src/workspace/c-toxcore/auto_tests/ -COPY testing/ /src/workspace/c-toxcore/testing/ -COPY toxav/ /src/workspace/c-toxcore/toxav/ -COPY toxcore/ /src/workspace/c-toxcore/toxcore/ -COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/ -COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/ -COPY other/analysis/run-cppcheck \ - other/analysis/gen-file.sh \ - other/analysis/variants.sh \ - /src/workspace/c-toxcore/other/analysis/ -COPY other/docker/cppcheck/toxcore.cfg \ - /src/workspace/c-toxcore/other/docker/cppcheck/ -WORKDIR /src/workspace/c-toxcore -RUN ["other/analysis/run-cppcheck"] diff --git a/other/docker/cppcheck/cppcheck.Dockerfile b/other/docker/cppcheck/cppcheck.Dockerfile new file mode 100644 index 00000000..7bc800c0 --- /dev/null +++ b/other/docker/cppcheck/cppcheck.Dockerfile @@ -0,0 +1,23 @@ +FROM toxchat/c-toxcore:sources AS sources +FROM alpine:3.19.0 + +RUN ["apk", "add", "--no-cache", \ + "bash", \ + "cppcheck", \ + "findutils", \ + "libconfig-dev", \ + "libsodium-dev", \ + "libvpx-dev", \ + "linux-headers", \ + "make", \ + "opus-dev"] + +COPY --from=sources /src/ /src/workspace/c-toxcore/ +COPY other/analysis/run-cppcheck \ + other/analysis/gen-file.sh \ + other/analysis/variants.sh \ + /src/workspace/c-toxcore/other/analysis/ +COPY other/docker/cppcheck/toxcore.cfg \ + /src/workspace/c-toxcore/other/docker/cppcheck/ +WORKDIR /src/workspace/c-toxcore +RUN ["other/analysis/run-cppcheck"] diff --git a/other/docker/cppcheck/run b/other/docker/cppcheck/run index 8e437f4c..4cc18bac 100755 --- a/other/docker/cppcheck/run +++ b/other/docker/cppcheck/run @@ -2,4 +2,5 @@ set -eux BUILD=cppcheck -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/doxygen/Dockerfile b/other/docker/doxygen/doxygen.Dockerfile similarity index 71% rename from other/docker/doxygen/Dockerfile rename to other/docker/doxygen/doxygen.Dockerfile index e10c645d..09e80292 100644 --- a/other/docker/doxygen/Dockerfile +++ b/other/docker/doxygen/doxygen.Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:latest AS build +FROM toxchat/c-toxcore:sources AS sources +FROM alpine:3.19.0 AS build ENV LANG=en_US.UTF-8 \ LANGUAGE=en_US.UTF-8 \ @@ -8,9 +9,9 @@ ENV LANG=en_US.UTF-8 \ RUN apk add --no-cache doxygen git graphviz texlive \ && git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/doxygen-awesome-css WORKDIR /work -COPY . /work/ -RUN cat docs/Doxyfile > Doxyfile \ - && echo "WARN_AS_ERROR = YES" >> Doxyfile \ +COPY --from=sources /src/ /work/ +COPY docs/Doxyfile /work/Doxyfile +RUN echo "WARN_AS_ERROR = YES" >> Doxyfile \ && sed -i -e 's/^non_null([^)]*) *//;s/^nullable([^)]*) *//' $(find . -name "*.[ch]") \ && doxygen Doxyfile diff --git a/other/docker/doxygen/run b/other/docker/doxygen/run index c702ba5f..b7deb943 100755 --- a/other/docker/doxygen/run +++ b/other/docker/doxygen/run @@ -1,6 +1,8 @@ #!/bin/sh set -eux +BUILD=doxygen +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . -docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile . -docker run --name toxcore-docs --rm -it -p "28192:80" toxchat/c-toxcore:docs +docker run --name toxcore-doxygen --rm -it -p "28192:80" "toxchat/c-toxcore:$BUILD" diff --git a/other/docker/goblint/Dockerfile b/other/docker/goblint/goblint.Dockerfile similarity index 70% rename from other/docker/goblint/Dockerfile rename to other/docker/goblint/goblint.Dockerfile index ab27b4c8..eb627510 100644 --- a/other/docker/goblint/Dockerfile +++ b/other/docker/goblint/goblint.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM ghcr.io/goblint/analyzer:latest RUN apt-get update && \ @@ -8,15 +9,9 @@ RUN apt-get update && \ && rm -rf /var/lib/apt/lists/* WORKDIR /work -COPY auto_tests/ /work/auto_tests/ -COPY testing/ /work/testing/ -COPY toxav/ /work/toxav/ -COPY toxcore/ /work/toxcore/ -COPY toxencryptsave/ /work/toxencryptsave/ -COPY third_party/ /work/third_party/ +COPY --from=sources /src/ /work/ COPY other/make_single_file /work/other/ -COPY other/docker/goblint/sodium.c /work/other/docker/goblint/ RUN other/make_single_file -core auto_tests/tox_new_test.c other/docker/goblint/sodium.c > analysis.c # Try compiling+linking just to make sure we have all the fake functions. diff --git a/other/docker/goblint/run b/other/docker/goblint/run index 8b07193b..f2bbceea 100755 --- a/other/docker/goblint/run +++ b/other/docker/goblint/run @@ -2,4 +2,5 @@ set -eux BUILD=goblint -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/infer/Dockerfile b/other/docker/infer/infer.Dockerfile similarity index 89% rename from other/docker/infer/Dockerfile rename to other/docker/infer/infer.Dockerfile index b4f8ebb2..f7f4547b 100644 --- a/other/docker/infer/Dockerfile +++ b/other/docker/infer/infer.Dockerfile @@ -1,9 +1,7 @@ +FROM toxchat/c-toxcore:sources AS sources FROM toxchat/infer:latest -COPY toxav/ /work/c-toxcore/toxav/ -COPY toxcore/ /work/c-toxcore/toxcore/ -COPY toxencryptsave/ /work/c-toxcore/toxencryptsave/ -COPY third_party/ /work/c-toxcore/third_party/ +COPY --from=sources /src/ /work/c-toxcore/ RUN infer capture -- clang++ -fsyntax-only \ $(pkg-config --cflags libconfig libsodium opus vpx) \ /work/c-toxcore/toxav/*.c \ diff --git a/other/docker/infer/run b/other/docker/infer/run index ab1c021c..f605d140 100755 --- a/other/docker/infer/run +++ b/other/docker/infer/run @@ -2,4 +2,5 @@ set -eux BUILD=infer -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/misra/Makefile b/other/docker/misra/Makefile index edb1cb8f..9f6e32a3 100644 --- a/other/docker/misra/Makefile +++ b/other/docker/misra/Makefile @@ -155,7 +155,12 @@ SUPPRESSIONS += 21.10 CPPFLAGS := -DCMP_NO_FLOAT=1 -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE -SOURCES := $(shell find /src/workspace/c-toxcore -name "*.c") +FIND_FLAGS := -name "*.c" \ + -and -not -wholename "*/auto_tests/*" \ + -and -not -wholename "*/other/*" \ + -and -not -wholename "*/super_donators/*" \ + -and -not -wholename "*/third_party/*" +SOURCES := $(shell find /src/workspace/c-toxcore $(FIND_FLAGS)) analyse: $(DUMPS:.dump=.diag) cppcheck --error-exitcode=1 -j8 --addon=misra --suppress=doubleFree $(patsubst %,--suppress=misra-c2012-%,$(SUPPRESSIONS)) $(CPPFLAGS) $(SOURCES) diff --git a/other/docker/misra/Dockerfile b/other/docker/misra/misra.Dockerfile similarity index 60% rename from other/docker/misra/Dockerfile rename to other/docker/misra/misra.Dockerfile index d005b4c9..aa99a530 100644 --- a/other/docker/misra/Dockerfile +++ b/other/docker/misra/misra.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM ubuntu:20.04 RUN apt-get update && \ @@ -12,10 +13,7 @@ RUN apt-get update && \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -COPY toxav/ /src/workspace/c-toxcore/toxav/ -COPY toxcore/ /src/workspace/c-toxcore/toxcore/ -COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/ -COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/cmp.h +COPY --from=sources /src/ /src/workspace/c-toxcore/ COPY other/docker/misra/Makefile /src/workspace/ WORKDIR /src/workspace RUN ["make"] diff --git a/other/docker/misra/run b/other/docker/misra/run index 2f96bb4b..a2692a37 100755 --- a/other/docker/misra/run +++ b/other/docker/misra/run @@ -2,4 +2,5 @@ set -eux BUILD=misra -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/sources/Dockerfile b/other/docker/sources/Dockerfile deleted file mode 100644 index 73a3ea0b..00000000 --- a/other/docker/sources/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM scratch - -# Roughly in order of change frequency. -COPY third_party/ /src/third_party/ -COPY .github/scripts/flags*.sh /src/.github/scripts/ -COPY other/proxy/ /src/other/proxy/ -COPY cmake/ /src/cmake/ -COPY other/bootstrap_daemon/ /src/other/bootstrap_daemon/ -COPY other/pkgconfig/ /src/other/pkgconfig/ -COPY other/rpm/ /src/other/rpm/ -COPY other/*.[ch] /src/other/ -COPY CMakeLists.txt so.version /src/ -COPY toxencryptsave/ /src/toxencryptsave/ -COPY testing/ /src/testing/ -COPY toxav/ /src/toxav/ -COPY toxcore/ /src/toxcore/ -COPY auto_tests/ /src/auto_tests/ diff --git a/other/docker/sources/build b/other/docker/sources/build new file mode 100755 index 00000000..277936f6 --- /dev/null +++ b/other/docker/sources/build @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux +BUILD=sources +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/sources/sources.Dockerfile b/other/docker/sources/sources.Dockerfile new file mode 100644 index 00000000..c3008b42 --- /dev/null +++ b/other/docker/sources/sources.Dockerfile @@ -0,0 +1,2 @@ +FROM scratch +COPY . /src/ diff --git a/other/docker/sources/sources.Dockerfile.dockerignore b/other/docker/sources/sources.Dockerfile.dockerignore new file mode 100644 index 00000000..698f7a55 --- /dev/null +++ b/other/docker/sources/sources.Dockerfile.dockerignore @@ -0,0 +1,22 @@ +# 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 diff --git a/other/docker/tcc/run b/other/docker/tcc/run index 870852ba..63412b55 100755 --- a/other/docker/tcc/run +++ b/other/docker/tcc/run @@ -2,4 +2,5 @@ set -eux BUILD=tcc -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/tcc/Dockerfile b/other/docker/tcc/tcc.Dockerfile similarity index 87% rename from other/docker/tcc/Dockerfile rename to other/docker/tcc/tcc.Dockerfile index d1f10181..425256bc 100644 --- a/other/docker/tcc/Dockerfile +++ b/other/docker/tcc/tcc.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM ubuntu:22.04 RUN apt-get update && \ @@ -12,12 +13,7 @@ RUN apt-get update && \ && rm -rf /var/lib/apt/lists/* WORKDIR /work -COPY auto_tests/ /work/auto_tests/ -COPY testing/ /work/testing/ -COPY toxav/ /work/toxav/ -COPY toxcore/ /work/toxcore/ -COPY toxencryptsave/ /work/toxencryptsave/ -COPY third_party/ /work/third_party/ +COPY --from=sources /src/ /work/ SHELL ["/bin/bash", "-o", "pipefail", "-c"] diff --git a/other/docker/tokstyle/run b/other/docker/tokstyle/run index c743defd..1d92173d 100755 --- a/other/docker/tokstyle/run +++ b/other/docker/tokstyle/run @@ -2,4 +2,5 @@ set -eux BUILD=tokstyle -docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" . +other/docker/sources/build +docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . diff --git a/other/docker/tokstyle/Dockerfile b/other/docker/tokstyle/tokstyle.Dockerfile similarity index 51% rename from other/docker/tokstyle/Dockerfile rename to other/docker/tokstyle/tokstyle.Dockerfile index 3bb677b5..1cc0c2bc 100644 --- a/other/docker/tokstyle/Dockerfile +++ b/other/docker/tokstyle/tokstyle.Dockerfile @@ -1,3 +1,4 @@ +FROM toxchat/c-toxcore:sources AS sources FROM toxchat/haskell:hs-tokstyle AS tokstyle FROM ubuntu:22.04 @@ -15,8 +16,11 @@ RUN apt-get update && \ COPY --from=tokstyle /bin/check-c /bin/ RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/hs-tokstyle", "/src/workspace/hs-tokstyle"] -COPY toxav/ /src/workspace/c-toxcore/toxav/ -COPY toxcore/ /src/workspace/c-toxcore/toxcore/ -COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/ -COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/cmp.h -RUN /bin/check-c $(find /src/workspace/c-toxcore -name "*.c") +COPY --from=sources /src/ /src/workspace/c-toxcore/ +RUN /bin/check-c $(find /src/workspace/c-toxcore -name "*.c" \ + -and -not -wholename "*/auto_tests/*" \ + -and -not -wholename "*/other/*" \ + -and -not -wholename "*/super_donators/*" \ + -and -not -wholename "*/testing/*" \ + -and -not -wholename "*/third_party/cmp/examples/*" \ + -and -not -wholename "*/third_party/cmp/test/*")