Skip to content

Commit a8bfc08

Browse files
committed
feat(install): replace secrets with rand pwds and host
1 parent a557ff3 commit a8bfc08

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

install/install_nomad.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ WAIT_FOR_IT_SCRIPT_URL="https://raw.githubusercontent.com/vishnubob/wait-for-it/
3939

4040
script_option_debug='true'
4141
accepted_terms='false'
42-
local_ip=''
42+
local_ip_address=''
4343

4444
###################################################################################################################################################################################################
4545
# #
@@ -98,6 +98,16 @@ check_is_debug_mode(){
9898
fi
9999
}
100100

101+
generateRandomPass() {
102+
local length="${1:-32}" # Default to 32
103+
local password
104+
105+
# Generate random password using /dev/urandom
106+
password=$(tr -dc 'A-Za-z0-9!@#$%^&*()_+=-' < /dev/urandom | head -c "$length")
107+
108+
echo "$password"
109+
}
110+
101111
ensure_docker_installed() {
102112
if ! command -v docker &> /dev/null; then
103113
echo -e "${YELLOW}#${RESET} Docker not found. Installing Docker...\\n"
@@ -235,6 +245,22 @@ download_management_compose_file() {
235245
exit 1
236246
fi
237247
echo -e "${GREEN}#${RESET} Docker compose file downloaded successfully to $compose_file_path.\\n"
248+
249+
local app_key=$(generateRandomPass 32)
250+
local db_root_password=$(generateRandomPass 16)
251+
local db_user_password=$(generateRandomPass 16)
252+
253+
# Inject dynamic env values into the compose file
254+
echo -e "${YELLOW}#${RESET} Configuring docker-compose file env variables...\\n"
255+
sed -i "s|HOST=replaceme|HOST=${local_ip_address}|g" "$compose_file_path"
256+
sed -i "s|URL=replaceme|URL=http://${local_ip_address}:8080|g" "$compose_file_path"
257+
sed -i "s|APP_KEY=replaceme|APP_KEY=${app_key}|g" "$compose_file_path"
258+
259+
sed -i "s|DB_PASSWORD=replaceme|DB_PASSWORD=${db_user_password}|g" "$compose_file_path"
260+
sed -i "s|MYSQL_ROOT_PASSWORD=replaceme|MYSQL_ROOT_PASSWORD=${db_root_password}|g" "$compose_file_path"
261+
sed -i "s|MYSQL_PASSWORD=replaceme|MYSQL_PASSWORD=${db_user_password}|g" "$compose_file_path"
262+
263+
echo -e "${GREEN}#${RESET} Docker compose file configured successfully.\\n"
238264
}
239265

240266
download_wait_for_it_script() {
@@ -300,7 +326,7 @@ get_local_ip() {
300326
local_ip_address=$(hostname -I | awk '{print $1}')
301327
if [[ -z "$local_ip_address" ]]; then
302328
echo -e "${RED}#${RESET} Unable to determine local IP address. Please check your network configuration."
303-
# Don't exit if we can't determine the local IP address, it's not critical for the installation
329+
exit 1
304330
fi
305331
}
306332

@@ -328,13 +354,13 @@ check_is_debug_mode
328354
get_install_confirmation
329355
accept_terms
330356
ensure_docker_installed
357+
get_local_ip
331358
create_nomad_directory
332359
download_wait_for_it_script
333360
download_entrypoint_script
334361
download_helper_scripts
335362
download_management_compose_file
336363
start_management_containers
337-
get_local_ip
338364
success_message
339365

340366
# free_space_check() {

install/management_compose.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ services:
1616
- PORT=8080
1717
- LOG_LEVEL=debug
1818
- DRIVE_DISK=fs
19-
- APP_KEY=secretlongpasswordsecret
20-
- HOST=0.0.0.0
21-
- URL=http://localhost:8080
19+
- APP_KEY=replaceme
20+
- HOST=replaceme
21+
- URL=replaceme
2222
- DB_HOST=mysql
2323
- DB_PORT=3306
2424
- DB_DATABASE=nomad
2525
- DB_USER=nomad_user
26-
- DB_PASSWORD=nomad_password
26+
- DB_PASSWORD=replaceme
2727
- DB_NAME=nomad
2828
- DB_SSL=false
2929
depends_on:
@@ -53,10 +53,10 @@ services:
5353
ports:
5454
- "3306:3306"
5555
environment:
56-
- MYSQL_ROOT_PASSWORD=secretpassword
56+
- MYSQL_ROOT_PASSWORD=replaceme
5757
- MYSQL_DATABASE=nomad
5858
- MYSQL_USER=nomad_user
59-
- MYSQL_PASSWORD=nomad_password
59+
- MYSQL_PASSWORD=replaceme
6060
volumes:
6161
- /opt/project-nomad/mysql:/var/lib/mysql
6262
healthcheck:

0 commit comments

Comments
 (0)