diff --git a/.github/workflows/setup/action.yaml b/.github/workflows/setup/action.yaml index a6c58aae08..e791e51ac2 100644 --- a/.github/workflows/setup/action.yaml +++ b/.github/workflows/setup/action.yaml @@ -1,6 +1,10 @@ name: 'openpilot env setup' inputs: + setup_docker_scons_cache: + description: 'Whether or not to build the scons-cache docker image' + required: false + default: 'false' git_lfs: description: 'Whether or not to pull the git lfs' required: false @@ -28,7 +32,14 @@ runs: restore-keys: | scons-${{ env.CACHE_COMMIT_DATE }}- scons- - + - id: setup-scons-cache-docker + name: Sets up a docker image with scons cache that can by mounted as a buildkit cache mount + shell: bash + if: ${{ inputs.setup_docker_scons_cache == 'true' }} + run: | + cp selfdrive/test/Dockerfile.scons_cache ~ + cd ~ + DOCKER_BUILDKIT=1 docker build -t scons-cache -f Dockerfile.scons_cache . # build our docker image - shell: bash run: eval ${{ env.BUILD }} diff --git a/.github/workflows/tools_tests.yaml b/.github/workflows/tools_tests.yaml index e0d471882f..b21f290880 100644 --- a/.github/workflows/tools_tests.yaml +++ b/.github/workflows/tools_tests.yaml @@ -58,10 +58,14 @@ jobs: with: submodules: true - uses: ./.github/workflows/setup + with: + setup_docker_scons_cache: true - name: Build base cl image run: eval "$BUILD_CL" - name: Build simulator image - run: DOCKER_BUILDKIT=1 docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $DOCKER_REGISTRY/$IMAGE_NAME:latest -t $DOCKER_REGISTRY/$IMAGE_NAME:latest -f tools/sim/Dockerfile.sim . + run: | + docker pull $DOCKER_REGISTRY/$IMAGE_NAME:latest + DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $DOCKER_REGISTRY/$IMAGE_NAME:latest -t $DOCKER_REGISTRY/$IMAGE_NAME:latest -f tools/sim/Dockerfile.sim . - name: Push to container registry if: github.ref == 'refs/heads/master' && github.repository == 'commaai/openpilot' run: | @@ -74,14 +78,15 @@ jobs: timeout-minutes: 45 env: BUILD: | - DOCKER_BUILDKIT=1 docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $DOCKER_REGISTRY/openpilot-docs-base:latest -t $DOCKER_REGISTRY/openpilot-docs-base:latest -f docs/docker/Dockerfile --target openpilot-docs-base . - DOCKER_BUILDKIT=1 docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $DOCKER_REGISTRY/openpilot-docs-base:latest --cache-from $DOCKER_REGISTRY/openpilot-docs:latest -t $DOCKER_REGISTRY/openpilot-docs:latest -f docs/docker/Dockerfile . + docker pull $DOCKER_REGISTRY/openpilot-docs:latest + DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $DOCKER_REGISTRY/openpilot-docs:latest -t $DOCKER_REGISTRY/openpilot-docs:latest -f docs/docker/Dockerfile . steps: - uses: actions/checkout@v3 with: submodules: true - uses: ./.github/workflows/setup with: + setup_docker_scons_cache: true git_lfs: false - name: Push docker container if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/openpilot' diff --git a/docs/docker/Dockerfile b/docs/docker/Dockerfile index 209fba010f..94ddd3c3ad 100644 --- a/docs/docker/Dockerfile +++ b/docs/docker/Dockerfile @@ -1,4 +1,6 @@ -FROM ghcr.io/commaai/openpilot-base:latest as openpilot-docs-base +FROM scons-cache as scons-cache + +FROM ghcr.io/commaai/openpilot-base:latest ENV PYTHONUNBUFFERED 1 @@ -29,7 +31,7 @@ COPY ./selfdrive ${OPENPILOT_PATH}/selfdrive COPY ./system ${OPENPILOT_PATH}/system COPY ./*.md ${OPENPILOT_PATH}/ -RUN scons -j$(nproc) +RUN --mount=type=bind,from=scons-cache,source=/tmp/scons_cache,target=/tmp/scons_cache,rw scons -j$(nproc) RUN apt update && apt install doxygen -y COPY ./docs ${OPENPILOT_PATH}/docs @@ -38,5 +40,5 @@ WORKDIR ${OPENPILOT_PATH}/docs RUN make html FROM nginx:1.21 -COPY --from=0 /home/batman/openpilot/build/docs/html /usr/share/nginx/html +COPY --from=1 /home/batman/openpilot/build/docs/html /usr/share/nginx/html COPY ./docs/docker/nginx.conf /etc/nginx/conf.d/default.conf diff --git a/selfdrive/test/Dockerfile.scons_cache b/selfdrive/test/Dockerfile.scons_cache new file mode 100644 index 0000000000..6e320d243c --- /dev/null +++ b/selfdrive/test/Dockerfile.scons_cache @@ -0,0 +1,3 @@ +FROM alpine:3 + +COPY ./scons_cache /tmp/scons_cache \ No newline at end of file diff --git a/tools/sim/Dockerfile.sim b/tools/sim/Dockerfile.sim index d312f34ecd..96630c9e6f 100644 --- a/tools/sim/Dockerfile.sim +++ b/tools/sim/Dockerfile.sim @@ -1,3 +1,5 @@ +FROM scons-cache as scons-cache + FROM ghcr.io/commaai/openpilot-base-cl:latest RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -29,6 +31,6 @@ COPY ./system $HOME/openpilot/system COPY ./tools $HOME/openpilot/tools WORKDIR $HOME/openpilot -RUN scons --cache-readonly -j12 +RUN --mount=type=bind,from=scons-cache,source=/tmp/scons_cache,target=/tmp/scons_cache,rw scons -j12 RUN python -c "from openpilot.selfdrive.test.helpers import set_params_enabled; set_params_enabled()"