chore: Speed up docker builds a bit by reducing layer count.

This is especially noticeable on local builds (less so on the github
workers).
This commit is contained in:
iphydf 2024-01-25 15:32:17 +00:00
parent d6d67d56f3
commit 8328449c1a
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
35 changed files with 152 additions and 113 deletions

View File

@ -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

View File

@ -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:

View File

@ -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};

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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" .

View File

@ -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

View File

@ -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" .

View File

@ -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'

View File

@ -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" .

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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" .

View File

@ -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

View File

@ -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"

View File

@ -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.

View File

@ -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" .

View File

@ -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 \

View File

@ -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" .

View File

@ -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)

View File

@ -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"]

View File

@ -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" .

View File

@ -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/

5
other/docker/sources/build Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eux
BUILD=sources
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -0,0 +1,2 @@
FROM scratch
COPY . /src/

View File

@ -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

View File

@ -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" .

View File

@ -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"]

View File

@ -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" .

View File

@ -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/*")