承接 dennenboom/harvest 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dennenboom/harvest

Composer 安装命令:

composer require dennenboom/harvest

包简介

Simple deployment automation tool for Laravel applications

README 文档

README

A simple deployment automation tool for Laravel applications, inspired by Laravel Envoy. Harvest helps you automate deployment scenarios by executing a series of commands on remote servers via SSH.

Features

  • Simple deployment automation
  • SSH-based remote execution
  • Optional confirmation prompts
  • Variable placeholders for dynamic deployments
  • Sudo password handling
  • Shell context switching support
  • SSH jump host (proxy) support
  • Easy configuration
  • Docker-friendly

Installation

Install via Composer:

composer require dennenboom/harvest

The package will auto-register itself via Laravel's package discovery.

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=harvest-config

This will create a config/harvest.php file. Configure your deployment environments:

return [
    'deployments' => [
        'uat' => [
            // The SSH command used to connect to the server
            'ssh_command' => 'ssh user@host -p2121',

            // Prompt for confirmation before executing actions
            'ask_confirmation' => true,

            // Actions to execute on the remote server
            'actions' => [
                'cd /var/www/my-app',
                'git pull origin main',
                'composer install --no-dev --optimize-autoloader',
                'php artisan migrate --force',
                'php artisan config:cache',
            ],
        ],

        'production' => [
            'ssh_command' => 'ssh user@production-host',
            'ask_confirmation' => true,
            'actions' => [
                'cd /var/www/my-app',
                'git pull origin main',
                'composer install --no-dev --optimize-autoloader',
                'php artisan migrate --force',
            ],
        ],
    ],
];

SSH Setup

Docker: Mount SSH keys

# docker-compose.yml
services:
  app:
    volumes:
      - ~/.ssh:/root/.ssh:ro

Usage

Deploy to a specific environment:

php artisan harvest:deploy uat

Skip confirmation prompt:

php artisan harvest:deploy uat --no-confirm

Pass variables via command line:

php artisan harvest:deploy production --var=version=v1.57.3

Pass multiple variables:

php artisan harvest:deploy production --var=version=v1.57.3 --var=branch=main

SSH Authentication

Harvest executes SSH commands directly, so authentication is handled by your SSH configuration. This means:

  • Your SSH keys should be set up and configured outside of Harvest
  • Use ssh-agent to manage your keys
  • Configure SSH aliases in your ~/.ssh/config for easier management

Example SSH config (~/.ssh/config):

Host uat-server
    HostName uat.example.com
    User deployer
    Port 2121
    IdentityFile ~/.ssh/deploy_key

Then in your Harvest config:

'uat' => [
    'ssh_command' => 'ssh uat-server',
    // ...
],

Docker Considerations

If your Laravel application runs inside Docker containers, you have several options for SSH key management:

Option 1: SSH Agent Forwarding (Recommended)

Mount your SSH agent socket into the container:

# docker-compose.yml
services:
  app:
    volumes:
      - $SSH_AUTH_SOCK:/ssh-agent
    environment:
      - SSH_AUTH_SOCK=/ssh-agent

Then run:

docker-compose exec app php artisan harvest:deploy uat

Option 2: Mount SSH Keys as Volume

Mount your SSH directory (ensure proper permissions):

# docker-compose.yml
services:
  app:
    volumes:
      - ~/.ssh:/root/.ssh:ro

Warning: Be careful with this approach and never commit SSH keys to your repository.

Option 3: Run Harvest Outside Docker

Since Harvest only orchestrates SSH commands, you can run it from your host machine:

# On your host machine
php artisan harvest:deploy uat

Option 4: Use Environment Variables for SSH Config

You can set SSH connection details via environment variables:

# .env (DO NOT COMMIT)
HARVEST_UAT_SSH=ssh user@host -p2121

Then in your config:

'uat' => [
    'ssh_command' => env('HARVEST_UAT_SSH', 'ssh user@host'),
    // ...
],

How It Works

  1. Harvest reads your deployment configuration from config/harvest.php
  2. It connects to the remote server using the configured SSH command
  3. Each action is executed sequentially on the remote server
  4. If any action fails, deployment stops immediately
  5. Success/failure status is reported back to you

