Skip to content

Commit 0758c9e

Browse files
authored
Merge pull request #162 from LORD-MicroStrain/feature/docker_shell
Uses docker_shell instead of docker_build for more modular builds
2 parents 5dcb568 + 34694ea commit 0758c9e

File tree

4 files changed

+210
-156
lines changed

4 files changed

+210
-156
lines changed

.devcontainer/docker_build.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
################################################################################################################################################
4+
# The purpose of this script is to build a docker image which can build the MIP SDK for an os and arch
5+
################################################################################################################################################
6+
set -e
7+
8+
# Get some arguments from the user
9+
os="ubuntu"
10+
arch="amd64"
11+
while [[ $# -gt 0 ]]; do
12+
case $1 in
13+
--os)
14+
os="$2"
15+
shift # past argument
16+
shift # past value
17+
;;
18+
--arch)
19+
arch="$2"
20+
shift # past argument
21+
shift # past value
22+
;;
23+
--no-cache)
24+
no_cache="--no-cache"
25+
shift # past argument
26+
;;
27+
*)
28+
shift # past argument
29+
;;
30+
esac
31+
done
32+
33+
# Find the script directory
34+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
35+
project_dir="${script_dir}/.."
36+
dockerfile="${script_dir}/Dockerfile.${os}"
37+
image_name="microstrain/mipsdk_${os}_builder:${arch}"
38+
39+
# Build the docker image
40+
docker build \
41+
-t "${image_name}" \
42+
${no_cache} \
43+
--build-arg ARCH="${arch}" \
44+
--build-arg USER_ID="$(id -u)" \
45+
--build-arg GROUP_ID="$(id -g)" \
46+
-f "${dockerfile}" \
47+
"${project_dir}"

.devcontainer/docker_shell.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
################################################################################################################################################
4+
# The purpose of this script is to run an arbitrary shell command in the docker image built by docker_build_image.sh
5+
# This script requires you to have run the docker_build_image.sh script before running with the same os and arch parameters
6+
################################################################################################################################################
7+
set -e
8+
9+
# Get some arguments from the user
10+
os="ubuntu"
11+
arch="amd64"
12+
remaining_args=()
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--os)
16+
os="$2"
17+
shift # past argument
18+
shift # past value
19+
;;
20+
--arch)
21+
arch="$2"
22+
shift # past argument
23+
shift # past value
24+
;;
25+
*)
26+
remaining_args+=("$1")
27+
shift # past argument
28+
;;
29+
esac
30+
done
31+
32+
# If no arguments were passed, default to just running a shell
33+
if [[ ${#remaining_args[@]} -eq 0 ]]; then
34+
remaining_args=("/bin/bash")
35+
fi
36+
37+
# Find the script directory
38+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
39+
project_dir="${script_dir}/.."
40+
docker_project_dir="/home/microstrain/mipsdk"
41+
image_name="microstrain/mipsdk_${os}_builder:${arch}"
42+
43+
44+
# Different flags for run depending on if we are running in jenkins or not
45+
if [ "${ISHUDSONBUILD}" != "True" ]; then
46+
docker_it_flags="-it"
47+
fi
48+
49+
# Run a shell in the docker image
50+
docker run \
51+
--rm \
52+
${docker_it_flags} \
53+
--entrypoint="/bin/bash" \
54+
-v "${project_dir}:${docker_project_dir}" \
55+
-w "${docker_project_dir}" \
56+
--user="microstrain" \
57+
"${image_name}" -c "${remaining_args[@]}"

0 commit comments

Comments
 (0)