Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 445f2da

Browse files
authored
EVG-17470 Set up environmental variables for parsley (#11)
1 parent b4e7046 commit 445f2da

File tree

8 files changed

+79
-6
lines changed

8 files changed

+79
-6
lines changed

.env-cmdrc.sample.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"devLocal": {
3+
"REACT_APP_LOGKEEPER_URL": "devLocal",
4+
"REACT_APP_EVERGREEN_URL": "http://localhost:9090"
5+
},
6+
"local": {
7+
"REACT_APP_LOGKEEPER_URL": "devLocal",
8+
"REACT_APP_EVERGREEN_URL": "http://localhost:9090",
9+
"REACT_APP_RELEASE_STAGE": "local"
10+
}
11+
}

.evergreen.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ functions:
9292
permissions: public-read
9393
display_name: storybook_assets_map_
9494

95+
copy-cmdrc:
96+
command: shell.exec
97+
params:
98+
working_dir: parsley
99+
script: |
100+
cp .env-cmdrc.sample.json .env-cmdrc.json
101+
95102
get-project:
96103
command: git.get_project
97104
type: setup
@@ -187,6 +194,7 @@ functions:
187194
tasks:
188195
- name: compile
189196
commands:
197+
- func: copy-cmdrc
190198
- func: yarn-build
191199

192200
- name: type_check
@@ -204,6 +212,7 @@ tasks:
204212

205213
- name: e2e_test
206214
commands:
215+
- func: copy-cmdrc
207216
- func: yarn-build
208217
- func: yarn-preview
209218
- func: install-chrome

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ storybook-static
1515
/src/**/*.css
1616

1717
#env variables
18-
.cmdrc.json
18+
.env-cmdrc.json
1919

2020
# misc
2121
.DS_Store

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,26 @@ Parsley is the UI for Evergreen's log viewer. It will eventually replace [Lobste
1212