Advanced Features

Variable Placeholders

Use dynamic variables in your deployment actions. Perfect for version tagging, branch selection, or any dynamic value.

Configuration:

'production' => [
    'ssh_command' => 'ssh deployer@prod.example.com',
    'ask_confirmation' => true,
    'variables' => [
        'version' => 'Enter version tag to deploy (e.g., v1.57.3)',
        'branch' => [
            'prompt' => 'Enter branch name',
            'default' => 'main',
        ],
    ],
    'actions' => [
        'cd /var/www/app',
        'git fetch --all --tags',
        'git checkout {version}',
        'composer install --no-dev --optimize-autoloader',
    ],
],

Usage:

# Will prompt for version
php artisan harvest:deploy production

# Pass version via command line
php artisan harvest:deploy production --var=version=v1.57.3

Sudo Password Handling

Harvest automatically detects when your deployment requires sudo password and prompts you securely.

Auto-detection: Harvest detects sudo -S or sudo -s commands automatically.

Manual configuration: Set needs_sudo_password to true to force password prompt.

'staging' => [
    'ssh_command' => 'ssh user@staging.example.com',
    'needs_sudo_password' => true,  // Force password prompt
    'actions' => [
        'sudo systemctl restart nginx',
        'sudo supervisorctl restart all',
    ],
],

Shell Context Switching

Harvest intelligently handles shell switching commands like sudo -u user -s /bin/bash. When detected, all subsequent commands run in that user's context.

Example:

'staging' => [
    'ssh_command' => 'ssh -J proxy@jump.example.com user@target.example.com',
    'ask_confirmation' => true,
    'actions' => [
        'sudo -S -u apache -s /bin/bash',  // Switch to apache user
        'cd /srv/www/app',                 // Runs as apache
        'git pull origin dev',             // Runs as apache
        'composer install',                // Runs as apache
        'php artisan migrate --force',     // Runs as apache
    ],
],

When you run this deployment, Harvest will:

  1. Prompt for sudo password (auto-detected from sudo -S)
  2. Connect via SSH jump host (proxy)
  3. Switch to apache user
  4. Execute remaining commands in apache user context

Configuration Options

Per-Environment Settings

  • ssh_command (required): The SSH command to connect to the server
  • ask_confirmation (optional, default: false): Whether to prompt for confirmation before deployment
  • actions (required): Array of commands to execute on the remote server
  • variables (optional): Define variables for use in actions with {varname} placeholders
  • needs_sudo_password (optional): Force sudo password prompt (auto-detected when using sudo -S or sudo -s)

Examples

Simple Deployment

'dev' => [
    'ssh_command' => 'ssh deployer@dev.example.com',
    'ask_confirmation' => false,
    'actions' => [
        'cd /var/www/app',
        'git pull',
        'composer install',
    ],
],

Production with Confirmation

'production' => [
    'ssh_command' => 'ssh deployer@prod.example.com',
    'ask_confirmation' => true,
    'actions' => [
        'cd /var/www/app',
        'git pull origin main',
        'composer install --no-dev --optimize-autoloader',
        'php artisan down',
        'php artisan migrate --force',
        'php artisan config:cache',
        'php artisan route:cache',
        'php artisan view:cache',
        'php artisan queue:restart',
        'php artisan up',
    ],
],

Multiple Servers

'staging' => [
    'ssh_command' => 'ssh deployer@staging.example.com',
    'actions' => ['cd /var/www/app', 'git pull'],
],
'production-web' => [
    'ssh_command' => 'ssh deployer@web1.example.com',
    'actions' => ['cd /var/www/app', 'git pull'],
],
'production-worker' => [
    'ssh_command' => 'ssh deployer@worker1.example.com',
    'actions' => ['cd /var/www/app', 'git pull', 'supervisorctl restart all'],
],

License

MIT License. See LICENSE for details.

dennenboom/harvest 适用场景与选型建议

dennenboom/harvest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 378 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dennenboom/harvest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dennenboom/harvest 我们能提供哪些服务?
定制开发 / 二次开发

基于 dennenboom/harvest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 378
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-27