Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Feature/use new snapshots #339

Merged
merged 8 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cd ~/.ssh
cp /mnt/c/Users/USER-NAME/.ssh/id_rsa* .
```
##### HTTPS on Windows
If https is not working in the browsers on Windows you will need to setup a shared root certificate.
If https is not working in the browsers on Windows you will need to setup a shared root certificate.
You will need [mkcert installed](https://github.com/FiloSottile/mkcert) inside WSL2 machine. With `mkcert` installed run:

```bash
Expand Down Expand Up @@ -247,7 +247,7 @@ In the ElasticPress settings, you should enter `http://<hostname>/__elasticsearc

### WP Snapshots

See the section on [using WP Snapshots](#user-content-wpsnapshots)
See the section on [using Snapshots](#user-content-snapshots)

### Running WP CLI Commands

Expand Down Expand Up @@ -436,30 +436,33 @@ Make sure your IDE is listening for PHP debug connections and set up a path mapp
]
```

#### WPsnapshots
#### Snapshots

As of version x.x.x of WP Local Docker, the snapshot system has switched from the old [WP Snapshots](https://github.com/10up/wpsnapshots) system, to the new [Snapshots](https://github.com/10up/snapshots) WP-CLI command.
Whilst the public API and configuration has stayed the same, the new system is much more robust and allows for features to be more easily added in the future.

##### Configuration

If you have not used [WP Snapshots](https://github.com/10up/wpsnapshots) with [WP Local Docker](https://github.com/10up/wp-local-docker-v2) yet, you'll first need to configure WP Snapshots with your AWS
credentials. To configure, run `10updocker wpsnapshots configure <repository>` (e.g. `10updocker wpsnapshots configure 10up`). You will then be prompted to enter
If you have not used [Snapshots](https://github.com/10up/snapshots) with [WP Local Docker](https://github.com/10up/wp-local-docker-v2) yet, you'll first need to configure Snapshots with your AWS
credentials. To configure, run `10updocker wp snapshots configure <repository>` (e.g. `10updocker wp snapshots configure 10up`). You will then be prompted to enter
your AWS credentials and a few other configuration details. Once complete, the configuration will be available across
all of your WP Local Docker environments.

##### Pulling an Environment

`10updocker wpsnapshots pull <snapshot-id>` This command pulls an existing snapshot from the repository into your current
`10updocker wp snapshots pull <snapshot-id>` This command pulls an existing snapshot from the repository into your current
environment, replacing your database and wp-content. This command must be run from withing your environment directory
(by default, this is somewhere within `~/wp-local-docker-sites/<environment>/`).

##### Searching for an Environment

`10updocker wpsnapshots search <search-term>` with searches the repository for snapshots. `<search-text>` will be
`10updocker wp snapshots search <search-term>` with searches the repository for snapshots. `<search-text>` will be
compared against project names and authors. Searching for "*" will return all snapshots.

##### Other Commands

`10updocker wpsnapshots <command>` is the general form for all WP Snapshots commands. `<command>` is passed directly to
WP Snapshots, so any command that WP Snapshots accepts will work in this form. Any command that requires a WordPress
`10updocker wp snapshots <command>` is the general form for all Snapshots commands. `<command>` is passed directly to
Snapshots, so any command that Snapshots accepts will work in this form. Any command that requires a WordPress
environment (pull, create, etc) needs to be run from somewhere within an environment directory (by default, this is
somewhere within `~/wp-local-docker-sites/<environment>/`).

Expand Down Expand Up @@ -570,6 +573,26 @@ Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using

For best results we recommend using the default port configuration whenever possible.

### I've upgraded WP Local Docker from a previous version and now the wpsnapshots command isn't working

This is likely to do with the change from the [WP Snapshots](https://github.com/10up/wpsnapshots) system, to the new [Snapshots](https://github.com/10up/snapshots) WP-CLI command.
This update removed the need for a dedicated container for the snapshots system, and instead uses the `phpfpm` container.
Because of this, we need to ensure that the `phpfpm` container has access to the `~/.wpsnapshots` and `~/.aws` directories on your host machine.

To provide that access, please edit the `docker-compose.yml` file in the environment you are updating, to add the following lines:

```yaml
phpfpm:
image: '10up/wp-php-fpm-dev:7.4-ubuntu'
# ...
volumes:
# ...
- '~/.wpsnapshots:/home/www-data/.wpsnapshots:cached'
- '~/.aws:/home/www-data/.aws:cached'
darylldoyle marked this conversation as resolved.
Show resolved Hide resolved
```

You'll then need to stop and start the environment for the changes to take effect.

---

## Support Level
Expand Down
158 changes: 0 additions & 158 deletions src/commands/clone/pull-snapshot.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/commands/create/make-docker-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const slugify = require( '@sindresorhus/slugify' );

const { cacheVolume } = require( '../../env-utils' );
const { images } = require( '../../docker-images' );
const config = require( '../../configure' );

module.exports = function makeDockerCompose( spinner ) {
return async ( hosts, settings ) => {
Expand All @@ -24,6 +25,8 @@ module.exports = function makeDockerCompose( spinner ) {
const { type: wordpressType } = wordpress || {};
const allHosts = [ ...hosts, ...hosts.map( ( host ) => `*.${ host }` ) ];

const wpsnapshotsDir = await config.get( 'snapshotsPath' );

const baseConfig = {
// use version 2 so we can use limits
version: '2.2',
Expand Down Expand Up @@ -89,6 +92,8 @@ module.exports = function makeDockerCompose( spinner ) {
if ( platform() == 'linux' ) {
baseConfig.services.phpfpm.image = `wp-php-fpm-dev-${ phpVersion }-${ slugify( process.env.USER ) }`;
baseConfig.services.phpfpm.volumes.push( `~/.ssh:/home/${ process.env.USER }/.ssh:cached` );
baseConfig.services.phpfpm.volumes.push( `${ wpsnapshotsDir }:/home/${ process.env.USER }/.wpsnapshots:cached` );
baseConfig.services.phpfpm.volumes.push( `~/.aws:/home/${ process.env.USER }/.aws:cached` );
darylldoyle marked this conversation as resolved.
Show resolved Hide resolved
baseConfig.services.phpfpm.build = {
dockerfile: 'php-fpm',
context: '.containers',
Expand All @@ -101,6 +106,8 @@ module.exports = function makeDockerCompose( spinner ) {
} else {
// the official containers for this project will have a www-data user.
baseConfig.services.phpfpm.volumes.push( '~/.ssh:/home/www-data/.ssh:cached' );
baseConfig.services.phpfpm.volumes.push( `${ wpsnapshotsDir }:/home/www-data/.wpsnapshots:cached` );
baseConfig.services.phpfpm.volumes.push( '~/.aws:/home/www-data/.aws:cached' );
}

let nginxConfig = 'default.conf';
Expand Down
70 changes: 48 additions & 22 deletions src/commands/wpsnapshots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const makeDocker = require( '../utils/make-docker' );
const { execSync } = require( 'child_process' );

const makeCommand = require( '../utils/make-command' );
const makeSpinner = require( '../utils/make-spinner' );
const runSnapshots = require( '../utils/run-snapshots' );
const shellEscape = require( 'shell-escape' );
const envUtils = require( '../env-utils' );
const gateway = require( '../gateway' );
const environment = require( '../environment' );
const compose = require( '../utils/docker-compose' );

exports.command = 'wpsnapshots <cmd..>';
exports.aliases = [ 'snapshots' ];
Expand All @@ -14,33 +19,54 @@ exports.builder = function( yargs ) {
} );
};

exports.handler = makeCommand( async function( { _, env, verbose } ) {
exports.handler = makeCommand( async function( { env, verbose } ) {
let envSlug = env;
if ( ! envSlug ) {
envSlug = await envUtils.parseOrPromptEnv();
}

if ( envSlug === false ) {
throw new Error( 'Error: Unable to determine which environment to use snapshots with. Please run this command from within your environment\'s directory.' );
}

const envPath = await envUtils.envPath( envSlug );
const spinner = ! verbose ? makeSpinner() : undefined;

// Get everything after the snapshots command, so we can pass to the docker container
let wpsnapshotsCommand = false;
const command = [];
// Check if the container is running, otherwise, start up the stacks
const isRunning = await compose.isRunning( envPath );
if ( ! isRunning ) {
spinner && spinner.info( 'Environment is not running, starting it...' );
await gateway.startGlobal( spinner );
await environment.start( envSlug, spinner );
}

// Compose wp-cli command to run
let snapshotCommand = false;
const command = [
'wp',
'snapshots',
];
for ( let i = 0; i < process.argv.length; i++ ) {
if ( process.argv[i].toLowerCase() === _[0] ) {
wpsnapshotsCommand = true;
} else if ( wpsnapshotsCommand ) {
if ( process.argv[i].toLowerCase() === 'wpsnapshots' || process.argv[i].toLowerCase() === 'snapshots' ) {
snapshotCommand = true;
continue;
}

if ( snapshotCommand ) {
command.push( process.argv[i] );
}
}

try {
const docker = makeDocker();
const wpsnapshots = runSnapshots( spinner, docker );
await wpsnapshots( env, command, 'inherit' );
} catch ( err ) {
if ( spinner ) {
if ( spinner.isSpinning ) {
spinner.stop();
}

spinner.fail( err );
} else {
console.error( err );
}
// Check for TTY
const ttyFlag = process.stdin.isTTY ? '' : ' -T';

// Run the command
execSync( `docker-compose exec${ ttyFlag } phpfpm ${ shellEscape( command ) }`, {
stdio: 'inherit',
cwd: envPath
} );
} catch {
// do nothing
}
} );
1 change: 0 additions & 1 deletion src/docker-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports.images = {
'php7.1': '10up/wp-php-fpm-dev:7.1-ubuntu',
'php7.0': '10up/wp-php-fpm-dev:7.0-ubuntu',
'php5.6': '10up/wp-php-fpm-dev:5.6-ubuntu',
wpsnapshots: '10up/wpsnapshots:2',
memcached: 'memcached:latest',
nginx: 'nginx:latest',
elasticsearch: 'docker.elastic.co/elasticsearch/elasticsearch:7.9.3',
Expand Down
Loading