Skip to content

Commit

Permalink
Merge pull request #30 from Automattic/add/devcontainer
Browse files Browse the repository at this point in the history
chore: add dev container configuration
  • Loading branch information
sjinks authored Jan 7, 2025
2 parents b1e1f8b + 47a1c94 commit 9d2d2fc
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"features": {
"ghcr.io/automattic/vip-codespaces/entrypoints": {
"version": "1.0.0",
"resolved": "ghcr.io/automattic/vip-codespaces/entrypoints@sha256:b153687ebd808007d2d5355722ee952cfdc0ca26533b2e19f9547ccc3d440df3",
"integrity": "sha256:b153687ebd808007d2d5355722ee952cfdc0ca26533b2e19f9547ccc3d440df3"
},
"ghcr.io/automattic/vip-codespaces/mariadb": {
"version": "1.3.0",
"resolved": "ghcr.io/automattic/vip-codespaces/mariadb@sha256:3b6011b207c57103de397c8e231fc4a7faa9b476b9ff5caf0ebf0b1a68ac5575",
"integrity": "sha256:3b6011b207c57103de397c8e231fc4a7faa9b476b9ff5caf0ebf0b1a68ac5575"
},
"ghcr.io/automattic/vip-codespaces/nginx": {
"version": "1.3.0",
"resolved": "ghcr.io/automattic/vip-codespaces/nginx@sha256:4706f4cfc531fe259401ba3942b72a7701fc231c695329ddc332fd56198db797",
"integrity": "sha256:4706f4cfc531fe259401ba3942b72a7701fc231c695329ddc332fd56198db797"
},
"ghcr.io/automattic/vip-codespaces/php": {
"version": "2.5.1",
"resolved": "ghcr.io/automattic/vip-codespaces/php@sha256:d399a6b07be5532bfc3f1a8946d5d32329283027fb0843a3b583b44ac84b5f97",
"integrity": "sha256:d399a6b07be5532bfc3f1a8946d5d32329283027fb0843a3b583b44ac84b5f97"
},
"ghcr.io/automattic/vip-codespaces/wordpress": {
"version": "2.4.0",
"resolved": "ghcr.io/automattic/vip-codespaces/wordpress@sha256:238fb47a25a017b7fbe471cf14cdfb20e05e086a621260bf14956af85f9c17e7",
"integrity": "sha256:238fb47a25a017b7fbe471cf14cdfb20e05e086a621260bf14956af85f9c17e7"
},
"ghcr.io/automattic/vip-codespaces/wp-cli": {
"version": "1.1.3",
"resolved": "ghcr.io/automattic/vip-codespaces/wp-cli@sha256:53d86865b61f6448fa76ff1dfcfd304ff79c6836efe63e685a30263442a5f898",
"integrity": "sha256:53d86865b61f6448fa76ff1dfcfd304ff79c6836efe63e685a30263442a5f898"
},
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.0.12",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:183d18b42de353e3689615fd21eb67427bc1f763c5b830c2798dcbb993da2049",
"integrity": "sha256:183d18b42de353e3689615fd21eb67427bc1f763c5b830c2798dcbb993da2049"
}
}
}
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:1-1.22-bookworm",
"forwardPorts": [80, 4444],
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/automattic/vip-codespaces/entrypoints": {},
"ghcr.io/automattic/vip-codespaces/nginx": {},
"ghcr.io/automattic/vip-codespaces/mariadb": {},
"ghcr.io/automattic/vip-codespaces/php": {
"lite-install": true,
"skip-gmagick": true
},
"ghcr.io/automattic/vip-codespaces/wp-cli": {},
"ghcr.io/automattic/vip-codespaces/wordpress": {},
"./local-features/cron-runner-environment": {}
},
"customizations": {
"vscode": {
"extensions": [
"dlech.chmod",
"zhiayang.tabindentspacealign",
"GitHub.copilot",
"GitHub.copilot-chat",
"github.vscode-github-actions",
"ms-vsliveshare.vsliveshare"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/usr/local/bin/wp plugin install --activate https://github.com/Automattic/Cron-Control/archive/refs/tags/3.1.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "cron-runner-environment",
"version": "1.0.0",
"name": "Cron Runner Environment",
"installsAfter": [
"ghcr.io/automattic/vip-codespaces/nginx",
"ghcr.io/automattic/vip-codespaces/wordpress"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace WPCLI\FPM;
error_reporting( 0 );

if ( isset( $_POST['payload'] ) ) {
$payload_str = $_POST['payload'];
unset( $_POST['payload'] );
} elseif ( isset ( $_GET['payload'] ) ) {
$payload_str = $_GET['payload'];
unset( $_GET['payload'] );
} else {
header( 'Status: 400 Bad Request' );
header( 'Content-Type: text/plain' );
echo 'no payload given' . "\n";
exit( 1 );
}

try {
$payload = json_decode( $payload_str, null, 512, JSON_THROW_ON_ERROR | JSON_OBJECT_AS_ARRAY );
if ( ! is_array( $payload ) ) {
throw new \Exception( "not a json array" );
}
} catch ( \Exception $e ) {
header( 'Status: 400 Bad Request' );
header( 'Content-Type: text/plain' );
echo 'payload cannot be decoded as json: ' . $e->getMessage() . "\n";
exit( 1 );
}

array_unshift( $payload, '/usr/local/bin/wp' );

global $_SERVER;
$_SERVER['argv'] = $payload;
$_SERVER['SCRIPT_NAME'] = '/usr/local/bin/wp';
$_SERVER['SCRIPT_FILENAME'] = '/usr/local/bin/wp';
unset( $_SERVER['FCGI_ROLE'] );
unset( $_SERVER['GATEWAY_INTERFACE'] );
unset( $_SERVER['QUERY_STRING'] );
unset( $_SERVER['REQUEST_METHOD'] );

global $_ENV;
$_ENV['SCRIPT_NAME'] = '/usr/local/bin/wp';
$_ENV['SCRIPT_FILENAME'] = '/usr/local/bin/wp';
unset( $_ENV['FCGI_ROLE'] );
unset( $_ENV['GATEWAY_INTERFACE'] );
unset( $_ENV['QUERY_STRING'] );
unset( $_ENV['REQUEST_METHOD'] );

global $argv;
$argv = $payload;

$outfh = tmpfile();
$errfh = tmpfile();

register_shutdown_function( function () use ( $outfh, $errfh ) {
$result = [
'buf' => ob_get_contents(),
];
ob_end_clean();
fseek( $outfh, 0 );
$result['stdout'] = stream_get_contents( $outfh );
fclose( $outfh );
fseek( $errfh, 0 );
$result['stderr'] = stream_get_contents( $errfh );
fclose( $errfh );
header( 'Status: 200 OK' );
header( 'Content-Type: application/json' );
echo json_encode( $result );
} );

define( 'WP_CLI_ROOT', 'phar:///usr/local/bin/wp.phar/vendor/wp-cli/wp-cli' );
define( 'STDIN', fopen( '/dev/null', 'r' ) );
define( 'STDOUT', $outfh );
define( 'STDERR', $errfh );

ob_start();

require_once WP_CLI_ROOT . '/php/wp-cli.php';

exit( 0 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

install -D -m 0644 -o root -g root fpm-cron-runner.php /var/wpvip/fpm-cron-runner.php
install -m 0755 -o root -g root cron-runner-postinstall.sh /var/lib/wordpress/postinstall.d/cron-runner-postinstall
rm -rf /var/www/*
ln -sf /wp /var/www/html
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: devcontainers
directory: "/"
schedule:
interval: weekly

0 comments on commit 9d2d2fc

Please sign in to comment.