Esempio n. 1
0
$app->post('/deploy/{service}', function (Application $app, Request $request, $service) {
    if (isset($app['config'][$service])) {
        $config = $app['config'][$service];
        $secret = $request->get("secret");
        if ($secret != $config['secret']) {
            return new Response("Forbidden", 403, array('Content-Type' => 'text/plain'));
        }
        $deployer = new Deployer($service, $config);
        $stream = function () use($deployer, $request) {
            $deployer->deploy($request);
        };
        return $app->stream($stream, 200, array('Content-Type' => 'text/plain'));
    }
    return "ERROR: missing service: " . $service;
});
$app->post('/rollback/{service}', function (Application $app, Request $request, $service) {
    if (isset($app['config'][$service])) {
        $config = $app['config'][$service];
        $secret = $request->get("secret");
        if ($secret != $config['secret']) {
            return new Response("Forbidden", 403, array('Content-Type' => 'text/plain'));
        }
        $deployer = new Deployer($service, $config);
        $deployer->recursive_unlink($config['current_path']);
        if (!@rename($config['old_path'], $config['current_path'])) {
            $deployer->recurse_copy($config['old_path'], $config['current_path']);
        }
        return "Done!";
    }
});
$app->run();