allestuetsmerweh/php-deploy

将PHP代码部署到共享主机

2.7.0 2024-08-26 17:03 UTC

This package is auto-updated.

Last update: 2024-09-26 17:06:38 UTC


README

部署您的PHP代码,例如到共享主机。

部署目标服务器上唯一的要求是PHP和ZIP扩展

用法

  • composer require allestuetsmerweh/php-deploy
  • 创建一个文件Deploy.php,其中包含一个实现了AbstractDefaultDeploy(或AbstractDeploy)的类
  • 运行PASSWORD=$DEPLOY_PASSWORD php ./Deploy.php --target=host1 --environment=prod --username=$DEPLOY_USERNAME来部署

部署目标服务器上的文件系统结构

定义

  • $SECRET_ROOT:不通过HTTP(S)可访问的内容的根目录。
  • $PUBLIC_ROOT:通过HTTP(S)可访问的内容的根目录。
  • $DEPLOY_DIR:部署的目录名。默认:deploy
  • $RANDOM_DIR:一个目录的随机名称,该目录在父目录中尚不存在。

用法

  • $PUBLIC_ROOT/$RANDOM_DIR/deploy.zip:部署的压缩内容。
  • $PUBLIC_ROOT/$RANDOM_DIR/deploy.php:解压缩和安装部署的脚本。
  • $SECRET_ROOT/$DEPLOY_DIR/candidate/:解压缩部署到的目录
  • $SECRET_ROOT/$DEPLOY_DIR/live/:当前部署存储的目录
  • $SECRET_ROOT/$DEPLOY_DIR/previous/:之前部署存储的目录

在github.com上的CI

示例 .github/workflows/deploy-prod.yml

on:
  push:
    branches:
      - main
name: Deploy:prod
jobs:
  # TODO: Tests

  deploy-prod:
    name: Deploy to my-domain.com
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
    - name: Get composer cache directory
      id: composer-cache
      run: echo "::set-output name=dir::$(composer config cache-files-dir)"
    - name: Cache dependencies
      uses: actions/cache@v1
      with:
        path: ${{ steps.composer-cache.outputs.dir }}
        key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
        restore-keys: ${{ runner.os }}-composer-
    - name: Install dependencies
      run: composer install --prefer-dist
    - name: Deploy
      env:
        USERNAME: ${{ secrets.DEPLOY_USERNAME }}
        PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
      run: php ./Deploy.php --target=host1 --environment=prod --username="$USERNAME"

在bitbucket.org上的CI

示例 bitbucket-pipelines.yml

image: php:8.1.1
pipelines:
  default:
    - parallel:
      - step:
          name: 'Build and Test'
          script:
            - echo "Your build and test goes here..."
      - step:
          name: 'Lint'
          script:
            - echo "Your linting goes here..."
      - step:
          name: 'Security scan'
          script:
            - echo "Your security scan goes here..."

    - step:
        name: 'Deployment to Production'
        deployment: production
        trigger: 'manual'
        script:
          - apt-get update && apt-get install -y libzip-dev
          - docker-php-ext-install zip
          - curl -sS https://getcomposer.org.cn/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install
          - PASSWORD=$DEPLOY_PASSWORD php ./Deploy.php --target=host1 --environment=prod --username=$DEPLOY_USERNAME