-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathbuild.sh
More file actions
85 lines (69 loc) · 2.04 KB
/
build.sh
File metadata and controls
85 lines (69 loc) · 2.04 KB
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
#!/usr/bin/env bash
#
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Monkey365 – Docker Image Build and Tagging Script
# Adapted from build.ps1 (PowerShell) to Bash
# Author: Juan Garrido (original) (bash adaptation by goldrak)
set -euo pipefail
NAME="monkey365"
VERSION="latest"
DOCKERFILE=""
usage() {
cat <<EOF
Use: $0 [Options]
Options:
-n, --name Name of the Docker image (default: $NAME)
-v, --version Image label (default: $VERSION)
-p, --path Path to the Dockerfile (required)
-h, --help Show this help and exit
Example:
$0 -n monkey365 -v latest -p ./docker/Dockerfile_linux
EOF
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
-n|--name)
NAME="$2"; shift 2;;
-v|--version)
VERSION="$2"; shift 2;;
-p|--path)
DOCKERFILE="$2"; shift 2;;
-h|--help)
usage;;
*)
echo "Unknown option: $1"
usage;;
esac
done
if [[ -z "$DOCKERFILE" ]]; then
echo "Error: You must specify the path to the Dockerfile with -p or --path."
usage
fi
if [[ ! -f "$DOCKERFILE" ]]; then
echo "Error: Dockerfile does not exist in '$DOCKERFILE'."
exit 1
fi
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
TAG="${NAME}:${VERSION}"
echo "Building Dockerfile using file '${DOCKERFILE}' and tag '${TAG}'"
docker build \
--rm \
-f "$DOCKERFILE" \
-t "$TAG" \
--build-arg VERSION="$VERSION" \
--build-arg VCS_URL="https://github.com/silverhack/monkey365" \
--build-arg BUILD_DATE="$BUILD_DATE" \
.