|
2 | 2 |
|
3 | 3 | namespace Deployer;
|
4 | 4 |
|
5 |
| -require 'recipe/common.php'; |
6 |
| -require 'vendor/studio24/deployer-recipes/recipe/common.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/default.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 | +// Default deployment and HTTP users |
| 22 | +set('remote_user', 'studio24'); |
26 | 23 | set('http_user', 'apache');
|
27 | 24 | set('webroot', '');
|
28 | 25 | set('keep_releases', 10);
|
29 |
| -set('git_tty', true); |
30 |
| -set('allow_anonymous_stats', false); |
31 | 26 |
|
32 | 27 | // Folder to help build clean copy of design system site
|
33 | 28 | set('build_root', getenv('HOME') . '/.deployer');
|
34 | 29 |
|
35 | 30 | // Default stage - prevents accidental deploying to production with dep deploy
|
36 |
| -set('default_stage', 'staging'); |
| 31 | +set('default_selector', 'stage=staging'); |
| 32 | + |
37 | 33 |
|
38 | 34 | /**
|
39 |
| - * Hosts |
| 35 | + * 3. Hosts |
40 | 36 | */
|
41 | 37 |
|
| 38 | +localhost('local'); |
| 39 | + |
42 | 40 | host('production')
|
43 | 41 | ->set('labels', ['stage' => 'production'])
|
44 | 42 | ->set('hostname', 'proteus.w3.internal')
|
|
53 | 51 | ->set('deploy_path','/srv/staging-design-system.w3.org')
|
54 | 52 | ->set('url', 'https://staging-design-system.w3.org/');
|
55 | 53 |
|
| 54 | + |
56 | 55 | /**
|
57 |
| - * Deployment task |
58 |
| - * The task that will be run when using dep deploy |
| 56 | + * 4. Deployment tasks |
59 | 57 | */
|
60 | 58 |
|
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 |
| 59 | +// Overwrite deploy:prepare to build and upload static site |
| 60 | +desc('Prepares a new release'); |
| 61 | +task('deploy:prepare', [ |
68 | 62 | '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', |
| 63 | + 'deploy:setup', |
77 | 64 | 'deploy:lock',
|
78 | 65 | 'deploy:release',
|
79 | 66 | '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' |
| 67 | + 'deploy:update_code' |
89 | 68 | ]);
|
90 | 69 |
|
| 70 | + |
91 | 71 | // Build tasks
|
92 | 72 | desc('Build Design System website');
|
93 | 73 | task('local:build', function () {
|
94 | 74 |
|
95 | 75 | // Set local Deployment directory
|
96 | 76 | $buildRoot = get('build_root');
|
97 | 77 |
|
| 78 | + // Set project root directory for build |
| 79 | + $buildPath = $buildRoot.'/'.run('basename {{repository}} .git'); |
| 80 | + |
98 | 81 | // Create local Deployment directory
|
99 |
| - if (!file_exists($buildRoot)) { |
| 82 | + if (!file_exists($buildPath)) { |
100 | 83 | writeln('Creating Deployment Directory');
|
101 |
| - mkdir($buildRoot); |
| 84 | + mkdir($buildPath, recursive: true); |
102 | 85 | } else {
|
103 | 86 | writeln('Deployment Directory exists, skipping');
|
104 | 87 | }
|
105 | 88 |
|
106 |
| - // Set project root directory for build |
107 |
| - $buildPath = $buildRoot.'/'.run('basename {{repository}} .git'); |
108 |
| - |
109 | 89 | // Remove previous local build
|
110 |
| - if (!file_exists($buildPath)) { |
| 90 | + if (!file_exists($buildPath . '/README.md')) { |
111 | 91 | writeln('No previous build');
|
112 | 92 | } else {
|
113 |
| - run('rm -rf '.$buildPath); |
| 93 | + run(sprintf('rm -rf %s/*', $buildPath)); |
114 | 94 | writeln('Removed previous build');
|
115 | 95 | }
|
116 | 96 |
|
117 | 97 | writeln('Cloning Repository (Branch: <info>{{branch}}</info>)');
|
118 | 98 |
|
119 | 99 | // Clone the required branch to the local build directory
|
120 |
| - run('git clone --single-branch --branch {{branch}} {{repository}} '.$buildPath); |
| 100 | + //run('git clone --single-branch --branch {{branch}} {{repository}} '.$buildPath); |
| 101 | + run(sprintf("git archive {{branch}} | tar -x -f - -C %s 2>&1", $buildPath)); |
121 | 102 | writeln('Clone complete');
|
122 | 103 |
|
123 | 104 | cd($buildPath);
|
|
131 | 112 |
|
132 | 113 | writeln('Build complete.');
|
133 | 114 |
|
134 |
| -})->local(); |
| 115 | +})>select('local'); |
135 | 116 |
|
136 | 117 | desc('Copy static website files to remote server');
|
137 | 118 | task('deploy:update_code', function () {
|
|
143 | 124 | upload($buildRoot.'/'.$directory.'/_dist/', '{{release_path}}');
|
144 | 125 | });
|
145 | 126 |
|
146 |
| -// Add unlock to failed deployment event. |
147 |
| -after('deploy:failed', 'deploy:unlock'); |
148 |
| - |
0 commit comments