-
Notifications
You must be signed in to change notification settings - Fork 4
/
dockerfunctions.sh
executable file
·138 lines (113 loc) · 3.4 KB
/
dockerfunctions.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env sh
# Wrappers for docker run commands
#
# Helper Functions
#
del_stopped() {
name=$1
state="$(docker inspect --format "{{.State.Running}}" "$name" 2>/dev/null || echo "")"
if [ "$state" = "false" ]; then
docker rm "$name"
fi
unset state
unset name
}
prune_container_runtime_environment() {
docker system prune \
--all \
--force \
--volumes
}
relies_on() {
for container in "$@"; do
state="$(docker inspect --format "{{.State.Running}}" "$container" 2>/dev/null || echo "")"
if [ "$state" = "false" ] || [ "$state" = "" ]; then
echo "$container is not running, starting it for you."
$container
fi
unset state
done
}
set_docker_interactive_and_tty_options() {
_DOCKER_INTERACTIVE_TTY_OPTION=
if [ -t 0 ]; then
_DOCKER_INTERACTIVE_TTY_OPTION="-it"
fi
}
update_container_image() {
if [ "${UPDATE_CONTAINER_IMAGE:-}" = "true" ]; then
docker pull "${1}"
fi
}
#
# Container Aliases
#
ansible() {
_CONTAINER_IMAGE_ID="ansible/ansible:${CONTAINER_IMAGE_VERSION:-"latest"}"
update_container_image "${_CONTAINER_IMAGE_ID}"
_CONTAINER_NAME="ansible"
del_stopped "${_CONTAINER_NAME}"
set_docker_interactive_and_tty_options
# shellcheck disable=SC2086
docker run \
${_DOCKER_INTERACTIVE_TTY_OPTION} \
--name "${_CONTAINER_NAME}" \
--rm \
--volume "$(pwd)":/etc/ansible \
--volume /etc/localtime:/etc/localtime:ro \
"${_CONTAINER_IMAGE_ID}" \
"$@"
unset _CONTAINER_IMAGE_ID
unset _CONTAINER_NAME
}
if ! is_command_available "gcloud"; then
gcloud() {
_CONTAINER_IMAGE_ID="gcr.io/google.com/cloudsdktool/cloud-sdk:${CONTAINER_IMAGE_VERSION:-"latest"}"
update_container_image "${_CONTAINER_IMAGE_ID}"
_CONTAINER_NAME="gcloud"
del_stopped "${_CONTAINER_NAME}"
set_docker_interactive_and_tty_options
# shellcheck disable=SC2086
docker run \
${_DOCKER_INTERACTIVE_TTY_OPTION} \
--env CLOUDSDK_CONFIG=/config/gcloud \
--name "${_CONTAINER_NAME}" \
--rm \
--volume "${GCLOUD_CONFIG_DIRECTORY}":/config/gcloud \
--volume /etc/localtime:/etc/localtime:ro \
"${_CONTAINER_IMAGE_ID}" \
gcloud "$@"
unset _CONTAINER_IMAGE_ID
unset _CONTAINER_NAME
}
fi
super_linter() {
_CONTAINER_IMAGE_ID="ghcr.io/github/super-linter:${CONTAINER_IMAGE_VERSION:-"latest"}"
update_container_image "${_CONTAINER_IMAGE_ID}"
_CONTAINER_NAME="super_linter"
del_stopped "${_CONTAINER_NAME}"
set_docker_interactive_and_tty_options
# shellcheck disable=SC2086
docker run \
${_DOCKER_INTERACTIVE_TTY_OPTION} \
--env ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-"false"}" \
--env ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY:-"/ansible"}" \
--env DEFAULT_WORKSPACE=/tmp/lint \
--env DISABLE_ERRORS=false \
--env ERROR_ON_MISSING_EXEC_BIT=true \
--env IGNORE_GITIGNORED_FILES=true \
--env KUBERNETES_KUBEVAL_OPTIONS="--strict --ignore-missing-schemas --schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/" \
--env LINTER_RULES_PATH="${LINTER_RULES_PATH:-"."}" \
--env MULTI_STATUS=false \
--env RUN_LOCAL=true \
--env VALIDATE_ALL_CODEBASE=true \
--name "${_CONTAINER_NAME}" \
--rm \
--volume "$(pwd)":/tmp/lint \
--volume /etc/localtime:/etc/localtime:ro \
--workdir /tmp/lint \
"${_CONTAINER_IMAGE_ID}" \
"$@"
unset _CONTAINER_IMAGE_ID
unset _CONTAINER_NAME
}