-
Notifications
You must be signed in to change notification settings - Fork 1
/
yio
executable file
·84 lines (70 loc) · 2.51 KB
/
yio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# Wrapper build script for yioremote/remote-os-build Docker image
# https://github.com/YIO-Remote/documentation/wiki
# Symlink this script in /usr/local/bin to call it from anywhere
#
# Environment variables:
# Either define them in your shell environment (e.g. ~/.bash_profile or ~/.profile)
# or define them in your current shell: export YIO_BUILD_OUTPUT=/projects/yio/build-output
#
# Mandatory environment variables:
# - YIO_BUILD_OUTPUT: defines the mapped output directory for the binary artefacts.
#
# Optional environment variables:
# - YIO_BUILD_SOURCE: defines the mapped source directory of the projects.
# If not defined a Docker Volume named `yio-projects` will be used.
#
set -e
#YIO_BUILD_OUTPUT=/projects/yio/build-output
YIO_PROJECTS_SOURCE=yio-projects
YIO_DOCKER_IMG=yioremote/remote-os-build
# --- Helper functions ---
function checkDockerVolume() {
docker volume inspect $1 &> /dev/null || {
echo "Docker volume '$1' doesn't exist: creating it..."
docker volume create $1
}
}
# --- Script starts here ---
if [[ -z "${YIO_BUILD_OUTPUT}" ]]; then
echo "Environment variable YIO_BUILD_OUTPUT not defined!"
exit 1
fi
if [ ! -d ${YIO_BUILD_OUTPUT} ]; then
echo "Output directory defined in 'YIO_BUILD_OUTPUT' doesn't exist: '${YIO_BUILD_OUTPUT}'"
exit 1
fi
which docker &> /dev/null || {
echo "Docker not found in path"
exit 1
}
docker version &> /dev/null || {
echo "Docker is not running"
exit 1
}
if [ "$1" = "info" ]; then
echo "Using docker image : $YIO_DOCKER_IMG"
echo "Docker image version : `docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.version"}}' $YIO_DOCKER_IMG`"
echo "Storing build output in : $YIO_BUILD_OUTPUT"
fi
if [[ ! -z "${YIO_BUILD_SOURCE}" ]]; then
if [[ ! -d ${YIO_BUILD_SOURCE} ]]; then
echo "Source directory defined in 'YIO_BUILD_SOURCE' doesn't exist: '${YIO_BUILD_SOURCE}'"
exit 1
elif [ "$1" = "info" ]; then
echo "Mounting projects from host directory: ${YIO_BUILD_SOURCE}"
fi
YIO_PROJECTS_SOURCE="${YIO_BUILD_SOURCE}"
else
if [ "$1" = "info" ]; then
echo "Using Docker Volume for projects : ${YIO_PROJECTS_SOURCE}"
fi
checkDockerVolume ${YIO_PROJECTS_SOURCE}
fi
checkDockerVolume yio-buildroot
docker run --rm -it \
-v ${YIO_PROJECTS_SOURCE}:/yio-remote/src \
-v yio-buildroot:/yio-remote/buildroot \
-v ${YIO_BUILD_OUTPUT}:/yio-remote/target \
$YIO_DOCKER_IMG $@