Commit 02fbb44
authored
fix: introduce robust env configuration (#165)
The #81 pull request
introduced a nasty bug where we weren't using prod.
The TL;DR of the bug is that `sed` was replacing both the initial
assignment and the pattern, such that this code:
```javascript
const placeholder = 'MLAB_PROJECT_PLACEHOLDER';
return placeholder === 'MLAB_PROJECT_PLACEHOLDER' ? 'mlab-staging' : placeholder;
```
became, at runtime:
```javascript
const placeholder = 'mlab-oti';
return placeholder === 'mlab-oti' ? 'mlab-staging' : placeholder;
```
This was fixed in #164
but `sed` substitution is fragile. We need more robustness.
I spent time thinking about this and this is what I concluded:
1. The biggest issue of the `sed` substitution is not the substitution
per se, but a *lack of debuggability* by which the substitution only
happens when deploying and cannot be tested locally.
2. Any solution that only applies when merging a pull request would
be morally as bad as that one. It could fail without notice.
3. We now have `scripts/build.js` so we can take advantage of that.
4. Using `scripts/build.js` to select a committed `env.prod.js` _or_
`env.staging.js` is a *bad idea* because they might drift, thus
putting us *back again* into a scenario where we only know something
is wrong after merging a pull request.
Based on this reasoning, with this diff I am proposing what I think
is the most robust solution to the problem at hand:
1. We autogenerate `dist/js/env.js` from `scripts/build.js`
2. `scripts/build.js` *requires* a command line argument identifying
the target deployment environment and this value is *parsed* and we
reject invalid configurations (furthermore, it is always required to
specify the argument so prod and staging cannot drift)
3. `dist/js/env.js` *only* contains a *single* variable named
`mlabEnvName` and that can be *either* "prod" or "staging" (and it
must always be like that, so drift is *not possible*)
4. The codebase *continues* to select the correct configuration
inline depending on `mlabEnvName` values (which preserves the
principle of locality and ensures the code that selects the config
is *close to* the code it has effects upon)
5. Now the codebase *rejects* invalid or missing `mlabEnvName`
and the "not configured case" leads to *hard failure*
6. Both deployment paths use the same pattern `npm run build -- $name`
where `$name` is either "prod" or "staging" (this is arguably
better than before where the staging deployment relied on a default)
As a bonus, deploy `console.log` aggressively. This follows the
*rule of transparency*. The operator must be able to easily and
clearly see what URLs we're using. Easy inspection solves many
problems and empowers to perform better manual testing. (Also, a
user can now more easily report bugs.)1 parent c583f65 commit 02fbb44
File tree
6 files changed
+46
-16
lines changed- .github/workflows
- scripts
- src
- js
6 files changed
+46
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 26 | + | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
| |||
86 | 102 | | |
87 | 103 | | |
88 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
89 | 110 | | |
90 | 111 | | |
91 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
| 132 | + | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
| |||
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| 154 | + | |
| 155 | + | |
152 | 156 | | |
| 157 | + | |
| 158 | + | |
153 | 159 | | |
| 160 | + | |
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
160 | 167 | | |
161 | | - | |
| 168 | + | |
162 | 169 | | |
163 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
164 | 174 | | |
165 | 175 | | |
166 | 176 | | |
167 | | - | |
| 177 | + | |
168 | 178 | | |
169 | 179 | | |
170 | 180 | | |
| |||
176 | 186 | | |
177 | 187 | | |
178 | 188 | | |
179 | | - | |
| 189 | + | |
180 | 190 | | |
181 | 191 | | |
182 | 192 | | |
| |||
234 | 244 | | |
235 | 245 | | |
236 | 246 | | |
237 | | - | |
| 247 | + | |
238 | 248 | | |
239 | 249 | | |
240 | 250 | | |
| |||
0 commit comments