This repository has been archived by the owner on Jul 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
executable file
·119 lines (96 loc) · 3.15 KB
/
docker.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# Author: Michal Svorc <michalsvorc.com>
# Description: Docker commands helper script
#===============================================================================
# Script options
#===============================================================================
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# set -o xtrace # debugging
#===============================================================================
# Variables
#===============================================================================
# Docker arguments
application_name='react-native'
image_name="michalsvorc/${application_name}"
android_sdk_version='29'
android_build_tools_version='29.0.2'
nodejs_version='14'
image_tag="android-sdk-${android_sdk_version}"
container_name="michalsvorc_${application_name}-${image_tag}"
mount_workspace_source="${PWD}/workspace"
mount_workspace_target="/home/user/workspace"
#===============================================================================
# Help
#===============================================================================
_print_help() {
cat <<HELP
Usage: ./docker.sh [COMMAND]
Docker commands helper script
Commands:
-h|--help print this help text and exit
build build Docker image
run run Docker image
start start Docker container
HELP
}
#===============================================================================
# Functions
#===============================================================================
_die() {
local error_message="${1}"
printf 'Error: %s\nSee help for proper usage:\n\n' "${error_message}" >&2
_print_help
exit 1
}
_docker_build() {
printf 'Docker build image %s\n' "${image_name}:${image_tag}"
docker build \
--build-arg android_sdk_version="${android_sdk_version}" \
--build-arg android_build_tools_version="${android_build_tools_version}" \
--build-arg nodejs_version="${nodejs_version}" \
--tag "${image_name}:${image_tag}" \
.
}
_docker_run() {
printf 'Docker run image %s\n' "${image_name}:${image_tag}"
docker run \
-d \
-it \
--privileged \
--env DISPLAY="${DISPLAY}" \
-v '/tmp/.X11-unix:/tmp/.X11-unix' \
-v '/dev/bus/usb:/dev/bus/usb' \
--mount type=bind,source="${mount_workspace_source}",target="${mount_workspace_target}" \
--name "${container_name}" \
"${image_name}:${image_tag}" \
bash
}
_docker_start() {
printf 'Docker start container %s\n' "${container_name}"
docker start "${container_name}"
}
#===============================================================================
# Execution
#===============================================================================
if [ $# -eq 0 ]; then
_die 'No arguments provided'
fi
case "${1}" in
-h|--help)
_print_help
;;
build)
_docker_build
;;
run)
_docker_run
;;
start)
_docker_start
;;
*)
_die "Unknown argument '${1}'"
;;
esac