Skip to content

Commit 46e265b

Browse files
authored
Removed need to change version controlled files configurations for local development (oncokb#551)
1 parent 7cdaf66 commit 46e265b

File tree

9 files changed

+123
-55
lines changed

9 files changed

+123
-55
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,7 @@ Desktop.ini
167167
# Sentry Config File
168168
.env.sentry-build-plugin
169169
.vscode/settings.json
170+
171+
local-frontend-config.json
172+
src/main/resources/firebase.json
173+
src/main/resources/config/application-dev.yml

README.md

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@
2424

2525
5. [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/)
2626

27-
2. Run the brew command for the Mac in the [compiling section](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) of the node-canvas readme. For other systems, please see [compiling section](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling) for instructions.
27+
2. Copy the example dev yaml file
2828

29-
```sh
30-
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
31-
```
29+
```sh
30+
cp src/main/resources/config/application-dev-example.yml src/main/resources/config/application-dev.yml
31+
```
32+
33+
3. Run the brew command for the Mac in the [compiling section](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling)
34+
of the node-canvas readme. For other systems, please see
35+
[compiling section](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling)
36+
for instructions.
37+
38+
```sh
39+
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
40+
```
3241

33-
3. After installing Node and yarn, you should be able to run the following command
42+
4. After installing Node and yarn, you should be able to run the following command
3443
to install development tools. You will only need to run this command when
3544
dependencies change in [package.json](package.json).
3645

@@ -40,7 +49,7 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
4049

4150
We use yarn scripts and [Webpack](https://webpack.js.org/) as our build system.
4251

43-
4. If you are using redis as a cache, you will have to launch a cache server (Optional).
52+
5. If you are using redis as a cache, you will have to launch a cache server (Optional).
4453

4554
- To start your cache server, run:
4655

@@ -59,7 +68,7 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
5968
See [here](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html#boot-features-caching-provider-none)
6069
for details.
6170

62-
5. Configure Keycloak and Google SSO
71+
6. Configure Keycloak and Google SSO
6372

6473
To log in to your app, you'll need to have [Keycloak](https://keycloak.org)
6574
up and running.
@@ -120,7 +129,7 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
120129
scope: openid,profile,email
121130
```
122131
123-
6. Configure Firebase
132+
7. Configure Firebase
124133
125134
1. Go to [Firebase Console](https://console.firebase.google.com/) and create
126135
a new project
@@ -149,7 +158,9 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
149158
9. Click **Project settings**
150159
10. Choose **Service Accounts** on header
151160
11. Under **Firebase Admin SDK** section, click on **Generate new private key**
152-
12. Move the service account credentials under `src/main/resources/<CREDENTIALS_FILENAME>.json`
161+
12. Move the service account credentials under `src/main/resources/firebase.json`
162+
> [!WARNING]
163+
> Never commit the `firebase.json` file to git!
153164
13. Update `application.firebase.service-account-credentials-path`
154165
to the filename
155166
14. Under **Project Overview** page in the **General** tab under the **Your apps**
@@ -158,10 +169,18 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
158169
- You do not need to setup firebase hosting
159170
16. The resulting credential and paste them in the corresponding fields
160171
in `application.firebase`
161-
17. Expand **Build** and click **Authentication**
162-
18. Click the **Sign-in method** section and add email/password provider
172+
17. Copy example front configuration file
173+
174+
```sh
175+
cp local-frontend-config-example.json local-frontend-config.json
176+
```
177+
178+
18. Copy the same credentials you put in `application.firebase` into the `local-frontend-config.json`
179+
file.
180+
19. Expand **Build** and click **Authentication**
181+
20. Click the **Sign-in method** section and add email/password provider
163182
164-
7. Verify that your mysql configuration in [application-dev.yaml](src/main/resources/config/application-dev.yml)
183+
8. Verify that your mysql configuration in [application-dev.yaml](src/main/resources/config/application-dev.yml)
165184
is correct for you mysql server instance.
166185
167186
```yaml
@@ -172,7 +191,7 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
172191
password: root
173192
```
174193
175-
8. Run the application (Don't login just yet)
194+
9. Run the application (Don't login just yet)
176195

177196
- Note your a oncokb_curation schema will be created in your mysql database.
178197
Data will also be seeded for it.
@@ -181,40 +200,40 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
181200
./mvnw
182201
```
183202

184-
9. Wait until the server is listening to requests and is able to redirect you to
185-
the login screen. (server url defaults to `http://localhost:9090`)
203+
10. Wait until the server is listening to requests and is able to redirect you to
204+
the login screen. (server url defaults to `http://localhost:9090`)
186205

187-
10. Add a login for yourself into your mysql instance. Replace <your_email>
206+
11. Add a login for yourself into your mysql instance. Replace <your_email>
188207
with your gmail email address.
189208

190-
```sql
191-
INSERT INTO `oncokb_curation`.`user`
192-
(
193-
`login`,
194-
`email`,
195-
`created_by`,
196-
`activated`)
197-
VALUES
198-
('<your_email>',
199-
'<your_email>',
200-
'SYSTEM',
201-
1);
202-
203-
SET @UserID = (SELECT Id
204-
FROM `oncokb_curation`.`user`
205-
WHERE email = '<your_email>');
206-
207-
INSERT INTO `oncokb_curation`.`user_authority`
208-
(user_id, authority_name)
209+
```sql
210+
INSERT INTO `oncokb_curation`.`user`
211+
(
212+
`login`,
213+
`email`,
214+
`created_by`,
215+
`activated`)
209216
VALUES
210-
(@UserId, 'ROLE_ADMIN'),
211-
(@UserId, 'ROLE_DEV'),
212-
(@UserId, 'ROLE_CURATOR'),
213-
(@UserId, 'ROLE_USER');
214-
215-
```
216-
217-
11. Login to curation!
217+
('<your_email>',
218+
'<your_email>',
219+
'SYSTEM',
220+
1);
221+
222+
SET @UserID = (SELECT Id
223+
FROM `oncokb_curation`.`user`
224+
WHERE email = '<your_email>');
225+
226+
INSERT INTO `oncokb_curation`.`user_authority`
227+
(user_id, authority_name)
228+
VALUES
229+
(@UserId, 'ROLE_ADMIN'),
230+
(@UserId, 'ROLE_DEV'),
231+
(@UserId, 'ROLE_CURATOR'),
232+
(@UserId, 'ROLE_USER');
233+
234+
```
235+
236+
12. Login to curation!
218237

219238
## Building for production
220239

local-frontend-config-example.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"firebase": {
3+
"enabled": true,
4+
"apiKey": "",
5+
"authDomain": "",
6+
"databaseUrl": "",
7+
"projectId": "",
8+
"storageBucket": "",
9+
"messagingSenderId": "",
10+
"appId": "",
11+
"measurementId": "",
12+
"connectToFirebaseEmulators": false
13+
}
14+
}

src/main/resources/config/application-dev.yml renamed to src/main/resources/config/application-dev-example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ application:
134134
messaging-sender-id:
135135
app-id:
136136
measurement-id:
137-
service-account-credentials-path:
137+
service-account-credentials-path: firebase.json
138138
oncokb-data-repo-dir:
139139
frontend:
140140
sentry-dsn:

src/main/webapp/app/stores/firebase/firebase-app.store.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ export class FirebaseAppStore extends BaseStore {
5454

5555
initializeFirebase() {
5656
if (!AppConfig.serverConfig.frontend) {
57-
throw new Error('No frontend config');
57+
alert('No frontend configuration found.');
58+
return;
5859
} else if (!AppConfig.serverConfig.frontend.firebase) {
59-
throw new Error('No firebase config');
60+
alert(
61+
`No firebase configuration.
62+
Are you running locally?
63+
Add your local-frontend-config.json file to the root directory.
64+
See the README.md for more details`,
65+
);
66+
return;
6067
}
6168
const { enabled, connectToFirebaseEmulators, ...firebaseOptions } = AppConfig.serverConfig.frontend.firebase;
6269
this.firebaseEnabled = enabled;

src/main/webapp/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@
7676
/*<![CDATA[*/
7777

7878
window.serverConfig = {};
79-
window.serverConfig.frontend = /*[[${frontendConfig}]]*/ {};
79+
80+
const isDev = <%= htmlWebpackPlugin.options.templateParameters.frontendConfig ? "true" : "false" %>;
81+
if (isDev) {
82+
window.serverConfig.frontend = <%= JSON.stringify(htmlWebpackPlugin.options.templateParameters.frontendConfig ?? {}) %>
83+
} else {
84+
window.serverConfig.frontend = /*[[${frontendConfig}]]*/ {};
85+
}
8086

8187
/*]]>*/
8288
</script>

webpack/webpack.common.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const path = require('path');
22
const webpack = require('webpack');
33
const { merge } = require('webpack-merge');
44
const CopyWebpackPlugin = require('copy-webpack-plugin');
5-
const HtmlWebpackPlugin = require('html-webpack-plugin');
65
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
76
const ESLintPlugin = require('eslint-webpack-plugin');
87
const utils = require('./utils.js');
@@ -75,7 +74,7 @@ module.exports = async options => {
7574
/*
7675
,
7776
Disabled due to https://github.com/jhipster/generator-jhipster/issues/16116
78-
Can be enabled with @reduxjs/toolkit@>1.6.1
77+
Can be enabled with @reduxjs/toolkit@>1.6.1
7978
{
8079
enforce: 'pre',
8180
test: /\.jsx?$/,
@@ -154,12 +153,6 @@ module.exports = async options => {
154153
{ from: './src/main/webapp/robots.txt', to: 'robots.txt' },
155154
],
156155
}),
157-
new HtmlWebpackPlugin({
158-
template: './src/main/webapp/index.html',
159-
chunksSortMode: 'auto',
160-
inject: 'body',
161-
base: '/',
162-
}),
163156
],
164157
},
165158
// jhipster-needle-add-webpack-config - JHipster will add custom config

webpack/webpack.dev.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ const webpackMerge = require('webpack-merge').merge;
33
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
44
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
55
const WebpackNotifierPlugin = require('webpack-notifier');
6+
const HtmlWebpackPlugin = require('html-webpack-plugin');
67
const path = require('path');
78
const sass = require('sass');
9+
const fs = require('fs');
810

911
const utils = require('./utils.js');
1012
const commonConfig = require('./webpack.common.js');
1113

1214
const ENV = 'development';
1315

16+
const serverConfigFilePath = 'local-frontend-config.json';
17+
let frontendConfigJson = undefined;
18+
if (fs.existsSync(serverConfigFilePath)) {
19+
frontendConfigJson = fs.readFileSync(serverConfigFilePath);
20+
}
21+
const frontendConfig = frontendConfigJson ? JSON.parse(frontendConfigJson) : undefined;
22+
1423
module.exports = async options =>
1524
webpackMerge(await commonConfig({ ...options, env: ENV }), {
1625
devtool: 'cheap-module-source-map', // https://reactjs.org/docs/cross-origin-errors.html
@@ -131,5 +140,14 @@ module.exports = async options =>
131140
title: 'Oncokb Curation',
132141
contentImage: path.join(__dirname, 'logo-oncokb.png'),
133142
}),
143+
new HtmlWebpackPlugin({
144+
template: './src/main/webapp/index.html',
145+
chunksSortMode: 'auto',
146+
inject: 'body',
147+
base: '/',
148+
templateParameters: {
149+
frontendConfig,
150+
},
151+
}),
134152
].filter(Boolean),
135153
});

webpack/webpack.prod.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const webpack = require('webpack');
22
const webpackMerge = require('webpack-merge').merge;
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
44
const WorkboxPlugin = require('workbox-webpack-plugin');
5+
const HtmlWebpackPlugin = require('html-webpack-plugin');
56
const TerserPlugin = require('terser-webpack-plugin');
67
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
78
const sass = require('sass');
@@ -108,6 +109,12 @@ module.exports = async () =>
108109
skipWaiting: true,
109110
exclude: [/swagger-ui/],
110111
}),
112+
new HtmlWebpackPlugin({
113+
template: './src/main/webapp/index.html',
114+
chunksSortMode: 'auto',
115+
inject: 'body',
116+
base: '/',
117+
}),
111118
// Sentry Webpack plugin needs to be put after all other plugins
112119
sentryWebpackPlugin({
113120
authToken: process.env.SENTRY_AUTH_TOKEN,

0 commit comments

Comments
 (0)