|
2 | 2 |
|
3 | 3 | namespace Deployer;
|
4 | 4 |
|
5 |
| -require 'recipe/common.php'; |
6 |
| -require 'vendor/studio24/deployer-recipes/all.php'; |
7 |
| - |
8 | 5 | /**
|
9 |
| - * Deployment configuration variables - set on a per-project basis |
| 6 | + * 1. Deployer recipes we are using for this website |
10 | 7 | */
|
| 8 | +require 'vendor/studio24/deployer-recipes/recipe/static.php'; |
11 | 9 |
|
12 |
| -// Friendly project name |
13 |
| -$project_name = 'W3C Design System documentation website'; |
14 |
| - |
15 |
| -// The repo for the project |
16 |
| -$repository = '[email protected]:w3c/w3c-website-templates-bundle.git'; |
17 | 10 |
|
18 | 11 | /**
|
19 |
| - * Apply configuration to Deployer |
20 |
| - * |
21 |
| - * Don't edit beneath here unless you know what you're doing! |
| 12 | + * 2. Deployment configuration variables |
22 | 13 | */
|
23 | 14 |
|
24 |
| -set('application', $project_name); |
25 |
| -set('repository', $repository); |
| 15 | +// Project name |
| 16 | +set('application', 'W3C Design System documentation website'); |
| 17 | + |
| 18 | +// Git repo |
| 19 | +set( 'repository', '[email protected]:w3c/w3c-website-templates-bundle.git'); |
| 20 | + |
| 21 | +// Filesystem volume we're deploying to |
| 22 | +set('disk_space_filesystem', '/dev/nvme1n1'); |
| 23 | + |
| 24 | +// Default deployment and HTTP users |
| 25 | +set('remote_user', 'studio24'); |
26 | 26 | set('http_user', 'apache');
|
27 |
| -set('webroot', ''); |
28 | 27 | set('keep_releases', 10);
|
29 |
| -set('git_tty', true); |
30 |
| -set('allow_anonymous_stats', false); |
31 |
| - |
32 |
| -// Folder to help build clean copy of design system site |
33 |
| -set('build_root', getenv('HOME') . '/.deployer'); |
34 | 28 |
|
35 | 29 | // Default stage - prevents accidental deploying to production with dep deploy
|
36 |
| -set('default_stage', 'staging'); |
| 30 | +set('default_selector', 'stage=staging'); |
| 31 | + |
| 32 | +// Directory that contains built website files |
| 33 | +set("build_folder", "_dist"); |
| 34 | + |
| 35 | +// Build commands for static site |
| 36 | +task('local_build', function() { |
| 37 | + runLocally("composer install"); |
| 38 | + runLocally("./vendor/bin/design-system"); |
| 39 | +}); |
37 | 40 |
|
38 | 41 | /**
|
39 |
| - * Hosts |
| 42 | + * 3. Hosts |
40 | 43 | */
|
41 | 44 |
|
| 45 | +localhost('local'); |
| 46 | + |
42 | 47 | host('production')
|
43 |
| - ->stage('production') |
44 |
| - ->hostname('proteus.w3.internal') |
45 |
| - ->user('studio24') |
| 48 | + ->set('labels', ['stage' => 'production']) |
| 49 | + ->set('hostname', 'proteus.w3.internal') |
| 50 | + ->set('remote_user', 'studio24') |
46 | 51 | ->set('deploy_path','/srv/design-system.w3.org')
|
47 | 52 | ->set('url', 'https://design-system.w3.org/');
|
48 | 53 |
|
49 | 54 | host('staging')
|
50 |
| - ->stage('staging') |
51 |
| - ->hostname('proteus.w3.internal') |
52 |
| - ->user('studio24') |
| 55 | + ->set('labels', ['stage' => 'staging']) |
| 56 | + ->set('hostname', 'proteus.w3.internal') |
| 57 | + ->set('remote_user', 'studio24') |
53 | 58 | ->set('deploy_path','/srv/staging-design-system.w3.org')
|
54 | 59 | ->set('url', 'https://staging-design-system.w3.org/');
|
55 |
| - |
56 |
| -/** |
57 |
| - * Deployment task |
58 |
| - * The task that will be run when using dep deploy |
59 |
| - */ |
60 |
| - |
61 |
| -desc('Deploy ' . get('application')); |
62 |
| -task('deploy', [ |
63 |
| - |
64 |
| - // Check that we are using local deployer |
65 |
| - 's24:check-local-deployer', |
66 |
| - |
67 |
| - // Run initial checks |
68 |
| - 'deploy:info', |
69 |
| - 's24:check-branch', |
70 |
| - 's24:display-disk-space', |
71 |
| - |
72 |
| - // Request confirmation to continue (default N) |
73 |
| - 's24:confirm-continue', |
74 |
| - |
75 |
| - // Deploy site |
76 |
| - 'deploy:prepare', |
77 |
| - 'deploy:lock', |
78 |
| - 'deploy:release', |
79 |
| - 'local:build', |
80 |
| - 'deploy:update_code', |
81 |
| - |
82 |
| - // Build complete, deploy is live once deploy:symlink runs |
83 |
| - 'deploy:symlink', |
84 |
| - |
85 |
| - // Cleanup |
86 |
| - 'deploy:unlock', |
87 |
| - 'cleanup', |
88 |
| - 'success' |
89 |
| -]); |
90 |
| - |
91 |
| -// Build tasks |
92 |
| -desc('Build Design System website'); |
93 |
| -task('local:build', function () { |
94 |
| - |
95 |
| - // Set local Deployment directory |
96 |
| - $buildRoot = get('build_root'); |
97 |
| - |
98 |
| - // Create local Deployment directory |
99 |
| - if (!file_exists($buildRoot)) { |
100 |
| - writeln('Creating Deployment Directory'); |
101 |
| - mkdir($buildRoot); |
102 |
| - } else { |
103 |
| - writeln('Deployment Directory exists, skipping'); |
104 |
| - } |
105 |
| - |
106 |
| - // Set project root directory for build |
107 |
| - $buildPath = $buildRoot.'/'.run('basename {{repository}} .git'); |
108 |
| - |
109 |
| - // Remove previous local build |
110 |
| - if (!file_exists($buildPath)) { |
111 |
| - writeln('No previous build'); |
112 |
| - } else { |
113 |
| - run('rm -rf '.$buildPath); |
114 |
| - writeln('Removed previous build'); |
115 |
| - } |
116 |
| - |
117 |
| - writeln('Cloning Repository (Branch: <info>{{branch}}</info>)'); |
118 |
| - |
119 |
| - // Clone the required branch to the local build directory |
120 |
| - run('git clone --single-branch --branch {{branch}} {{repository}} '.$buildPath); |
121 |
| - writeln('Clone complete'); |
122 |
| - |
123 |
| - cd($buildPath); |
124 |
| - |
125 |
| - // Install PHP packages |
126 |
| - run('composer install'); |
127 |
| - |
128 |
| - // Build site |
129 |
| - writeln('Build Design System website'); |
130 |
| - run('./vendor/bin/design-system'); |
131 |
| - |
132 |
| - writeln('Build complete.'); |
133 |
| - |
134 |
| -})->local(); |
135 |
| - |
136 |
| -desc('Copy static website files to remote server'); |
137 |
| -task('deploy:update_code', function () { |
138 |
| - |
139 |
| - $buildRoot = get('build_root'); |
140 |
| - $directory = run('basename {{repository}} .git'); |
141 |
| - |
142 |
| - writeln("<info>Uploading files to server</info>"); |
143 |
| - upload($buildRoot.'/'.$directory.'/_dist/', '{{release_path}}'); |
144 |
| -}); |
145 |
| - |
146 |
| -// Add unlock to failed deployment event. |
147 |
| -after('deploy:failed', 'deploy:unlock'); |
148 |
| - |
0 commit comments