1313
1. Clone this GitHub repository.
1414
2. Ensure you have Node.js 16.13+ and [Yarn](https://yarnpkg.com/getting-started/install) installed.
15-
3. Run `yarn`.
16-
4. Run `yarn run dev`. This will launch the app.
15+
3. Ask a colleague for their .cmdrc.json file and follow the instructions [here](#environment-variables)
16+
4. Run `yarn`.
17+
5. Run `yarn run dev`. This will launch the app.
18+
19+
20+
### Environment Variables
21+
22+
[env-cmd](https://github.com/toddbluhm/env-cmd#readme) is used to configure build environments for production, staging and development. This file is git ignored because it contains API keys that we do not want to publish. It should be named `.env-cmdrc.json` and placed at the root of the project. This file is required to deploy Parsley to production and to staging. Ask a team member to send you their copy of the file, which should look like the following:
23+
24+
```js
25+
{
26+
"devLocal": {
27+
"REACT_APP_LOGKEEPER_URL": "devLocal",
28+
"REACT_APP_EVERGREEN_URL": "http://localhost:9090"
29+
},
30+
"local": {
31+
"REACT_APP_LOGKEEPER_URL": "devLocal",
32+
"REACT_APP_EVERGREEN_URL": "http://localhost:9090",
33+
"REACT_APP_RELEASE_STAGE": "local"
34+
}
35+
}
36+
37+
```

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
"type": "commonjs",
66
"scripts": {
77
"build": "tsc && vite build",
8-
"build:local": "yarn build",
8+
"build:local": "env-cmd -e local yarn build",
9+
"build:staging": "env-cmd -e staging yarn build",
10+
"build:production": "env-cmd -e production yarn build",
911
"check-types": "tsc -p tsconfig.json --noEmit",
1012
"cy:open": "cypress open",
1113
"cy:run": "cypress run",
12-
"dev": "vite",
14+
"dev": "env-cmd -e devLocal vite",
15+
"staging": "env-cmd -e devStaging vite",
16+
"production": "env-cmd -e devProduction vite",
1317
"eslint:fix": "yarn eslint:strict --fix",
1418
"eslint:staged": "STRICT=1 eslint",
1519
"eslint:strict": "STRICT=1 eslint '*.{js,ts,tsx}' 'src/**/*.ts?(x)' 'cypress/**/*.ts'",
@@ -64,6 +68,7 @@
6468
"@vitejs/plugin-react": "2.0.1",
6569
"babel-loader": "^8.2.5",
6670
"cypress": "10.4.0",
71+
"env-cmd": "^10.1.0",
6772
"eslint": "8.21.0",
6873
"eslint-config-airbnb": "19.0.4",
6974
"eslint-config-prettier": "8.5.0",
@@ -87,6 +92,7 @@
8792
"typescript": "^4.6.4",
8893
"vite": "^3.0.0",
8994
"vite-plugin-checker": "^0.4.9",
95+
"vite-plugin-env-compatible": "^1.1.1",
9096
"vite-tsconfig-paths": "^3.5.0"
9197
},
9298
"resolutions": {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const releaseStage = process.env.REACT_APP_RELEASE_STAGE;
2+
const evergreenURL = process.env.REACT_APP_EVERGREEN_URL;
3+
const logkeeperURL = process.env.REACT_APP_LOGKEEPER_URL;
4+
5+
const isLocal = releaseStage === "local";
6+
const isProduction = releaseStage === "production";
7+
const isStaging = releaseStage === "staging";
8+
9+
export { isLocal, isProduction, isStaging, evergreenURL, logkeeperURL };

vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import react from "@vitejs/plugin-react";
22
import { defineConfig } from "vite";
33
import checker from "vite-plugin-checker";
4+
import envCompatible from "vite-plugin-env-compatible";
45
import tsconfigPaths from "vite-tsconfig-paths";
56
import path from "path";
67

@@ -31,6 +32,9 @@ export default defineConfig({
3132
include: ["**/*.tsx", "**/*.ts"], // Only Typescript files should use fast refresh.
3233
fastRefresh: true,
3334
}),
35+
envCompatible({
36+
prefix: "REACT_APP_",
37+
}),
3438
// Typescript checking
3539
checker({ typescript: true }),
3640
],

yarn.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5318,7 +5318,7 @@ commander@^2.19.0, commander@^2.20.0:
53185318
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
53195319
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
53205320

5321-
commander@^4.1.1:
5321+
commander@^4.0.0, commander@^4.1.1:
53225322
version "4.1.1"
53235323
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
53245324
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==
@@ -6172,6 +6172,14 @@ entities@^2.0.0:
61726172
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
61736173
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
61746174

6175+
env-cmd@^10.1.0:
6176+
version "10.1.0"
6177+
resolved "https://registry.yarnpkg.com/env-cmd/-/env-cmd-10.1.0.tgz#c7f5d3b550c9519f137fdac4dd8fb6866a8c8c4b"
6178+
integrity sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==
6179+
dependencies:
6180+
commander "^4.0.0"
6181+
cross-spawn "^7.0.0"
6182+
61756183
errno@^0.1.3, errno@~0.1.7:
61766184
version "0.1.8"
61776185
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.8.tgz#8bb3e9c7d463be4976ff888f76b4809ebc2e811f"
@@ -13326,6 +13334,11 @@ vite-plugin-checker@^0.4.9:
1332613334
vscode-languageserver-textdocument "^1.0.1"
1332713335
vscode-uri "^3.0.2"
1332813336

13337+
vite-plugin-env-compatible@^1.1.1:
13338+
version "1.1.1"
13339+
resolved "https://registry.yarnpkg.com/vite-plugin-env-compatible/-/vite-plugin-env-compatible-1.1.1.tgz#2e11b059a5f3e8fc609d6a4bba84ca497081ee20"
13340+
integrity sha512-4lqhBWhOzP+SaCPoCVdmpM5cXzjKQV5jgFauxea488oOeElXo/kw6bXkMIooZhrh9q7gclTl8en6N9NmnqUwRQ==
13341+
1332913342
vite-tsconfig-paths@^3.5.0:
1333013343
version "3.5.0"
1333113344
resolved "https://registry.yarnpkg.com/vite-tsconfig-paths/-/vite-tsconfig-paths-3.5.0.tgz#bfdf93f8072eff04125112ea9602fd50ae8cdad9"

0 commit comments

Comments
 (0)