Skip to content
Merged
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
22 changes: 22 additions & 0 deletions recipe/provision/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{domain}} {

root * {{deploy_path}}/current/{{public_path}}
file_server
php_fastcgi * unix//run/php/php{{php_version}}-fpm.sock {
resolve_root_symlink
}

log {
output file {{deploy_path}}/log/access.log
}

handle_errors {
@404 {
expression {http.error.status_code} == 404
}
rewrite @404 /404.html
file_server {
root /var/dep/html
}
}
}
40 changes: 7 additions & 33 deletions recipe/provision/website.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,17 @@

desc('Provision website');
task('provision:website', function () {
set('deploy_path', run("realpath {{deploy_path}}"));

run("[ -d {{deploy_path}} ] || mkdir -p {{deploy_path}}");
run("chown -R deployer:deployer {{deploy_path}}");

$domain = get('domain');
$phpVersion = get('php_version');
$deployPath = run("realpath {{deploy_path}}");
$publicPath = get('public_path');

cd($deployPath);
cd('{{deploy_path}}');

run("[ -d log ] || mkdir log");
run("chgrp caddy log");

$caddyfile = <<<EOF
$domain {

\troot * $deployPath/current/$publicPath
\tfile_server
\tphp_fastcgi * unix//run/php/php$phpVersion-fpm.sock {
\t\tresolve_root_symlink
\t}

\tlog {
\t\toutput file $deployPath/log/access.log
\t}

\thandle_errors {
\t\t@404 {
\t\t\texpression {http.error.status_code} == 404
\t\t}
\t\trewrite @404 /404.html
\t\tfile_server {
\t\t\troot /var/dep/html
\t\t}
\t}
}
EOF;
$caddyfile = parse(file_get_contents('./Caddyfile'));

if (test('[ -f Caddyfile ]')) {
run("echo $'$caddyfile' > Caddyfile.new");
Expand All @@ -68,12 +42,12 @@
run("echo $'$caddyfile' > Caddyfile");
}

if (!test("grep -q 'import $deployPath/Caddyfile' /etc/caddy/Caddyfile")) {
run("echo 'import $deployPath/Caddyfile' >> /etc/caddy/Caddyfile");
if (!test("grep -q 'import {{deploy_path}}/Caddyfile' /etc/caddy/Caddyfile")) {
run("echo 'import {{deploy_path}}/Caddyfile' >> /etc/caddy/Caddyfile");
}
run('service caddy reload');

info("Website $domain configured!");
info("Website {{domain}} configured!");
})->limit(1);

desc('Shows caddy logs');
Expand Down