-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Envoy.blade.php
99 lines (81 loc) · 2.68 KB
/
Envoy.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@setup
require __DIR__."/vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$userAndServer = explode(',', $_ENV["ENVOY_USER_AND_SERVER"]);
$repository = "anonaddy/addy.io";
$baseDir = $_ENV["ENVOY_BASE_DIR"];
$releasesDir = "{$baseDir}/releases";
$currentDir = "{$baseDir}/current";
$newReleaseName = date("Ymd-His");
$newReleaseDir = "{$releasesDir}/{$newReleaseName}";
function logMessage($message) {
return "echo '\033[32m" .$message. "\033[0m';\n";
}
@endsetup
@servers(["local" => "127.0.0.1", "remote" => $userAndServer])
@story("deploy")
startDeployment
cloneRepository
runComposer
runNpm
generateAssets
cleanOldReleases
finishDeploy
@endstory
@story("deploy-rollback")
deploymentRollback
@endstory
@task("startDeployment", ["on" => "local"])
{{ logMessage("🏃 Starting deployment...") }}
@endtask
@task("cloneRepository", ["on" => "remote"])
{{ logMessage("🌀 Cloning repository...") }}
[ -d {{ $releasesDir }} ] || mkdir {{ $releasesDir }}
cd {{ $releasesDir }}
# Create the release dir
mkdir {{ $newReleaseDir }}
# Clone the repo
git clone --depth 1 [email protected]:{{ $repository }} {{ $newReleaseName }}
# Configure sparse checkout
cd {{ $newReleaseDir }}
git config core.sparsecheckout true
echo "*" > .git/info/sparse-checkout
echo "!storage" >> .git/info/sparse-checkout
echo "!public/build" >> .git/info/sparse-checkout
git read-tree -mu HEAD
@endtask
@task("runComposer", ["on" => "remote"])
{{ logMessage("🚚 Running Composer...") }}
cd {{ $newReleaseDir }}
composer install --prefer-dist --no-scripts --no-dev -q -o
@endtask
@task("runNpm", ["on" => "remote"])
{{ logMessage("📦 Running Npm...") }}
cd {{ $newReleaseDir }}
npm install --no-progress &> /dev/null
@endtask
@task("generateAssets", ["on" => "remote"])
{{ logMessage("🌅 Generating assets...") }}
cd {{ $newReleaseDir }}
npm run prod --no-progress &> /dev/null
# Mark release
cd {{ $newReleaseDir }}
echo "{{ $newReleaseName }}" > build_production/release-name.txt
ln -nfs {{ $newReleaseDir }} {{ $currentDir }}
@endtask
@task("cleanOldReleases", ["on" => "remote"])
{{ logMessage("🚾 Cleaning up old releases...") }}
# Delete all but the 3 most recent.
cd {{ $releasesDir }}
ls -dt {{ $releasesDir }}/* | tail -n +4 | xargs -d "\n" chown -R deployer .
ls -dt {{ $releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf
@endtask
@task("finishDeploy", ["on" => "local"])
{{ logMessage("🚀 Application deployed!") }}
@endtask
@task("deploymentRollback")
cd {{ $releasesDir }}
ln -nfs {{ $releasesDir }}/$(find . -maxdepth 1 -name "20*" | sort | tail -n 2 | head -n1) {{ $baseDir }}/current
echo "Rolled back to $(find . -maxdepth 1 -name "20*" | sort | tail -n 2 | head -n1)"
@endtask