Skip to content

Commit

Permalink
Pull base image with build capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
hhenry01 committed Feb 26, 2023
1 parent a8987f5 commit 7ddd425
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/ubcsailbot/sailbot_workspace/dev:arm-support-updated
FROM ghcr.io/ubcsailbot/sailbot_workspace/dev:base-image-build-capable

# # Uncomment this section to install the apt packages used in the ROS 2 tutorials
# ENV DEBIAN_FRONTEND=noninteractive
Expand Down
11 changes: 9 additions & 2 deletions .devcontainer/base-dev/base-dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ FROM ghcr.io/ubcsailbot/sailbot_workspace/pre-base:ros_humble-ompl_4c86b2f as ba
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y \
clang \
cmake \
libboost-all-dev \
libprotobuf-dev \
protobuf-compiler \
python3-colcon-common-extensions \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
Expand Down Expand Up @@ -81,14 +86,16 @@ ARG ROS_WORKSPACE=/workspaces/sailbot_workspace
COPY update-bashrc.sh /sbin/update-bashrc
RUN chmod +x /sbin/update-bashrc ; chown ros /sbin/update-bashrc ; sync ; /bin/bash -c /sbin/update-bashrc ; rm /sbin/update-bashrc

# install clang, some clang tools, and protobuf for network systems
# install some clang tools and googletest for network systems
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y \
clang \
clang-tidy \
clangd \
clang-tidy \
cmake \
googletest \
libboost-all-dev \
libprotobuf-dev \
protobuf-compiler \
&& apt-get autoremove -y \
Expand Down
19 changes: 19 additions & 0 deletions .devcontainer/deployment_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Deployment Scripts

## start_container.sh

- [Default] Builds and runs the latest base docker image in sailbot_workspace
- [Optional] Run with a docker image ID as the first argument to run a specific image

```
./start_container.sh
./start_container.sh <IMAGE_ID>
```

## quick_build.sh

- Builds all Sailbot software code without checks that slow down the build like static analysis

```
./quick_build.sh
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# build without any extra linting or static analysis

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
HOST_WORKSPACE_ROOT="$SCRIPT_DIR/.."
HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.."

$HOST_WORKSPACE_ROOT/build.sh RelWithDebInfo OFF
$HOST_WORKSPACE_ROOT/build.sh RelWithDebInfo OFF OFF
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash
# Build and run the sailbot_workspace image without VSCode for deployment
# Run the sailbot_workspace image without VSCode for deployment
# Pulls and runs the latest base image by default
# (Optional) run this script with an image ID as the first argument to run a specific version of the image

IMAGE_ID=${1:-""}

IMAGE_NAME="sailbot_workspace"
BASE_IMAGE="ghcr.io/ubcsailbot/sailbot_workspace/base"
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
HOST_WORKSPACE_ROOT="$SCRIPT_DIR/.."
HOST_WORKSPACE_ROOT="$SCRIPT_DIR/../.."
DOCKERFILE_DIR="$HOST_WORKSPACE_ROOT/.devcontainer"
DOCKERFILE_PATH="$DOCKERFILE_DIR/Dockerfile"
DEVCONTAINER_PATH="$DOCKERFILE_DIR/devcontainer.json"
CONTAINER_WORKSPACE_PATH="/workspaces/sailbot_workspace"
# args to mount the repo inside the container
Expand All @@ -24,16 +26,25 @@ get_docker_run_args()

echo $DOCKER_RUN_ARGS # return args
}
# Parse the Dockerfile to get the latest image tag
get_latest_tag()
{
TAG=$(head -n1 $DOCKERFILE_PATH) # Get first line with the image source and tag
IFS=':' read -ra TAG <<< "$TAG" # Turn the string into an array
TAG=${TAG[1]} # Get the tag from the second element in the array

echo $TAG # return tag
}

DOCKER_RUN_ARGS=$(get_docker_run_args)

if [[ $IMAGE_ID == "" ]]
then
# Build IMAGE_NAME from dockerfile found in DOCKERFILE_DIR (does nothing if image is already built)
docker build -t $IMAGE_NAME $DOCKERFILE_DIR
# Run latest IMAGE_NAME in an interactive bash terminal
echo "Running: docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $IMAGE_NAME /bin/bash"
docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $IMAGE_NAME /bin/bash
TAG=$(get_latest_tag)
docker pull $BASE_IMAGE:$TAG
# Run latest base image in an interactive bash terminal
echo "Running: docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $BASE_IMAGE:$TAG /bin/bash"
docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $BASE_IMAGE:$TAG /bin/bash
else
echo "Running: docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $IMAGE_ID /bin/bash"
docker run -it $DOCKER_MNT_VOL_ARGS $DOCKER_RUN_ARGS $IMAGE_ID /bin/bash
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
// IMPORTANT: be careful with the general devcontainer.json properties
// https://containers.dev/implementors/json_reference/#general-properties
// sailbot_workspace/deployment_scripts/start_container.sh parses this file for "runArgs" to run the container,
// but if you use, for example, the "capAdd" JSON field then it will NOT be picked up by the script without changes
// This only applies to properties that correspond to a docker run argument
// Do not add any properties that correspond to a docker run argument
// https://docs.docker.com/engine/reference/commandline/run/#options
// sailbot_workspace/.devcontainer/deployment_scripts/start_container.sh parses this file for "runArgs" to run the
// container, but if you use, for example, the "capAdd" JSON field then it will NOT be picked up by the script
// without changes
{
"dockerFile": "Dockerfile",
"build": {
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ set -e
# Set the build type
BUILD_TYPE=${1:-RelWithDebInfo}
STATIC_ANALYSIS=${2:-ON}
UNIT_TEST=${3:-ON}
colcon build \
--merge-install \
--symlink-install \
--cmake-args "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSTATIC_ANALYSIS=$STATIC_ANALYSIS" "--no-warn-unused-cli"
--cmake-args "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSTATIC_ANALYSIS=$STATIC_ANALYSIS" "-DUNIT_TEST=$UNIT_TEST" "--no-warn-unused-cli"

# For Clangd
if [[ -f /workspaces/sailbot_workspace/build/compile_commands.json && ! -f /workspaces/sailbot_workspace/compile_commands.json ]]
Expand Down

0 comments on commit 7ddd425

Please sign in to comment.