ソースを参照

separate start script

Denys Bashkatov 1 ヶ月 前
コミット
42378679e5
4 ファイル変更184 行追加41 行削除
  1. 7 7
      README.md
  2. 16 4
      admin/app/routes/documentation.tsx
  3. 5 30
      setup.sh
  4. 156 0
      start.sh

+ 7 - 7
README.md

@@ -53,10 +53,10 @@ This will create:
 
 ### 2. Deploy the Container
 
-Run the startup script to deploy the container:
+Run the setup script to deploy the container:
 
 ```bash
-./startup.sh
+./setup.sh
 ```
 
 The script will:
@@ -71,10 +71,10 @@ The script will:
 
 ### Configuration Process
 
-The startup script uses a template-based approach:
+The setup script uses a template-based approach:
 
 1. **Template File**: `docker-compose.src.yml` contains the base configuration with environment variable placeholders
-2. **Generation**: The startup script copies the template to `docker-compose.yml` and replaces placeholders with actual values
+2. **Generation**: The setup script copies the template to `docker-compose.yml` and replaces placeholders with actual values
 3. **Customization**: You can modify the generated `docker-compose.yml` file directly if needed
 
 ### Configuration Variables
@@ -231,20 +231,20 @@ docker compose -f docker-compose.yml restart
 
 To update the configuration:
 
-1. **Automatic Method**: Run `./startup.sh` again to regenerate configuration
+1. **Automatic Method**: Run `./setup.sh` again to regenerate configuration
 2. **Manual Method**: 
    - Stop the container: `docker compose -f docker-compose.yml down`
    - Edit the generated `docker-compose.yml` file directly
    - Restart the container: `docker compose -f docker-compose.yml up -d`
 
