Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Standardise modules #89

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
# Every Tuesday at 2:25pm UTC
schedule:
- cron: '25 14 * * 2'

jobs:
ci:
name: CI
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
vendor/
.DS_Store
.phpunit.result.cache
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

66 changes: 31 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# SSPak

[![Build Status](https://api.travis-ci.com/silverstripe/sspak.svg?branch=master)](https://travis-ci.com/silverstripe/sspak)
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe/sspak.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe/sspak)
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)

SSPak is a SilverStripe tool for managing database and assets content, for back-up, restoration, or transfer between
SSPak is a Silverstripe tool for managing database and assets content, for back-up, restoration, or transfer between
environments.

## The file format
Expand All @@ -15,9 +13,9 @@ An sspak file is either a Phar (executable) file or a Tar (non-executable) file,
* **assets.tar.gz:** A gzipped tar file containing all assets. The root directory within the tar file must be called "assets".
* **git-remote:** A text file of the following form:

remote = (url)
branch = (name)
sha = (sha-hash)
remote = (url)
branch = (name)
sha = (sha-hash)

By convention, the file should have the extension `.sspak` for non-executable versions, and `.sspak.phar` for executable versions.

Expand All @@ -35,106 +33,104 @@ You can install this package globally with Composer (ensure your composer bin is

If you have cURL, run this command (everything except for the `$>` part):

$> curl -sS https://silverstripe.github.io/sspak/install | php -- /usr/local/bin
$> curl -sS https://silverstripe.github.io/sspak/install | php -- /usr/local/bin

The final argument is the directory that the script will be loaded into. If omitted, the script will be installed into the current directory. If you don't have permission to write to the directory, "sudo" will be used to escalate permissions.

For example, this would also work:

$> cd /usr/local/bin
$> curl -sS https://silverstripe.github.io/sspak/install | sudo php
$> cd /usr/local/bin
$> curl -sS https://silverstripe.github.io/sspak/install | sudo php

### Manually

If you prefer not to use the installer, you can download the script and copy it to your executable path as follows:

$> wget https://silverstripe.github.io/sspak/sspak.phar
$> chmod +x sspak.phar
$> sudo mv sspak.phar /usr/local/bin/sspak

$> wget https://silverstripe.github.io/sspak/sspak.phar
$> chmod +x sspak.phar
$> sudo mv sspak.phar /usr/local/bin/sspak

## Common Issues

Creating archive disabled by the php.ini setting phar.readonly
Creating archive disabled by the php.ini setting phar.readonly

Set your phar.readonly setting to false in your php.ini (and php-cli.ini) files.


## Use

All sspak commands take the following general form.

$> sspak (command) (from) (to)
$> sspak (command) (from) (to)

Create an sspak file and save to /tmp:

$> sspak save /var/www /tmp/site.sspak
$> sspak save /var/www /tmp/site.sspak

Create an sspak file based on a remote site:

$> sspak save me@prodserver:/var/www prod-site.sspak
$> sspak save me@prodserver:/var/www prod-site.sspak

Create an sspak file based on a remote site using a specific private key to connect:

$> sspak save --identity=prodserver.key me@prodserver:/var/www prod-site.sspak
$> sspak save --identity=prodserver.key me@prodserver:/var/www prod-site.sspak

Create an executable sspak file by adding a phar extension:

$> sspak save me@prodserver:/var/www prod-site.sspak.phar
$> sspak save me@prodserver:/var/www prod-site.sspak.phar

Create an sspak from existing files:

$> sspak saveexisting --db=/path/to/database.sql --assets=/path/to/assets /tmp/site.sspak
$> sspak saveexisting --db=/path/to/database.sql --assets=/path/to/assets /tmp/site.sspak

Extract files from an existing sspak into the specified directory:

$> sspak extract /tmp/site.sspak /destination/path
$> sspak extract /tmp/site.sspak /destination/path

Load an sspak file into a local instance:

$> sspak load prod-site.sspak ~/Sites/devsite
$> sspak load prod-site.sspak ~/Sites/devsite

Load an sspak file into a local instance, dropping the existing DB first (mysql only):

$> sspak load prod-site.sspak ~/Sites/devsite --drop-db
$> sspak load prod-site.sspak ~/Sites/devsite --drop-db

Load an sspak file into a remote instance using a specific private key to connect:

$> sspak save --identity=backupserver.key prod-site.sspak me@backupserver:/var/www
$> sspak save --identity=backupserver.key prod-site.sspak me@backupserver:/var/www

Transfer in one step: *(not implemented yet)*

$> sspak transfer me@prodserver:/var/www ~/Sites/devsite
$> sspak transfer me@prodserver:/var/www ~/Sites/devsite

Sudo as www-data to perform the actions

$> sspak save --sudo=www-data me@prodserver:/var/www prod-site.sspak
$> sspak load --sudo=www1 prod-site.sspak ~/Sites/devsite
$> sspak transfer --from-sudo=www-data --to-sudo=www1 me@prodserver:/var/www ~/Sites/devsite
$> sspak save --sudo=www-data me@prodserver:/var/www prod-site.sspak
$> sspak load --sudo=www1 prod-site.sspak ~/Sites/devsite
$> sspak transfer --from-sudo=www-data --to-sudo=www1 me@prodserver:/var/www ~/Sites/devsite

Save only the database:

$> sspak save --db me@prodserver:/var/www dev.sspak
$> sspak save --db me@prodserver:/var/www dev.sspak

Load only the assets:

$> sspak load --assets dev.sspak ~/Sites/devsite
$> sspak load --assets dev.sspak ~/Sites/devsite

Install a new site from an sspak (needs to contain a git-remote):

$> sspak install newsite.sspak ~/Sites/newsite
$> sspak install newsite.sspak ~/Sites/newsite

Save all while using a custom TMP folder (make sure the folder exists and is writable):

$> TMPDIR="/tmp/my_custom_tmp" sspak save /var/www /tmp/site.sspak
$> TMPDIR="/tmp/my_custom_tmp" sspak save /var/www /tmp/site.sspak

## Caveats

If you don't have PKI passwordless log-in into remote servers, you will be asked for your log-in a few times.

## How it works

sspak relies on the SilverStripe executable code to determine database credentials. It does this by using a small script, sspak-sniffer.php, which it uploads to the /tmp folder of any remote servers.
sspak relies on the Silverstripe executable code to determine database credentials. It does this by using a small script, sspak-sniffer.php, which it uploads to the /tmp folder of any remote servers.

This script returns database credentials and the location of the assets path. Once it has that, it will remotely execute mysql, mysqldump and tar commands to archive or restore the content.

Expand Down
18 changes: 11 additions & 7 deletions bin/build-phar
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
<?php

// Root from which to refer to src/
if(!defined('PACKAGE_ROOT')) define('PACKAGE_ROOT', dirname(dirname(__FILE__)) . '/');
// if(!defined('PACKAGE_ROOT')) define('PACKAGE_ROOT', dirname(dirname(__FILE__)) . '/');

require_once(PACKAGE_ROOT . 'src/FilesystemEntity.php');
require_once(PACKAGE_ROOT . 'src/SSPakFile.php');
// require_once(PACKAGE_ROOT . 'src/FilesystemEntity.php');
// require_once(PACKAGE_ROOT . 'src/SSPakFile.php');

require 'vendor/autoload.php';

use SilverStripe\SSPak\SSPakFile;

if(empty($_SERVER['argv'][1])) {
$pharFile = dirname(dirname(__FILE__))."/build/sspak.phar";
$pharFile = dirname(dirname(__FILE__))."/build/sspak.phar";
} else {
$pharFile = $_SERVER['argv'][1];
$pharFile = $_SERVER['argv'][1];
}

if(!file_exists(dirname($pharFile))) {
echo "Creating directory " . dirname($pharFile) . "...\n";
mkdir(dirname($pharFile));
echo "Creating directory " . dirname($pharFile) . "...\n";
mkdir(dirname($pharFile));
}

echo "Building sspak executable $pharFile\n";
Expand Down
22 changes: 11 additions & 11 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ echo "Downloading...\n";
$sspak = file_get_contents("http://silverstripe.github.io/sspak/sspak.phar");

if(!empty($_SERVER['argv'][1])) {
$destFolderArg = $_SERVER['argv'][1];
$CLI_destFolderArg = escapeshellarg($destFolderArg);
// Rationalise destfolder (parse ~, etc)
$destFolder = trim(`cd $CLI_destFolderArg && pwd`);
if(!$destFolder) {
echo "ERROR: Can't find folder $destFolderArg!\n";
die();
}
$destFolderArg = $_SERVER['argv'][1];
$CLI_destFolderArg = escapeshellarg($destFolderArg);
// Rationalise destfolder (parse ~, etc)
$destFolder = trim(`cd $CLI_destFolderArg && pwd`);
if(!$destFolder) {
echo "ERROR: Can't find folder $destFolderArg!\n";
die();
}

} else {
$destFolder = getcwd();
$destFolder = getcwd();
}

// Write to /tmp
Expand All @@ -27,9 +27,9 @@ echo "Copying to " . realpath($destFolder) . "...";

// Write directly, or via sudo, depending on access writes
if(is_writable($destFolder)) {
rename("/tmp/sspak", "$destFolder/sspak");
rename("/tmp/sspak", "$destFolder/sspak");
} else {
passthru("sudo mv /tmp/sspak " . escapeshellarg($destFolder));
passthru("sudo mv /tmp/sspak " . escapeshellarg($destFolder));
}

echo"\nDone! Run 'sspak help' to get started.\n\n";
34 changes: 17 additions & 17 deletions bin/sspak
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

// Root from which to refer to src/
if (!defined('PACKAGE_ROOT')) {
define('PACKAGE_ROOT', dirname(dirname(__FILE__)) . '/');
define('PACKAGE_ROOT', dirname(dirname(__FILE__)) . '/');
}

// We only need composer once
if (!defined('SSPAK_COMPOSER_INSTALL') || !SSPAK_COMPOSER_INSTALL) {
require_once PACKAGE_ROOT . 'vendor/autoload.php';
require_once PACKAGE_ROOT . 'vendor/autoload.php';
}

require_once PACKAGE_ROOT . 'src/Args.php';
Expand All @@ -22,11 +22,11 @@ $argObj = new Args($_SERVER['argv']);
/*
// Special case for self-extracting sspaks
if($isSelfExtracting) {
$argObj->unshiftUnnamed('@self');
if(!in_array($argObj->getAction(), array("install", "load"))) {
echo "Self-extracting sspaks can only use 'install' and 'load' actions.\n";
exit(3);
}
$argObj->unshiftUnnamed('@self');
if(!in_array($argObj->getAction(), array("install", "load"))) {
echo "Self-extracting sspaks can only use 'install' and 'load' actions.\n";
exit(3);
}
}
*/

Expand All @@ -39,15 +39,15 @@ $action = strtolower($argObj->getAction());
if(!$action) $action = 'help';

if(isset($allowedActions[$action])) {
$method = $allowedActions[$action]['method'];
try {
$ssPak->$method($argObj);
} catch(Exception $e) {
echo $e->getMessage() . "\n";
exit(4);
}
$method = $allowedActions[$action]['method'];
try {
$ssPak->$method($argObj);
} catch(Exception $e) {
echo $e->getMessage() . "\n";
exit(4);
}
} else {
echo "Unrecognised action '" . $action . "'.\n";
$ssPak->help($argObj);
exit(3);
echo "Unrecognised action '" . $action . "'.\n";
$ssPak->help($argObj);
exit(3);
}
Loading