Skip to content

Commit

Permalink
refactor: refactor Docker build script (autowarefoundation#2704)
Browse files Browse the repository at this point in the history
Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
  • Loading branch information
kenji-miyake authored Jul 4, 2022
1 parent 7f36827 commit 244cb86
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
13 changes: 13 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ cd autoware/
./docker/build.sh
```

To build without CUDA, use the `--no-cuda` option:

```bash
./docker/build.sh --no-cuda
```

To specify the platform, use the `--platform` option:

```bash
./docker/build.sh --platform linux/amd64
./docker/build.sh --platform linux/arm64
```

## Tips

### Precautions for not using `rocker`
Expand Down
48 changes: 38 additions & 10 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,41 @@ set -e
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
WORKSPACE_ROOT="$SCRIPT_DIR/../"

# Set default platform
platform="linux/amd64"
if [ "$(uname -m)" = "aarch64" ]; then
platform="linux/arm64"
# Parse arguments
args=()
while [ "$1" != "" ]; do
case "$1" in
--no-cuda)
option_no_cuda=true
;;
--platform)
option_platform="$2"
shift
;;
*)
args+=("$1")
;;
esac
shift
done

# Set CUDA options
if [ "$option_no_cuda" = "true" ]; then
setup_args="--no-nvidia"
image_name_suffix=""
else
setup_args="--no-cuda-drivers"
image_name_suffix="-cuda"
fi

# Override platform by arg
if [ "$1" = "amd64" ] || [ "$1" = "arm64" ]; then
platform="linux/$1"
# Set platform
if [ -n "$option_platform" ]; then
platform="$option_platform"
else
platform="linux/amd64"
if [ "$(uname -m)" = "aarch64" ]; then
platform="linux/arm64"
fi
fi

# Load env
Expand All @@ -25,12 +51,14 @@ fi
# https://github.com/docker/buildx/issues/484
export BUILDKIT_STEP_LOG_MAX_SIZE=10000000

set -x
docker buildx bake --load --progress=plain -f "$SCRIPT_DIR/autoware-universe/docker-bake.hcl" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$rosdistro" \
--set "*.args.BASE_IMAGE=$base_image" \
--set "*.args.SETUP_ARGS=--no-cuda-drivers" \
--set "devel.tags=ghcr.io/autowarefoundation/autoware-universe:$rosdistro-latest" \
--set "prebuilt.tags=ghcr.io/autowarefoundation/autoware-universe:$rosdistro-latest-prebuilt"
--set "*.args.SETUP_ARGS=$setup_args" \
--set "devel.tags=ghcr.io/autowarefoundation/autoware-universe:$rosdistro-latest$image_name_suffix" \
--set "prebuilt.tags=ghcr.io/autowarefoundation/autoware-universe:$rosdistro-latest-prebuilt$image_name_suffix"
set +x

0 comments on commit 244cb86

Please sign in to comment.