Skip to content

Commit

Permalink
feat: Use docker build cache when running docker compose build
Browse files Browse the repository at this point in the history
  • Loading branch information
j3soon committed Dec 15, 2024
1 parent 7e9aa51 commit adf7444
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 3 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,40 @@ mkdocs serve
# Go to https://127.0.0.1:8000 to view the site.
```

## Link Documentation to ROS2 Workspaces
### Link Documentation to ROS2 Workspaces

```sh
scripts/setup_link.sh
```

## Reusing Docker Build Cache

The default (`docker`) build driver does not support pulling pre-built build cache from Docker Hub. Changing to the `docker-container` build driver allow reusing build cache from Docker Hub, however may introduce a few minute overhead after building any image (for sending tarballs). This is a tradeoff you should consider.

The default `docker` build driver cannot pull pre-built caches from Docker Hub. Using the `docker-container` driver [enables cache reuse](https://docs.docker.com/build/builders/drivers/) but may add [a few minutes of overhead](https://github.com/docker/buildx/issues/107) for sending tarballs after the build. You should consider this tradeoff if you choose to switch the build driver.

### Switching to `docker-container` Build Driver

```sh
# Install buildx as `docker build` alias
docker buildx install
# Create and use new builder
docker buildx create --name docker-container --driver docker-container --driver-opt default-load=true --use
```

After setting this, using `docker compose build` will use the build cache from Docker Hub. If you want to switch back to the default `docker` build driver, follow the instructions below.

### Switching back to `docker` Build Driver

```sh
# Uninstall buildx as `docker build` alias
docker buildx uninstall
# Unuse the created builder and remove it
docker buildx use default
docker buildx stop docker-container
docker buildx rm -f --all-inactive
```

## Acknowledgement

The code is mainly contributed by [Johnson](https://github.com/j3soon), [Yu-Zhong Chen](https://github.com/YuZhong-Chen), [Assume Zhan](https://github.com/Assume-Zhan), [Lam Chon Hang](https://github.com/ClassLongJoe1112), and others. For a full list of contributors, please refer to the [contribution list](https://github.com/j3soon/ros2-essentials/graphs/contributors).
Expand Down
3 changes: 3 additions & 0 deletions aloha_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-aloha-ws:buildcache-amd64
- j3soon/ros2-aloha-ws:buildcache-arm64
image: j3soon/ros2-aloha-ws
container_name: ros2-aloha-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions cartographer_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-cartographer-ws:buildcache-amd64
- j3soon/ros2-cartographer-ws:buildcache-arm64
image: j3soon/ros2-cartographer-ws
container_name: ros2-cartographer-ws
stdin_open: true
Expand Down
30 changes: 29 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,40 @@ mkdocs serve
# Go to https://127.0.0.1:8000 to view the site.
```

## Link Documentation to ROS2 Workspaces
### Link Documentation to ROS2 Workspaces

```sh
scripts/setup_link.sh
```

## Reusing Docker Build Cache

The default (`docker`) build driver does not support pulling pre-built build cache from Docker Hub. Changing to the `docker-container` build driver allow reusing build cache from Docker Hub, however may introduce a few minute overhead after building any image (for sending tarballs). This is a tradeoff you should consider.

The default `docker` build driver cannot pull pre-built caches from Docker Hub. Using the `docker-container` driver [enables cache reuse](https://docs.docker.com/build/builders/drivers/) but may add [a few minutes of overhead](https://github.com/docker/buildx/issues/107) for sending tarballs after the build. You should consider this tradeoff if you choose to switch the build driver.

### Switching to `docker-container` Build Driver

```sh
# Install buildx as `docker build` alias
docker buildx install
# Create and use new builder
docker buildx create --name docker-container --driver docker-container --driver-opt default-load=true --use
```

After setting this, using `docker compose build` will use the build cache from Docker Hub. If you want to switch back to the default `docker` build driver, follow the instructions below.

### Switching back to `docker` Build Driver

```sh
# Uninstall buildx as `docker build` alias
docker buildx uninstall
# Unuse the created builder and remove it
docker buildx use default
docker buildx stop docker-container
docker buildx rm -f --all-inactive
```

## Acknowledgement

The code is mainly contributed by [Johnson](https://github.com/j3soon), [Yu-Zhong Chen](https://github.com/YuZhong-Chen), [Assume Zhan](https://github.com/Assume-Zhan), [Lam Chon Hang](https://github.com/ClassLongJoe1112), and others. For a full list of contributors, please refer to the [contribution list](https://github.com/j3soon/ros2-essentials/graphs/contributors).
Expand Down
3 changes: 3 additions & 0 deletions gazebo_world_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-gazebo-world-ws:buildcache-amd64
- j3soon/ros2-gazebo-world-ws:buildcache-arm64
image: j3soon/ros2-gazebo-world-ws
container_name: ros2-gazebo-world-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions husky_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-husky-ws:buildcache-amd64
- j3soon/ros2-husky-ws:buildcache-arm64
image: j3soon/ros2-husky-ws
container_name: ros2-husky-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions kobuki_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-kobuki-ws:buildcache-amd64
- j3soon/ros2-kobuki-ws:buildcache-arm64
image: j3soon/ros2-kobuki-ws
container_name: ros2-kobuki-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions orbslam3_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-orbslam3-ws:buildcache-amd64
- j3soon/ros2-orbslam3-ws:buildcache-arm64
image: j3soon/ros2-orbslam3-ws
container_name: ros2-orbslam3-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions rtabmap_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-rtabmap-ws:buildcache-amd64
- j3soon/ros2-rtabmap-ws:buildcache-arm64
image: j3soon/ros2-rtabmap-ws
container_name: ros2-rtabmap-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions template_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-template-ws:buildcache-amd64
- j3soon/ros2-template-ws:buildcache-arm64
image: j3soon/ros2-template-ws
container_name: ros2-template-ws
stdin_open: true
Expand Down
3 changes: 3 additions & 0 deletions tests/diff_base/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-{PLACEHOLDER}-ws:buildcache-amd64
- j3soon/ros2-{PLACEHOLDER}-ws:buildcache-arm64
image: j3soon/ros2-{PLACEHOLDER}-ws
container_name: ros2-{PLACEHOLDER}-ws
stdin_open: true
Expand Down
2 changes: 1 addition & 1 deletion tests/lint_comp_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ def error(msg, i):
compare_file_with_template(".gitignore")
compare_file_with_template("docker/.bashrc")
compare_file_with_template("docker/.dockerignore", ignored_workspaces=["ros1_bridge_ws"])
compare_file_with_template("docker/compose.yaml", ignored_workspaces=["ros1_bridge_ws"])
compare_file_with_template("docker/compose.yaml", ignored_workspaces=["ros1_bridge_ws", "jazzy_template_ws"])
compare_file_with_template("docker/Dockerfile", ignored_workspaces=["ros1_bridge_ws", "jazzy_template_ws"])
compare_file_with_template("README.md")
3 changes: 3 additions & 0 deletions vlp_ws/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
# Reference: https://docs.docker.com/compose/compose-file/build/#platforms
# platforms:
# - "linux/arm64"
cache_from:
- j3soon/ros2-vlp-ws:buildcache-amd64
- j3soon/ros2-vlp-ws:buildcache-arm64
image: j3soon/ros2-vlp-ws
container_name: ros2-vlp-ws
stdin_open: true
Expand Down

0 comments on commit adf7444

Please sign in to comment.