* chore(docker): Adding dynamic env generator * ci(make): Create deployment yamls * ci(make): Generating docker envs * change env name structure * proper env names * chore(docker): clickhouse * chore(docker-compose): generate env file format * chore(docker-compose): Adding docker-compose * chore(docker-compose): format make * chore(docker-compose): Update version * chore(docker-compose): adding new secrets * ci(make): default target * ci(Makefile): Update common protocol * chore(docker-compose): refactor folder structure * ci(make): rename to docker-envs * feat(docker): add clickhouse volume definition Add clickhouse persistent volume to the docker-compose configuration to ensure data is preserved between container restarts. * refactor: move env files to docker-envs directory Updates all environment file references in docker-compose.yaml to use a consistent directory structure, placing them under the docker-envs/ directory for better organization. * fix(docker): rename imagestorage to images The `imagestorage` service and related environment file have been renamed to `images` for clarity and consistency. This change reflects the service's purpose of handling images. * feat(docker): introduce docker-compose template A new docker-compose template to generate docker-compose files from a list of services. The template uses helm syntax. * fix: Properly set FILES variable in Makefile The FILES variable was not being set correctly in the Makefile due to subshell issues. This commit fixes the variable assignment and ensures that the variable is accessible in subsequent commands. * feat: Refactor docker-compose template for local development This commit introduces a complete overhaul of the docker-compose template, switching from a helm-based template to a native docker-compose.yml file. This change simplifies local development and makes it easier to manage the OpenReplay stack. The new template includes services for: - PostgreSQL - ClickHouse - Redis - MinIO - Nginx - Caddy It also includes migration jobs for setting up the database and MinIO. * fix(docker-compose): Add fallback empty environment Add an empty environment to the docker-compose template to prevent errors when the env_file is missing. This ensures that the container can start even if the environment file is not present. * feat(docker): Add domainname and aliases to services This change adds the `domainname` and `aliases` attributes to each service in the docker-compose.yaml file. This is to ensure that the services can communicate with each other using their fully qualified domain names. Also adds shared volume and empty environment variables. * update version * chore(docker): don't pull parallel * chore(docker-compose): proper pull * chore(docker-compose): Update db service urls * fix(docker-compose): clickhouse url * chore(clickhouse): Adding clickhouse db migration * chore(docker-compose): Adding clickhouse * fix(tpl): variable injection * chore(fix): compose tpl variable rendering * chore(docker-compose): Allow override pg variable * chore(helm): remove assist-server * chore(helm): pg integrations * chore(nginx): removed services * chore(docker-compose): Mulitple aliases * chore(docker-compose): Adding more env vars * feat(install): Dynamically generate passwords dynamic password generation by identifying `change_me_*` entries in `common.env` and replacing them with random passwords. This enhances security and simplifies initial setup. The changes include: - Replacing hardcoded password replacements with a loop that iterates through all `change_me_*` entries. - Using `grep` to find all `change_me_*` tokens. - Generating a random password for each token. - Updating the `common.env` file with the generated passwords. * chore(docker-compose): disable clickhouse password * fix(docker-compose): clickhouse-migration * compose: chalice env * chore(docker-compose): overlay vars * chore(docker): Adding ch port * chore(docker-compose): disable clickhouse password * fix(docker-compose): migration name * feat(docker): skip specific values * chore(docker-compose): define namespace --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com>
144 lines
3.9 KiB
Bash
144 lines
3.9 KiB
Bash
#!/bin/bash
|
|
|
|
# Interactive Bash Script with Emojis
|
|
|
|
set -e
|
|
|
|
# Color codes for pretty printing
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[0;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# --- Helper functions for logs ---
|
|
info() {
|
|
echo -e "${GREEN}[INFO] $1 ${NC} 👍"
|
|
}
|
|
|
|
warn() {
|
|
echo -e "${YELLOW}[WARN] $1 ${NC} ⚠️"
|
|
}
|
|
|
|
fatal() {
|
|
echo -e "${RED}[FATAL] $1 ${NC} 🔥"
|
|
exit 1
|
|
}
|
|
|
|
# Function to check if a command exists
|
|
function exists() {
|
|
type "$1" &>/dev/null
|
|
}
|
|
|
|
# Generate a random password using openssl
|
|
randomPass() {
|
|
exists openssl || {
|
|
info "Installing openssl... 🔐"
|
|
sudo apt update &>/dev/null
|
|
sudo apt install openssl -y &>/dev/null
|
|
}
|
|
openssl rand -hex 10
|
|
}
|
|
|
|
# Create dynamic passwords and update the environment file
|
|
function create_passwords() {
|
|
info "Creating dynamic passwords..."
|
|
|
|
# Update domain name replacement
|
|
sed -i "s/change_me_domain/${DOMAIN_NAME}/g" common.env
|
|
|
|
# Find all change_me_ entries and replace them with random passwords
|
|
grep -o 'change_me_[a-zA-Z0-9_]*' common.env | sort -u | while read -r token; do
|
|
random_pass=$(randomPass)
|
|
sed -i "s/${token}/${random_pass}/g" common.env
|
|
info "Generated password for ${token}"
|
|
done
|
|
|
|
info "Passwords created and updated in common.env file."
|
|
}
|
|
|
|
# update apt cache
|
|
info "Grabbing latest apt caches"
|
|
sudo apt update
|
|
|
|
# setup docker
|
|
info "Setting up Docker"
|
|
sudo apt install docker.io docker-compose -y
|
|
|
|
# enable docker without sudo
|
|
sudo usermod -aG docker "${USER}" || true
|
|
|
|
# Prompt for DOMAIN_NAME input
|
|
echo -e "${GREEN}Please provide your domain name.${NC}"
|
|
echo "Let's get the exact domain OpenReplay will be installed on"
|
|
echo "Make sure that you have a Host A DNS record pointing to this instance!"
|
|
echo "This will be used for TLS 🔐"
|
|
echo -e "ie: my-openreplay.company.com (NOT an IP address)\n"
|
|
|
|
echo -e "${GREEN}"
|
|
read -rp "Enter DOMAIN_NAME: " DOMAIN_NAME
|
|
echo -e "${NC}"
|
|
if [[ -z $DOMAIN_NAME ]]; then
|
|
fatal "DOMAIN_NAME variable is empty. Please provide a valid domain name to proceed."
|
|
fi
|
|
info "Using domain name: $DOMAIN_NAME 🌐"
|
|
echo "CADDY_DOMAIN=\"$DOMAIN_NAME\"" >>common.env
|
|
|
|
read -p "Is the domain on a public DNS? (y/n) " yn
|
|
case $yn in
|
|
y)
|
|
echo "$DOMAIN_NAME is on a public DNS"
|
|
;;
|
|
n)
|
|
echo "$DOMAIN_NAME is on a private DNS"
|
|
#add TLS internal to caddyfile
|
|
#In local network Caddy can't reach Let's Encrypt servers to get a certificate
|
|
mv Caddyfile Caddyfile.public
|
|
mv Caddyfile.private Caddyfile
|
|
;;
|
|
*)
|
|
echo invalid response
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Create passwords if they don't exist
|
|
create_passwords
|
|
|
|
info "Starting the application with Docker... 🐳"
|
|
# Load variables from common.env into the current shell's environment
|
|
set -a # automatically export all variables
|
|
source common.env
|
|
set +a
|
|
|
|
# Use the `envsubst` command to substitute the shell environment variables into reference_var.env and output to a combined .env
|
|
find ./ -type f \( -iname "*.env" -o -iname "docker-compose.yaml" \) ! -name "common.env" -exec /bin/bash -c 'file="{}"; git checkout -- "$file"; cp "$file" "$file.bak"; envsubst < "$file.bak" > "$file"; rm "$file.bak"' \;
|
|
|
|
case $yn in
|
|
y)
|
|
echo "$DOMAIN_NAME is on a public DNS"
|
|
##No changes needed
|
|
;;
|
|
n)
|
|
echo "$DOMAIN_NAME is on a private DNS"
|
|
##Add a variable to chalice.env file
|
|
echo "SKIP_H_SSL=True" >>chalice.env
|
|
;;
|
|
*)
|
|
echo invalid response
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
readarray -t services < <(sudo -E docker-compose config --services)
|
|
for service in "${services[@]}"; do
|
|
echo "Pulling image for $service..."
|
|
sudo -E docker-compose pull --no-parallel "$service"
|
|
sleep 5
|
|
done
|
|
|
|
sudo -E docker-compose --profile migration up --force-recreate --build -d
|
|
cp common.env common.env.bak
|
|
echo "🎉🎉🎉 Done! 🎉🎉🎉"
|
|
|
|
info "Installation complete!! open https://${DOMAIN_NAME} 🐳"
|
|
info "${PWD} have the docker-compose file. you can use docker-compose stop/start"
|