diff --git a/.docker/Dockerfile.alpine b/.docker/Dockerfile.alpine index 730150228..f50b16a3b 100644 --- a/.docker/Dockerfile.alpine +++ b/.docker/Dockerfile.alpine @@ -11,7 +11,10 @@ RUN apk add --no-cache \ COPY . /code WORKDIR /code -RUN pipx install --pip-args="--no-cache-dir" . && \ +# Use cache mounts for pip to speed up dependency installation +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -33,5 +36,11 @@ RUN apk add --no-cache \ pipx \ sudo RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/root/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.docker/Dockerfile.arch b/.docker/Dockerfile.arch index 03d35ba34..ab7795e76 100644 --- a/.docker/Dockerfile.arch +++ b/.docker/Dockerfile.arch @@ -26,7 +26,10 @@ RUN pacman -Syu --noconfirm && \ wget COPY . /code WORKDIR /code -RUN pipx install . && \ +# Use cache mounts for pip and pipx to speed up dependency installation +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -34,5 +37,11 @@ RUN pipx install . && \ secator install addons redis && \ secator install addons dev RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/root/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.docker/Dockerfile.debian b/.docker/Dockerfile.debian index 44e8329cd..faa5d70f4 100644 --- a/.docker/Dockerfile.debian +++ b/.docker/Dockerfile.debian @@ -27,7 +27,10 @@ RUN apt update -y && \ wget COPY . /code WORKDIR /code -RUN pipx install . && \ +# Use cache mounts for pip and pipx to speed up dependency installation +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -36,5 +39,11 @@ RUN pipx install . && \ secator install addons dev RUN secator install langs go RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/root/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.docker/Dockerfile.kali b/.docker/Dockerfile.kali index e4a7265ef..4260467e0 100644 --- a/.docker/Dockerfile.kali +++ b/.docker/Dockerfile.kali @@ -27,7 +27,10 @@ RUN apt update -y && \ wget COPY . /code WORKDIR /code -RUN pipx install . && \ +# Use cache mounts for pip and pipx to speed up dependency installation +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -35,5 +38,11 @@ RUN pipx install . && \ secator install addons redis && \ secator install addons dev RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/root/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.docker/Dockerfile.osx b/.docker/Dockerfile.osx index 58b6193f4..2a675a493 100644 --- a/.docker/Dockerfile.osx +++ b/.docker/Dockerfile.osx @@ -30,7 +30,10 @@ RUN sudo pacman -Syu --noconfirm && \ COPY . /code WORKDIR /code USER arch -RUN pipx install . && \ +# Use cache mounts for pip and pipx to speed up dependency installation +RUN --mount=type=cache,target=/home/arch/.cache/pip \ + --mount=type=cache,target=/home/arch/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -38,5 +41,11 @@ RUN pipx install . && \ secator install addons redis && \ secator install addons dev RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/home/arch/.cache/pip \ + --mount=type=cache,target=/home/arch/.cache/go-build \ + --mount=type=cache,target=/home/arch/go/pkg/mod \ + --mount=type=cache,target=/home/arch/.cargo/registry \ + --mount=type=cache,target=/home/arch/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.docker/Dockerfile.ubuntu b/.docker/Dockerfile.ubuntu index ce9e246ca..826f99c85 100644 --- a/.docker/Dockerfile.ubuntu +++ b/.docker/Dockerfile.ubuntu @@ -28,7 +28,10 @@ RUN apt update -y && \ COPY . /code WORKDIR /code RUN . scripts/install_go.sh -RUN pipx install . && \ +# Use cache mounts for pip and pipx to speed up dependency installation +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/pipx \ + pipx install . && \ secator install addons worker && \ secator install addons gdrive && \ secator install addons gcs && \ @@ -36,5 +39,11 @@ RUN pipx install . && \ secator install addons redis && \ secator install addons dev RUN if [ "$build_from_source" = "true" ]; then secator config set security.force_source_install 1; fi -RUN if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi +# Use cache mounts for tool installation directories to speed up builds +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + --mount=type=cache,target=/root/.cargo/registry \ + --mount=type=cache,target=/root/.cargo/git \ + if [ "$flavor" != "lite" ]; then secator install tools --cleanup --fail-fast; fi ENTRYPOINT ["secator"] diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 925d80826..13cc2e32b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -38,7 +38,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build Docker image - run: "docker build -t freelabz/secator:${{ matrix.distribution }} -f .docker/Dockerfile.${{ matrix.distribution }} ." + run: "DOCKER_BUILDKIT=1 docker build -t freelabz/secator:${{ matrix.distribution }} -f .docker/Dockerfile.${{ matrix.distribution }} ." - name: Run secator health check (strict) run: docker run --privileged freelabz/secator:${{ matrix.distribution }} health --strict diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c7d4b766..ad583178e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -69,10 +69,10 @@ jobs: run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - name: Build Docker image (full) - run: docker build -t freelabz/secator:${VERSION} . + run: DOCKER_BUILDKIT=1 docker build -t freelabz/secator:${VERSION} . - name: Build Docker image (lite) - run: docker build -t freelabz/secator:${VERSION}-lite --build-arg flavor=lite . + run: DOCKER_BUILDKIT=1 docker build -t freelabz/secator:${VERSION}-lite --build-arg flavor=lite . - name: Tag image with 'latest' run: docker tag freelabz/secator:${VERSION} freelabz/secator:latest diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 6d4fe470b..734b16797 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -3,6 +3,8 @@ steps: entrypoint: 'bash' args: ['-c', 'docker pull ${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/secator:${_VERSION} || exit 0'] - name: 'gcr.io/cloud-builders/docker' + env: + - 'DOCKER_BUILDKIT=1' args: ['build', '-t', '${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/secator:${_VERSION}', '--build-arg', 'flavor=${_FLAVOR}', '--cache-from', '${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/secator:${_VERSION}', '.'] substitutions: