plasticstudio/ps-deployer

这是部署脚本的基模块 - 专门为我们在sitehost的设置定制

1.2.9 2024-08-01 21:26 UTC

README

快速访问命令

dep deploy stage=uat

dep deploy stage=uat --branch=master

dep deploy stage=prod --tag=1.0.1

dep sitehost:prepare

dep sitehost:prepare:deploy stage=uat --branch=master

dep sitehost:backup

dep savefromremote:latest

dep savefromremote

dep savefromremote:db

dep savefromremote:assets

dep savefromremote:logs

dep loadtoremote:assets

重要

为了保持正常设置 - 添加到您的docker文件环境变量

- DEPLOYER_VERSION=6.8.0

从v6迁移到7

  1. 确保您正在运行最新的Docker镜像(您可以在Docker Desktop内部获取此镜像)。Deployer 7目前与8.1和8.0 Docker镜像兼容。

  2. 安装新模块 composer require --dev PlasticStudio/ps-deployer ,它现在包含所有旧deploy.php中存在的任务

  3. 将您的 deploy.php 重命名为 deploy-backup.php

  4. 创建新的 deploy.php 并添加以下所有代码。

    <?php
    
    namespace Deployer;
    
    require 'vendor/plasticstudio/ps-deployer/ps_silverstripe.php';
    
    //Legacy deployer v6 path to use
    //set('current_path', '/container/application/current');
    set('repository', 'git@github.com:PlasticStudio/skeletor.git');
    set('remote_assets_backup_path', '/container/backups/containers/latest/application/shared/public/assets'); //no trailing slash is important
    set('remote_assets_path', '/container/application/shared/public/assets/');
    set('local_assets_path', '/var/www/html/public/assets/');
    
    //Staging
    host('uat.domain.co.nz')
        ->set('labels', ['stage' => 'uat'])
        ->set('http_user', 'uatuser')
        ->set('remote_user', 'uatuser');
    
    
    //Production
    host('production.domain.co.nz')
        ->set('labels', ['stage' => 'prod'])
        ->set('http_user', 'produser')
        ->set('remote_user', 'uatuser');
    
  5. 打开文件并复制所有网站特定变量,例如用户、主机和文件路径

  6. 复制后,现在您可以删除您的旧 deploy-backup.php

  7. 新容器:如果这是一个新容器,那么我们需要为sitehost准备 dep sitehost:prepare。这将删除public文件夹,并准备好进行符号链接。为您设置SSH密钥以便复制。设置PHP默认配置

    现有容器:如果这是一个现有容器,那么我们需要为sitehost准备。您可能希望保持当前的部署路径。在您的deploy.php文件中取消注释以下行。 //set('current_path', '/container/application/current');

    容器升级:待办事项

  8. 如果这是一个现有容器,那么在您第一次部署时,我们需要通过release_name进行部署。这将是目前版本+1。要找出当前版本,请通过SSH进入容器并检查releases文件夹。

dep deploy stage=uat --branch=master -o release_name=43

新设置

composer require PlasticStudio/ps-deployer

创建一个包含以下内容的新的deploy.php文件,并根据需要进行更新

<?php

namespace Deployer;

require 'vendor/plasticstudio/ps-deployer/ps_silverstripe.php';

//Legacy deployer v6 path to use
//set('current_path', '/container/application/current');
set('repository', 'git@github.com:PlasticStudio/skeletor.git');
set('remote_assets_backup_path', '/container/backups/containers/latest/application/shared/public/assets'); //no trailing slash is important
set('remote_assets_path', '/container/application/shared/public/assets/');
set('local_assets_path', '/var/www/html/public/assets/');

//Staging
host('uat.domain.co.nz')
    ->set('labels', ['stage' => 'uat'])
    ->set('http_user', 'uatuser')
    ->set('remote_user', 'uatuser');


//Production
host('production.domain.co.nz')
    ->set('labels', ['stage' => 'prod'])
    ->set('http_user', 'produser')
    ->set('remote_user', 'uatuser');

为Deployer设置SiteHost

待办事项:遵循guru卡进行设置,然后您可以运行此命令 - 这只需要运行一次

dep sitehost:prepare

这将

  • 删除在第一次创建Sitehost服务器时创建的public目录,这样我们就可以使用此路径作为符号链接
  • 生成SSH密钥,您可以将它复制到GitHub项目的部署密钥中
  • 创建PHP默认配置

如果您正在Sitehost上进行容器升级,那么您需要在之后立即运行此命令

dep sitehost:prepare:deploy stage=uat --branch=master

这将更新配置为默认值并修复符号链接

部署

部署网站

就像dep deploy一样简单。这将为您提供选择部署到哪个主机并获取当前git HEAD进行部署的选项。

dep deploy stage=uat
# Deploy the dev branch
dep deploy stage=uat --branch=master


# Deploy tag 1.0.1 to production
dep deploy stage=prod --tag=1.0.1

数据库和资产

确保您的deployer.php路径设置正确

创建新的备份,然后保存远程数据库和资产dep savefromremote:latest

保存远程数据库和资产dep savefromremote

保存最新的备份,即昨晚的数据库dep savefromremote:db

保存最新的备份,即昨晚的资产dep savefromremote:assets

创建当前活动资产的临时副本,如果有转移问题,则回滚到此。 loadtoremote:assets

Docker

部署器自带ps docker镜像。

确保在docker-compose.yml中将- ~/.ssh:/tmp/.ssh:ro作为挂载卷包含在内

保留旧版本