Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved deployment scripts and documentation #7504

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Database Configuration Tests

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
db-type: [mongo, cockroach, all]
node-version: [18.x]

env:
HULY_DB_TYPE: ${{ matrix.db-type }}

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: |
cd tests
npm install

- name: Run tests
run: |
cd tests
npm test

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.db-type }}
path: tests/junit.xml
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ This project offers a convenient method to host Huly using `docker`, designed fo
- [Table of Content](#table-of-content)
- [Pre-requisites](#pre-requisites)
- [Verification](#verification)
- [Fast start](#fast-start)
- [Automated Development Setup](#automated-development-setup)
- [Installation](#installation)
- [Build and run](#build-and-run)
- [Run in development mode](#run-in-development-mode)
Expand Down Expand Up @@ -64,6 +66,45 @@ To verify the installation, perform the following checks in your terminal:
sh ./scripts/fast-start.sh
```

## Automated Development Setup

For a streamlined development environment setup, we provide automated deployment scripts:

```bash
# Full automated setup
./scripts/deployment/deploy.sh all my_workspace

# Or individual steps
./scripts/deployment/deploy.sh clean # Run system cleanup
./scripts/deployment/deploy.sh check # Check dependencies
./scripts/deployment/deploy.sh prepare # Prepare branch
./scripts/deployment/deploy.sh workspace my_workspace # Create workspace
```

The automated setup handles:
- System cleanup and preparation
- Dependency installation and verification
- Branch setup
- Workspace creation
- Cross-platform support (Linux and macOS)

For detailed setup instructions, see our [Local Development Setup Guide](docs/getting-started/deployment/local-setup.md).

## Database Configuration

By default, both MongoDB and CockroachDB are started. You can control which databases to start using the `HULY_DB_TYPE` environment variable:

```bash
# Start both databases (default)
HULY_DB_TYPE=all ./scripts/select-db.sh up -d

# Start only MongoDB
HULY_DB_TYPE=mongo ./scripts/select-db.sh up -d

# Start only CockroachDB
HULY_DB_TYPE=cockroach ./scripts/select-db.sh up -d
```

## Installation

You need Microsoft's [rush](https://rushjs.io) to install application.
Expand Down
12 changes: 12 additions & 0 deletions dev/docker-compose.cockroach.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
cockroach:
image: cockroachdb/cockroach:latest-v24.2
ports:
- '26257:26257'
- '8089:8080'
command: start-single-node --insecure
volumes:
- cockroach_db:/cockroach/cockroach-data
restart: unless-stopped
volumes:
cockroach_db:
23 changes: 23 additions & 0 deletions dev/docker-compose.mongo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
mongodb:
image: 'mongo:7-jammy'
container_name: mongodb
extra_hosts:
- 'host.docker.internal:host-gateway'
healthcheck:
test: echo "try { db.currentOp().ok } catch (err) { }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
environment:
- PUID=1000
- PGID=1000
volumes:
- db:/data/db
ports:
- 27017:27017
restart: unless-stopped
volumes:
db:
35 changes: 7 additions & 28 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
services:
mongodb:
image: 'mongo:7-jammy'
container_name: mongodb
extra_hosts:
- 'host.docker.internal:host-gateway'
healthcheck:
test: echo "try { db.currentOp().ok } catch (err) { }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
environment:
- PUID=1000
- PGID=1000
volumes:
- db:/data/db
ports:
- 27017:27017
restart: unless-stopped
extends:
file: docker-compose.mongo.yaml
service: mongodb
postgres:
image: postgres
container_name: postgres
extra_hosts:
- "host.docker.internal:host-gateway"
- "host.docker.internal:host-gateway"
environment:
- POSTGRES_PASSWORD=example
volumes:
Expand All @@ -32,14 +16,9 @@ services:
- 5432:5432
restart: unless-stopped
cockroach:
image: cockroachdb/cockroach:latest-v24.2
ports:
- '26257:26257'
- '8089:8080'
command: start-single-node --insecure
volumes:
- cockroach_db:/cockroach/cockroach-data
restart: unless-stopped
extends:
file: docker-compose.cockroach.yaml
service: cockroach
minio:
image: 'minio/minio'
command: server /data --address ":9000" --console-address ":9001"
Expand Down
18 changes: 18 additions & 0 deletions scripts/deployment/config/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Base configuration
BASE_DIR="${HOME}/Huly/platform"
LOG_DIR="${BASE_DIR}/logs"

# Dependencies versions
NODE_VERSION="20"
NPM_VERSION="9.6.5"
PNPM_VERSION="7.30.5"

# Workspace defaults
DEFAULT_WORKSPACE="ws1"
DEFAULT_USERNAME="user1"
DEFAULT_PASSWORD="1234"
DEFAULT_FIRSTNAME="John"
DEFAULT_LASTNAME="Appleseed"

# Branch configuration
DEFAULT_BRANCH="feat/research-codebase"
5 changes: 5 additions & 0 deletions scripts/deployment/config/linux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Linux-specific configuration
PACKAGE_MANAGER="apt-get"
CACHE_DIR="/var/cache"
LOGS_DIR="/var/log"
DOCKER_SOCKET="/var/run/docker.sock"
5 changes: 5 additions & 0 deletions scripts/deployment/config/macos.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# macOS-specific configuration
PACKAGE_MANAGER="brew"
CACHE_DIR="${HOME}/Library/Caches"
LOGS_DIR="${HOME}/Library/Logs"
DOCKER_APP="/Applications/Docker.app"
66 changes: 66 additions & 0 deletions scripts/deployment/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# Source required modules
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
source "${SCRIPT_DIR}/config/default.conf"
source "${SCRIPT_DIR}/lib/logging.sh"
source "${SCRIPT_DIR}/lib/os_utils.sh"

# Command line arguments
ACTION=$1
WORKSPACE_NAME=${2:-$DEFAULT_WORKSPACE}

usage() {
echo "Usage: $0 [clean|check|prepare|workspace|all] [workspace_name]"
exit 1
}

run_clean() {
log_info "Starting system cleanup..."
bash scripts/clean-system.sh
}

run_dependency_check() {
log_info "Checking dependencies..."
bash scripts/dependency-check.sh
}

run_prepare_branch() {
log_info "Preparing branch..."
bash scripts/prepare-branch.sh
}

run_create_workspace() {
log_info "Creating workspace ${WORKSPACE_NAME}..."
bash scripts/create-workspace.sh "$WORKSPACE_NAME"
}

# Create scripts directory if it doesn't exist
mkdir -p "${SCRIPT_DIR}/scripts"

# Ensure we have a valid action
case "$ACTION" in
clean)
run_clean
;;
check)
run_dependency_check
;;
prepare)
run_prepare_branch
;;
workspace)
run_create_workspace
;;
all)
log_info "Starting full deployment process..."
run_clean
run_dependency_check
run_prepare_branch
run_create_workspace
log_info "Full deployment completed successfully"
;;
*)
usage
;;
esac
78 changes: 78 additions & 0 deletions scripts/deployment/scripts/clean-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Source required modules
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)"
source "${SCRIPT_DIR}/lib/logging.sh"
source "${SCRIPT_DIR}/lib/os_utils.sh"

analyze_space() {
log_info "Analyzing disk usage:"
echo "============================================"
log_info "Top 10 largest directories in project:"
du -h -d 1 "${BASE_DIR}" | sort -hr | head -10

log_info "Top 10 largest files in project:"
find "${BASE_DIR}" -type f -exec du -h {} + | sort -hr | head -10

log_info "Docker usage:"
docker system df

log_info "NPM cache size:"
du -h ~/.npm | tail -1

echo "============================================"
}

clean_system_cache() {
local os=$(detect_os)
case "$os" in
macos)
log_info "Cleaning development-specific caches..."
rm -rf ~/Library/Caches/npm
rm -rf ~/Library/Caches/typescript
rm -rf ~/Library/Caches/yarn
rm -rf ~/Library/Caches/pnpm
;;
linux)
log_info "Cleaning development-specific caches..."
rm -rf ~/.cache/npm
rm -rf ~/.cache/typescript
rm -rf ~/.cache/yarn
rm -rf ~/.cache/pnpm
;;
*)
log_warning "Unknown OS type, skipping cache cleanup"
;;
esac
}

# Start cleanup process
log_info "Starting system cleanup..."
analyze_space

# Clean npm cache
if command -v npm &> /dev/null; then
log_info "Cleaning npm cache..."
npm cache clean --force
fi

# Clean Docker - use safer approach
if command -v docker &> /dev/null; then
log_info "Cleaning unused Docker resources..."
# Only remove unused containers and images
docker container prune -f
docker image prune -f
fi

# Clean system cache
clean_system_cache

# Clean Homebrew if available
if command -v brew &> /dev/null; then
log_info "Cleaning Homebrew..."
brew cleanup -s
brew autoremove
fi

analyze_space
log_info "System cleanup completed"
Loading
Loading