Files

257 lines
5.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
if [ -z "${BASH_VERSION:-}" ]; then
exec bash "$0" "$@"
fi
set -euo pipefail
REPOSITORY_URL="ssh://git@git.hdrdevs.com.ar:2222/horacio/turnosxpress.git"
DEFAULT_BRANCH="main"
DEFAULT_TARGET_DIR="$HOME/PRODUCCION/turnosxpress"
if [[ -t 1 ]]; then
BLUE="\033[0;34m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
RED="\033[0;31m"
RESET="\033[0m"
else
BLUE=""
GREEN=""
YELLOW=""
CYAN=""
RED=""
RESET=""
fi
step() {
echo -e "${BLUE}$1${RESET}"
}
success() {
echo -e "${GREEN}$1${RESET}"
}
skip() {
echo -e "${YELLOW}⏭️ $1${RESET}"
}
info() {
echo -e "${CYAN}$1${RESET}"
}
warn() {
echo -e "${RED}⚠️ $1${RESET}"
}
DIRECTORIES_TO_REMOVE=(
".atl"
".codegraph"
".opencode"
"backupper"
"bot-admin-api"
"com.hdrdevs.turnosxpress"
"tx-android"
"file-manager"
"mongo-db"
"notification-sender"
"openspec"
"sysadmin"
"sysadmin-cli"
"txadmin"
"txbot"
"working-web"
)
FILES_TO_REMOVE=(
".dockerignore"
".gitignore"
"Dockerfile.alpine"
"Dockerfile.debian"
)
SERVER_DIRECTORIES_TO_REMOVE=(
"node_modules"
)
SERVER_FILES_TO_REMOVE=(
".env"
".env.android"
".env.dev"
".env.omv"
".env.txlocal"
)
TXCLIENT_DIRECTORIES_TO_REMOVE=(
".next"
"node_modules"
)
TXCLIENT_FILES_TO_REMOVE=(
".env"
".env.android"
".env.dev"
".env.omv"
".env.txlocal"
)
branch="${1:-$DEFAULT_BRANCH}"
target_dir="${2:-$DEFAULT_TARGET_DIR}"
timestamp="$(date +%Y%m%d-%H%M)"
image_archive="turnosxpress-${timestamp}.tar"
if [[ "$branch" == "-h" || "$branch" == "--help" ]]; then
cat <<USAGE
Usage: $0 [branch] [target-directory]
Clones the TurnosXpress repository and updates the selected branch.
After the repository is ready, it removes development and deployment folders/files
that are not needed by this workspace.
Arguments:
branch Branch to clone/update. Defaults to: ${DEFAULT_BRANCH}
target-directory Directory where the repository is cloned. Defaults to: ${DEFAULT_TARGET_DIR}
Examples:
$0
$0 develop
$0 feature/new-flow ../turnosxpress-feature
USAGE
exit 0
fi
step "Cleaning target directory '$target_dir'"
rm -rf -- "$target_dir"
mkdir -p -- "$(dirname -- "$target_dir")"
success "Target directory is clean"
step "Cloning branch '$branch' into '$target_dir'"
git clone --branch "$branch" --single-branch "$REPOSITORY_URL" "$target_dir"
success "Repository cloned"
step "Removing excluded root directories and files"
for directory in "${DIRECTORIES_TO_REMOVE[@]}"; do
path="$target_dir/$directory"
if [[ -d "$path" ]]; then
rm -rf -- "$path"
success "Removed directory: $directory"
else
skip "Directory not found: $directory"
fi
done
for file in "${FILES_TO_REMOVE[@]}"; do
path="$target_dir/$file"
if [[ -f "$path" ]]; then
rm -f -- "$path"
success "Removed file: $file"
else
skip "File not found: $file"
fi
done
server_dir="$target_dir/server"
if [[ -d "$server_dir" ]]; then
step "Removing excluded server directories and files"
for directory in "${SERVER_DIRECTORIES_TO_REMOVE[@]}"; do
path="$server_dir/$directory"
if [[ -d "$path" ]]; then
rm -rf -- "$path"
success "Removed server directory: $directory"
else
skip "Server directory not found: $directory"
fi
done
for file in "${SERVER_FILES_TO_REMOVE[@]}"; do
path="$server_dir/$file"
if [[ -f "$path" ]]; then
rm -f -- "$path"
success "Removed server file: $file"
else
skip "Server file not found: $file"
fi
done
if [[ -f "$server_dir/.env.prod" ]]; then
mv -- "$server_dir/.env.prod" "$server_dir/.env"
success "Renamed server file: .env.prod -> .env"
else
skip "Server file not found: .env.prod"
fi
else
warn "Server directory not found. Skipping server cleanup"
fi
txclient_dir="$target_dir/txclient"
if [[ -d "$txclient_dir" ]]; then
step "Removing excluded txclient directories and files"
for directory in "${TXCLIENT_DIRECTORIES_TO_REMOVE[@]}"; do
path="$txclient_dir/$directory"
if [[ -d "$path" ]]; then
rm -rf -- "$path"
success "Removed txclient directory: $directory"
else
skip "Txclient directory not found: $directory"
fi
done
for file in "${TXCLIENT_FILES_TO_REMOVE[@]}"; do
path="$txclient_dir/$file"
if [[ -f "$path" ]]; then
rm -f -- "$path"
success "Removed txclient file: $file"
else
skip "Txclient file not found: $file"
fi
done
if [[ -f "$txclient_dir/.env.prod" ]]; then
mv -- "$txclient_dir/.env.prod" "$txclient_dir/.env"
success "Renamed txclient file: .env.prod -> .env"
else
skip "Txclient file not found: .env.prod"
fi
else
warn "Txclient directory not found. Skipping txclient cleanup"
fi
step "Building Docker image"
(
cd "$target_dir"
info "Stopping container: turnosxpress"
docker stop turnosxpress || true
info "Removing container: turnosxpress"
docker rm turnosxpress || true
info "Removing image: turnosxpress:latest"
docker rmi turnosxpress:latest || true
info "Building image: turnosxpress:latest"
docker build -t turnosxpress .
)
success "Docker image built"
step "Exporting Docker image"
(
cd "$HOME/PRODUCCION"
info "Saving image to: $image_archive"
docker save turnosxpress:latest -o "$image_archive"
info "Compressing image: ${image_archive}.gz"
gzip -f "$image_archive"
)
success "Docker image exported to '$HOME/PRODUCCION/${image_archive}.gz'"
success "Done. Repository is ready at '$target_dir' on branch '$branch'"