diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml new file mode 100644 index 00000000000..01ad08fa7b5 --- /dev/null +++ b/.github/actions/docker-build/action.yaml @@ -0,0 +1,72 @@ +name: docker-build +description: "" + +inputs: + name: + description: "" + required: true + platform: + description: "" + required: true + cache-tag-suffix: + description: "" + required: true + build-args: + description: "" + required: true + +runs: + using: composite + steps: + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Install vcstool + run: | + sudo apt-get -y update + sudo apt-get -y install python3-pip + pip install --no-cache-dir vcstool + shell: bash + + - name: Run vcs import + run: | + mkdir src + vcs import src < autoware.repos + shell: bash + + - name: Cache + uses: actions/cache@v3 + id: cache + with: + path: | + root-ccache + key: cache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('autoware.repos') }} + restore-keys: | + cache-${{ inputs.platform }}-${{ inputs.name }}- + cache-${{ inputs.platform }}- + + - name: Inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + "root-ccache": "/root/.ccache" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Run docker build + uses: docker/build-push-action@v5 + with: + file: docker/Dockerfile + context: . + push: false + build-args: ${{ inputs.build-args }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ inputs.name }}-${{ inputs.platform }}-${{ inputs.cache-tag-suffix }} + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ inputs.name }}-${{ inputs.platform }}-${{ inputs.cache-tag-suffix }},mode=max diff --git a/.github/workflows/build-main-self-hosted.yaml b/.github/workflows/build-main-self-hosted.yaml index eb178be3c27..a93cc134485 100644 --- a/.github/workflows/build-main-self-hosted.yaml +++ b/.github/workflows/build-main-self-hosted.yaml @@ -4,13 +4,6 @@ on: schedule: - cron: 0 12 * * * workflow_dispatch: - inputs: - artifacts-destination: - type: choice - description: Built images will be saved as tarball - options: - - tarball - default: tarball jobs: load-env: @@ -46,9 +39,6 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Set git config uses: autowarefoundation/autoware-github-actions/set-git-config@v1 with: @@ -57,40 +47,17 @@ jobs: - name: Free disk space uses: ./.github/actions/free-disk-space - - name: Cache - uses: actions/cache@v3 - id: cache - with: - path: | - root-ccache - key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }} - restore-keys: | - cache-${{ matrix.platform }}-${{ matrix.name }}- - cache-${{ matrix.platform }}- - - name: inject cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.0 - with: - cache-map: | - { - "root-ccache": "/root/.ccache" - } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} - - name: Build 'Autoware' - uses: ./.github/actions/docker-build-and-push + uses: ./.github/actions/docker-build with: - bake-target: autoware + name: ${{ matrix.name }} + platform: ${{ matrix.platform }} + cache-tag-suffix: main build-args: | - *.platform=linux/${{ matrix.platform }} - *.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }} - *.args.BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }} - *.args.SETUP_ARGS=${{ matrix.setup-args }} - *.args.LIB_DIR=${{ matrix.lib_dir }} - *.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main - *.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main,mode=max - tag-suffix: ${{ matrix.additional-tag-suffix }}-${{ matrix.platform }} - tag-prefix: ${{ needs.load-env.outputs.rosdistro }} - allow-push: false + ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }} + BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }} + SETUP_ARGS=${{ matrix.setup-args }} + LIB_DIR=${{ matrix.lib_dir }} - name: Show disk space run: | diff --git a/.github/workflows/build-main.yaml b/.github/workflows/build-main.yaml index 76bf9d5b9dc..249402092e7 100644 --- a/.github/workflows/build-main.yaml +++ b/.github/workflows/build-main.yaml @@ -4,13 +4,6 @@ on: schedule: - cron: 0 12 * * * workflow_dispatch: - inputs: - artifacts-destination: - type: choice - description: Built images will be saved as tarball - options: - - tarball - default: tarball jobs: load-env: @@ -41,9 +34,6 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Set git config uses: autowarefoundation/autoware-github-actions/set-git-config@v1 with: @@ -52,40 +42,17 @@ jobs: - name: Free disk space uses: ./.github/actions/free-disk-space - - name: Cache - uses: actions/cache@v3 - id: cache - with: - path: | - root-ccache - key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }} - restore-keys: | - cache-${{ matrix.platform }}-${{ matrix.name }}- - cache-${{ matrix.platform }}- - - name: inject cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.0 - with: - cache-map: | - { - "root-ccache": "/root/.ccache" - } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} - - name: Build 'Autoware' - uses: ./.github/actions/docker-build-and-push + uses: ./.github/actions/docker-build with: - bake-target: autoware + name: ${{ matrix.name }} + platform: ${{ matrix.platform }} + cache-tag-suffix: main build-args: | - *.platform=linux/${{ matrix.platform }} - *.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }} - *.args.BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }} - *.args.SETUP_ARGS=${{ matrix.setup-args }} - *.args.LIB_DIR=${{ matrix.lib_dir }} - *.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main - *.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main,mode=max - tag-suffix: ${{ matrix.additional-tag-suffix }}-${{ matrix.platform }} - tag-prefix: ${{ needs.load-env.outputs.rosdistro }} - allow-push: false + ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }} + BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }} + SETUP_ARGS=${{ matrix.setup-args }} + LIB_DIR=${{ matrix.lib_dir }} - name: Show disk space run: | diff --git a/.github/workflows/docker-build-and-push-main-self-hosted.yaml b/.github/workflows/docker-build-and-push-main-self-hosted.yaml index 6af6d592294..374d5c29a82 100644 --- a/.github/workflows/docker-build-and-push-main-self-hosted.yaml +++ b/.github/workflows/docker-build-and-push-main-self-hosted.yaml @@ -69,9 +69,8 @@ jobs: - name: Free disk space uses: ./.github/actions/free-disk-space - - name: Cache - uses: actions/cache@v3 - id: cache + - name: Restore cache + uses: actions/cache/restore@v4 with: path: | root-ccache @@ -79,14 +78,15 @@ jobs: restore-keys: | cache-${{ matrix.platform }}-${{ matrix.name }}- cache-${{ matrix.platform }}- - - name: inject cache into docker + + - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.0 with: cache-map: | { "root-ccache": "/root/.ccache" } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} + skip-extraction: true - name: Build 'Autoware' uses: ./.github/actions/docker-build-and-push diff --git a/.github/workflows/docker-build-and-push-main.yaml b/.github/workflows/docker-build-and-push-main.yaml index 0703ffc3daa..69b27998f97 100644 --- a/.github/workflows/docker-build-and-push-main.yaml +++ b/.github/workflows/docker-build-and-push-main.yaml @@ -39,14 +39,14 @@ jobs: - cuda include: - name: no-cuda - base_image_env: base_image platform: amd64 + base_image_env: base_image lib_dir: x86_64 setup-args: --no-nvidia additional-tag-suffix: "" - name: cuda - base_image_env: base_image platform: amd64 + base_image_env: base_image lib_dir: x86_64 additional-tag-suffix: -cuda steps: @@ -64,9 +64,8 @@ jobs: - name: Free disk space uses: ./.github/actions/free-disk-space - - name: Cache - uses: actions/cache@v3 - id: cache + - name: Restore cache + uses: actions/cache/restore@v4 with: path: | root-ccache @@ -74,14 +73,15 @@ jobs: restore-keys: | cache-${{ matrix.platform }}-${{ matrix.name }}- cache-${{ matrix.platform }}- - - name: inject cache into docker + + - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.0 with: cache-map: | { "root-ccache": "/root/.ccache" } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} + skip-extraction: true - name: Build 'Autoware' uses: ./.github/actions/docker-build-and-push diff --git a/docker/Dockerfile b/docker/Dockerfile index 3a960776096..8ada18b521e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -65,7 +65,7 @@ FROM base as prebuilt SHELL ["/bin/bash", "-o", "pipefail", "-c"] ARG ROS_DISTRO ARG SETUP_ARGS -ENV CCACHE_DIR="/var/tmp/ccache" +ENV CCACHE_DIR="/root/.ccache" # cspell: ignore libcu libnv # Set up development environment