-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_service.sh
More file actions
executable file
·66 lines (53 loc) · 2.39 KB
/
build_service.sh
File metadata and controls
executable file
·66 lines (53 loc) · 2.39 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
#!/bin/bash
service=$1
version=$2
gitsha=$(git rev-parse --short HEAD)
build_type=${3:-"raw"} # raw, gcp, aws
cd dibbs-ecr-viewer/packer/ || exit
ls -lhsa
echo "Build to be created: $build_type"
# check if the build directory exists
if [ -d "build/$service-$build_type-$version-$gitsha" ]; then
echo "Build directory for that version already exists."
read -rp $' \e[3m'"Do you want to remove the build directory? (y/n): "$'\e[0m' choice
if [ "$choice" == "y" ]; then
rm -rf "build/$service-$build_type-$version-$gitsha"
else
echo "Cannot continue with the build process."
exit 1
fi
fi
if [ -z "$service" ] || [ -z "$version" ]; then
echo "Usage: ./build.sh [DIBBS_SERVICE] [DIBBS_VERSION] [BUILD_TYPE (default: raw)]"
echo "Example: ./build.sh dibbs-ecr-viewer 1.0.0"
echo "Example: ./build.sh dibbs-query-connector 1.0.0 gcp"
echo "Example: ./build.sh dibbs-ecr-viewer 1.0.0 aws"
exit 1
fi
# build machines need to have OpenSSL installed for random password generation.
if ! command -v openssl &>/dev/null; then
echo "openssl could not be found, exiting..."
exit 1
fi
# generate a random password for the user with no special characters
dibbs_user_password=$(openssl rand -base64 24 | tr -d '[:punct:]')
echo "Generated password: $dibbs_user_password"
# generate the password hash for the user
dibbs_user_password_hash=$(openssl passwd -6 $dibbs_user_password)
# replace the password hash in the packer user-data file
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s|'{dibbs-user-password-hash}'|'"$dibbs_user_password_hash"'|" ./http/user-data
sed -i '' "s|'{dibbs-user-password}'|"$dibbs_user_password"|" ./http/aws-user-data
else
sed -i "s|'{dibbs-user-password-hash}'|'"$dibbs_user_password_hash"'|" ./http/user-data
sed -i "s|'{dibbs-user-password}'|"$dibbs_user_password"|" ./http/aws-user-data
fi
echo "Password replaced in user-data file."
# init
packer init .
# validate
packer validate --var dibbs_service="$service" --var dibbs_version="$version" --var ssh_password="$dibbs_user_password" --var gitsha="$gitsha" --var build_type="$build_type" .
# Build the base image
packer build --var dibbs_service="$service" --var dibbs_version="$version" --var ssh_password="$dibbs_user_password" --var gitsha="$gitsha" --var build_type="$build_type" .
echo "Remember, to login, you need to use the password: $dibbs_user_password"
cd - || exit