-
Notifications
You must be signed in to change notification settings - Fork 14
/
deploy.php
148 lines (111 loc) · 3.54 KB
/
deploy.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Deployer;
require 'recipe/common.php';
require 'vendor/studio24/deployer-recipes/all.php';
/**
* Deployment configuration variables - set on a per-project basis
*/
// Friendly project name
$project_name = 'W3C Design System documentation website';
// The repo for the project
$repository = '[email protected]:w3c/w3c-website-templates-bundle.git';
/**
* Apply configuration to Deployer
*
* Don't edit beneath here unless you know what you're doing!
*/
set('application', $project_name);
set('repository', $repository);
set('http_user', 'apache');
set('webroot', '');
set('keep_releases', 10);
set('git_tty', true);
set('allow_anonymous_stats', false);
// Folder to help build clean copy of design system site
set('build_root', getenv('HOME') . '/.deployer');
// Default stage - prevents accidental deploying to production with dep deploy
set('default_stage', 'staging');
/**
* Hosts
*/
host('production')
->stage('production')
->hostname('proteus.w3.internal')
->user('studio24')
->set('deploy_path','/srv/design-system.w3.org')
->set('url', 'https://design-system.w3.org/');
host('staging')
->stage('staging')
->hostname('proteus.w3.internal')
->user('studio24')
->set('deploy_path','/srv/staging-design-system.w3.org')
->set('url', 'https://staging-design-system.w3.org/');
/**
* Deployment task
* The task that will be run when using dep deploy
*/
desc('Deploy ' . get('application'));
task('deploy', [
// Check that we are using local deployer
's24:check-local-deployer',
// Run initial checks
'deploy:info',
's24:check-branch',
's24:display-disk-space',
// Request confirmation to continue (default N)
's24:confirm-continue',
// Deploy site
'deploy:prepare',
'deploy:lock',
'deploy:release',
'local:build',
'deploy:update_code',
// Build complete, deploy is live once deploy:symlink runs
'deploy:symlink',
// Cleanup
'deploy:unlock',
'cleanup',
'success'
]);
// Build tasks
desc('Build Design System website');
task('local:build', function () {
// Set local Deployment directory
$buildRoot = get('build_root');
// Create local Deployment directory
if (!file_exists($buildRoot)) {
writeln('Creating Deployment Directory');
mkdir($buildRoot);
} else {
writeln('Deployment Directory exists, skipping');
}
// Set project root directory for build
$buildPath = $buildRoot.'/'.run('basename {{repository}} .git');
// Remove previous local build
if (!file_exists($buildPath)) {
writeln('No previous build');
} else {
run('rm -rf '.$buildPath);
writeln('Removed previous build');
}
writeln('Cloning Repository (Branch: <info>{{branch}}</info>)');
// Clone the required branch to the local build directory
run('git clone --single-branch --branch {{branch}} {{repository}} '.$buildPath);
writeln('Clone complete');
cd($buildPath);
// Install PHP packages
run('composer install');
// Build site
writeln('Build Design System website');
run('./vendor/bin/design-system');
writeln('Build complete.');
})->local();
desc('Copy static website files to remote server');
task('deploy:update_code', function () {
$buildRoot = get('build_root');
$directory = run('basename {{repository}} .git');
writeln("<info>Uploading files to server</info>");
upload($buildRoot.'/'.$directory.'/_dist/', '{{release_path}}');
});
// Add unlock to failed deployment event.
after('deploy:failed', 'deploy:unlock');