-**Note**: The `.env` file is used internally by the startup script. For manual changes, edit `docker-compose.yml` directly.
+**Note**: The `.env` file is used internally by the setup script. For manual changes, edit `docker-compose.yml` directly.
 
 ## 📁 Directory Structure
 
 ```
 ui-apt-mirror/
 ├── build.sh                 # Build script for Docker images
-├── startup.sh               # Deployment and configuration script
+├── setup.sh               # Deployment and configuration script
 ├── README.md               # This file
 ├── .env                    # Configuration file (generated)
 ├── docker-compose.src.yml  # Docker Compose template

+ 16 - 4
admin/app/routes/documentation.tsx

@@ -101,7 +101,7 @@ export default function Documentation() {
       <div>
         <h3 className="text-lg font-semibold mb-4">Initial Setup</h3>
         <div className="bg-gray-50 p-4 rounded-lg">
-          <h4 className="font-semibold text-blue-600 mb-2">./startup.sh</h4>
+          <h4 className="font-semibold text-blue-600 mb-2">./setup.sh</h4>
           <p className="text-gray-700 mb-3">Performs initial deployment and configuration of the apt-mirror container.</p>
           <div className="bg-white p-3 rounded border-l-4 border-green-500">
             <h5 className="font-semibold mb-2">Operations:</h5>
@@ -111,11 +111,10 @@ export default function Documentation() {
               <li>Prompts for custom configuration (domain, sync frequency, admin password)</li>
               <li>Generates nginx htpasswd file for authentication</li>
               <li>Cleans up previous installations</li>
-              <li>Loads appropriate Docker image</li>
               <li>Creates data directories structure</li>
               <li>Generates apt-mirror configuration</li>
               <li>Creates docker-compose.yml from template</li>
-              <li>Starts the container</li>
+              <li>Calls start.sh to load image and start container</li>
             </ul>
           </div>
         </div>
@@ -124,11 +123,24 @@ export default function Documentation() {
       <div>
         <h3 className="text-lg font-semibold mb-4">Starting and Restarting</h3>
         <div className="bg-gray-50 p-4 rounded-lg">
-          <h4 className="font-semibold text-blue-600 mb-2">After Initial Setup</h4>
+          <h4 className="font-semibold text-blue-600 mb-2">./start.sh</h4>
+          <p className="text-gray-700 mb-3">Loads Docker image and starts the container. Used by setup.sh and for manual restarts.</p>
+          <div className="bg-white p-3 rounded border-l-4 border-blue-500">
+            <h5 className="font-semibold mb-2">Operations:</h5>
+            <ul className="list-disc list-inside space-y-1 text-sm">
+              <li>Detects system architecture (amd64/arm64)</li>
+              <li>Validates required image files exist in dist/</li>
+              <li>Loads appropriate Docker image</li>
+              <li>Starts the container using docker-compose</li>
+            </ul>
+          </div>
+          
+          <h4 className="font-semibold text-blue-600 mb-2 mt-4">After Initial Setup</h4>
           <p className="text-gray-700 mb-3">Commands for managing the running container.</p>
           <div className="bg-white p-3 rounded border-l-4 border-orange-500">
             <h5 className="font-semibold mb-2">Operations:</h5>
             <ul className="list-disc list-inside space-y-1 text-sm">
+              <li><code className="bg-gray-100 px-1 rounded">./start.sh</code> - Load image and start container</li>
               <li><code className="bg-gray-100 px-1 rounded">docker compose up -d</code> - Start container</li>
               <li><code className="bg-gray-100 px-1 rounded">docker compose down</code> - Stop container</li>
               <li><code className="bg-gray-100 px-1 rounded">docker compose restart</code> - Restart container</li>

+ 5 - 30
startup.sh → setup.sh

@@ -193,19 +193,6 @@ cleanup_previous() {
     print_success "Cleanup completed."
 }
 
-# Function to load image
-load_image() {
-    local arch=$1
-    local tar_file="${DIST_DIR}/${IMAGE_NAME}-${arch}.tar.gz"
-    
-    print_status "Loading Docker image..."
-    
-    # Extract and load the image
-    gunzip -c "$tar_file" | docker load
-    
-    print_success "Image loaded successfully."
-}
-
 # Function to create data directories
 create_data_dirs() {
     print_status "Creating data directories..."
@@ -280,16 +267,6 @@ EOF
     print_success "apt-mirror configuration generated."
 }
 
-# Function to start container
-start_container() {
-    print_status "Starting container..."
-    
-    # Start with docker-compose
-    docker compose -f docker-compose.yml up -d
-    
-    print_success "Container started successfully."
-}
-
 # Function to show status
 show_status() {
     print_status "Container status:"
@@ -332,8 +309,8 @@ show_usage() {
     echo "  2. Validate that required image files exist"
     echo "  3. Get your custom configuration"
     echo "  4. Clean up previous installation"
-    echo "  5. Load the appropriate Docker image"
-    echo "  6. Start the container with your configuration"
+    echo "  5. Create data directories and generate configurations"
+    echo "  6. Call start.sh to load image and start container"
     echo ""
     echo "Prerequisites:"
     echo "  - Docker installed and running"
@@ -394,9 +371,6 @@ main() {
         cleanup_previous
     fi
     
-    # Load image
-    load_image "$arch"
-    
     # Create data directories
     create_data_dirs
     
@@ -406,8 +380,9 @@ main() {
     # Generate docker-compose.yml
     generate_docker_compose "$MIRROR_DOMAIN" "$SYNC_FREQUENCY"
     
-    # Start container
-    start_container
+    # Start container using start.sh
+    print_status "Starting container..."
+    ./start.sh
     
     # Show status
     show_status

+ 156 - 0
start.sh

@@ -0,0 +1,156 @@
+#!/bin/bash
+
+# Start script for ui-apt-mirror
+# This script handles loading the Docker image and starting the container
+
+set -e
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m' # No Color
+
+# Configuration
+IMAGE_NAME="ui-apt-mirror"
+CONTAINER_NAME="ui-apt-mirror"
+DIST_DIR="dist"
+
+# Function to print colored output
+print_status() {
+    echo -e "${BLUE}[INFO]${NC} $1"
+}
+
+print_success() {
+    echo -e "${GREEN}[SUCCESS]${NC} $1"
+}
+
+print_warning() {
+    echo -e "${YELLOW}[WARNING]${NC} $1"
+}
+
+print_error() {
+    echo -e "${RED}[ERROR]${NC} $1"
+}
+
+# Function to detect system architecture
+detect_architecture() {
+    print_status "Detecting system architecture..." >&2
+    
+    local arch=$(uname -m)
+    case $arch in
+        x86_64)
+            echo "amd64"
+            ;;
+        aarch64|arm64)
+            echo "arm64"
+            ;;
+        *)
+            print_error "Unsupported architecture: $arch"
+            exit 1
+            ;;
+    esac
+}
+
+# Function to validate dist directory
+validate_dist() {
+    local arch=$1
+    local tar_file="${DIST_DIR}/${IMAGE_NAME}-${arch}.tar.gz"
+    
+    print_status "Validating distribution files..."
+    
+    if [ ! -d "$DIST_DIR" ]; then
+        print_error "Distribution directory '$DIST_DIR' not found."
+        print_error "Please run ./build.sh first to build the images."
+        exit 1
+    fi
+    
+    if [ ! -f "$tar_file" ]; then
+        print_error "Image file '$tar_file' not found."
+        print_error "Please run ./build.sh first to build the images."
+        exit 1
+    fi
+    
+    print_success "Found image file: $tar_file"
+}
+
+# Function to load image
+load_image() {
+    local arch=$1
+    local tar_file="${DIST_DIR}/${IMAGE_NAME}-${arch}.tar.gz"
+    
+    print_status "Loading Docker image..."
+    
+    # Extract and load the image
+    gunzip -c "$tar_file" | docker load
+    
+    print_success "Image loaded successfully."
+}
+
+# Function to start container
+start_container() {
+    print_status "Starting container..."
+    
+    # Start with docker-compose
+    docker compose -f docker-compose.yml up -d
+    
+    print_success "Container started successfully."
+}
+
+# Function to show usage
+show_usage() {
+    echo "Usage: $0 [OPTIONS]"
+    echo ""
+    echo "Options:"
+    echo "  --help            Show this help message"
+    echo ""
+    echo "This script will:"
+    echo "  1. Detect your system architecture"
+    echo "  2. Validate that required image files exist"
+    echo "  3. Load the appropriate Docker image"
+    echo "  4. Start the container"
+    echo ""
+    echo "Prerequisites:"
+    echo "  - Docker installed and running"
+    echo "  - Built images in dist/ directory (run ./build.sh first)"
+    echo "  - docker-compose.yml file exists (run ./setup.sh first)"
+}
+
+# Main execution
+main() {
+    # Parse command line arguments
+    while [[ $# -gt 0 ]]; do
+        case $1 in
+            --help)
+                show_usage
+                exit 0
+                ;;
+            *)
+                print_error "Unknown option: $1"
+                show_usage
+                exit 1
+                ;;
+        esac
+    done
+    
+    print_status "Starting ui-apt-mirror..."
+    
+    # Detect architecture
+    local arch=$(detect_architecture)
+    print_success "Detected architecture: $arch"
+    
+    # Validate dist directory
+    validate_dist "$arch"
+    
+    # Load image
+    load_image "$arch"
+    
+    # Start container
+    start_container
+    
+    print_success "Container started successfully!"
+}
+
+# Run main function with all arguments
+main "$@"