Skip to content

Commit 1cb8900

Browse files
committed
Ported image generation script to bash
1 parent 6c6e0b7 commit 1cb8900

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

build.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# Monkey365 – Docker Image Build and Tagging Script
19+
# Adapted from build.ps1 (PowerShell) to Bash
20+
# Author: Juan Garrido (original) (bash adaptation by goldrak)
21+
22+
23+
set -euo pipefail
24+
25+
NAME="monkey365"
26+
VERSION="latest"
27+
DOCKERFILE=""
28+
29+
usage() {
30+
cat <<EOF
31+
Use: $0 [Options]
32+
33+
Options:
34+
-n, --name Name of the Docker image (default: $NAME)
35+
-v, --version Image label (default: $VERSION)
36+
-p, --path Path to the Dockerfile (required)
37+
-h, --help Show this help and exit
38+
39+
Example:
40+
$0 -n monkey365 -v latest -p ./docker/Dockerfile_linux
41+
EOF
42+
exit 1
43+
}
44+
45+
while [[ $# -gt 0 ]]; do
46+
case "$1" in
47+
-n|--name)
48+
NAME="$2"; shift 2;;
49+
-v|--version)
50+
VERSION="$2"; shift 2;;
51+
-p|--path)
52+
DOCKERFILE="$2"; shift 2;;
53+
-h|--help)
54+
usage;;
55+
*)
56+
echo "Unknown option: $1"
57+
usage;;
58+
esac
59+
done
60+
61+
if [[ -z "$DOCKERFILE" ]]; then
62+
echo "Error: You must specify the path to the Dockerfile with -p or --path."
63+
usage
64+
fi
65+
66+
if [[ ! -f "$DOCKERFILE" ]]; then
67+
echo "Error: Dockerfile does not exist in '$DOCKERFILE'."
68+
exit 1
69+
fi
70+
71+
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
72+
73+
TAG="${NAME}:${VERSION}"
74+
75+
echo "Building Dockerfile using file '${DOCKERFILE}' and tag '${TAG}'"
76+
77+
docker build \
78+
--rm \
79+
-f "$DOCKERFILE" \
80+
-t "$TAG" \
81+
--build-arg VERSION="$VERSION" \
82+
--build-arg VCS_URL="https://github.com/silverhack/monkey365" \
83+
--build-arg BUILD_DATE="$BUILD_DATE" \
84+
.
85+

0 commit comments

Comments
 (0)