139 lines
3.8 KiB
Markdown
139 lines
3.8 KiB
Markdown
# Project Mycelium Deployment Scripts
|
|
|
|
This directory contains improved deployment scripts for the Project Mycelium that handle repository and directory management robustly.
|
|
|
|
## Scripts Overview
|
|
|
|
### Development Environment
|
|
- **Script**: [`tf-marketplace-dev.sh`](tf-marketplace-dev.sh)
|
|
- **Domain**: dev.threefold.pro
|
|
- **Port**: 9998
|
|
- **Branch**: development
|
|
- **Service**: tf-marketplace-dev
|
|
|
|
### Production Environment
|
|
- **Script**: [`tf-marketplace-prod.sh`](tf-marketplace-prod.sh)
|
|
- **Domain**: threefold.pro
|
|
- **Port**: 9999
|
|
- **Branch**: main
|
|
- **Service**: tf-marketplace
|
|
|
|
## Key Improvements
|
|
|
|
### 1. Robust Directory/Repository Handling
|
|
- ✅ Creates directory structure if it doesn't exist
|
|
- ✅ Handles both fresh clones and existing repositories
|
|
- ✅ Properly updates existing repositories with `git reset --hard`
|
|
- ✅ Validates git repository integrity
|
|
- ✅ Uses correct working directories throughout
|
|
|
|
### 2. Error Handling
|
|
- ✅ Exit on error (`set -e`)
|
|
- ✅ Validates cargo availability
|
|
- ✅ Checks for Cargo.toml presence
|
|
- ✅ Proper error messages with context
|
|
|
|
### 3. Environment-Specific Configuration
|
|
- ✅ Separate scripts for dev and prod environments
|
|
- ✅ Correct ports (9998 for dev, 9999 for prod)
|
|
- ✅ Correct branches (development for dev, main for prod)
|
|
- ✅ Clear environment identification in logs
|
|
|
|
## Installation
|
|
|
|
### 1. Copy Scripts to Server
|
|
```bash
|
|
# Copy the deployment scripts with explicit naming
|
|
sudo cp tf-marketplace-dev.sh /etc/zinit/cmds/tf-marketplace-dev.sh
|
|
sudo cp tf-marketplace-prod.sh /etc/zinit/cmds/tf-marketplace-prod.sh
|
|
sudo chmod +x /etc/zinit/cmds/tf-marketplace-dev.sh
|
|
sudo chmod +x /etc/zinit/cmds/tf-marketplace-prod.sh
|
|
```
|
|
|
|
### 2. Install Zinit Service Definitions
|
|
```bash
|
|
# Copy service definitions from config directory
|
|
sudo cp ../config/zinit/tf-marketplace-dev.yaml /etc/zinit/tf-marketplace-dev.yaml
|
|
sudo cp ../config/zinit/tf-marketplace-prod.yaml /etc/zinit/tf-marketplace-prod.yaml
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Development Deployment
|
|
```bash
|
|
# Start development service
|
|
zinit start tf-marketplace-dev
|
|
|
|
# Monitor development service
|
|
zinit monitor tf-marketplace-dev
|
|
|
|
# View development logs
|
|
zinit log tf-marketplace-dev
|
|
```
|
|
|
|
### Production Deployment
|
|
```bash
|
|
# Start production service
|
|
zinit start tf-marketplace
|
|
|
|
# Monitor production service
|
|
zinit monitor tf-marketplace
|
|
|
|
# View production logs
|
|
zinit log tf-marketplace
|
|
```
|
|
|
|
## Comparison with Original Script
|
|
|
|
### Original Issues Fixed
|
|
|
|
1. **Directory Check Logic**:
|
|
- ❌ Original: `[ ! -d "$DIR_NAME" ] && git clone "$REPO_URL"`
|
|
- ✅ Fixed: Proper path handling and working directory management
|
|
|
|
2. **Missing Updates**:
|
|
- ❌ Original: No git pull for existing repositories
|
|
- ✅ Fixed: `git reset --hard origin/branch` for clean updates
|
|
|
|
3. **Error Handling**:
|
|
- ❌ Original: No error checking
|
|
- ✅ Fixed: Comprehensive error handling and validation
|
|
|
|
4. **Path Consistency**:
|
|
- ❌ Original: Mixed path conventions
|
|
- ✅ Fixed: Consistent with existing deployment infrastructure
|
|
|
|
## Monitoring and Troubleshooting
|
|
|
|
### Check Service Status
|
|
```bash
|
|
zinit list | grep tf-marketplace
|
|
```
|
|
|
|
### View Real-time Logs
|
|
```bash
|
|
# Development
|
|
tail -f /var/log/zinit/tf-marketplace-dev.log
|
|
|
|
# Production
|
|
tail -f /var/log/zinit/tf-marketplace.log
|
|
```
|
|
|
|
### Manual Testing
|
|
```bash
|
|
# Test development script manually
|
|
sudo /etc/zinit/cmds/tf-marketplace-dev.sh
|
|
|
|
# Test production script manually
|
|
sudo /etc/zinit/cmds/tf-marketplace.sh
|
|
```
|
|
|
|
## Integration with Existing Infrastructure
|
|
|
|
These scripts are designed to work seamlessly with:
|
|
- Existing Makefile deployment targets ([`deploy-dev`](../Makefile:14), [`deploy-prod`](../Makefile:19))
|
|
- Current Caddy configuration
|
|
- Existing zinit service management
|
|
- Current directory structure conventions
|
|
|
|
The scripts maintain compatibility with the existing deployment workflow while providing more robust error handling and repository management. |