Skip to content

Commit

Permalink
Denis coric/prod env (#404)
Browse files Browse the repository at this point in the history
* Make build for prod env

* Adjusted envconfig service

* Restored tooling part

* Updated dependency for YK Web

* Restored values in envconfig

* Updated default value in envconfig, and envconfig.example
  • Loading branch information
dcoric authored Jan 22, 2025
1 parent 4007aaa commit d45fc18
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ YK_VERSION=18a3c7f

# Add these near the top with other tool versions
NODE_VERSION ?= 22.13.0
PNPM_VERSION ?= latest
PNPM_VERSION ?= 9.15.4

# Add these with other LOCALBIN definitions
NODE_DIR ?= $(LOCALBIN_TOOLING)/node
Expand Down Expand Up @@ -319,14 +319,15 @@ test-k6-performance: ## run k6 performance tests.

.PHONY: web-build
web-build: node ## build the web components.
## Cleanup
rm -rf ./assets/**
rm -rf ./web/node_modules
## YHS Web
$(NODE_PATH) $(PNPM) --prefix ./web install
$(NODE_PATH) $(PNPM) --prefix ./web update yunikorn-web ## ensure that the yunikorn-web package is up to date
$(NODE_PATH) uhsApiURL=$(strip $(call uhs_api_url)) yunikornApiURL=$(strip $(call yunikorn_api_url)) \
moduleFederationRemoteEntry=$(strip $(call uhs_api_url))/remoteEntry.js \
localUhsComponentsWebAddress=$(strip $(call uhs_api_url)) \
$(NODE_PATH) production=true \
$(NODE_PATH) $(PNPM) --prefix ./web setenv
$(NODE_PATH) $(PNPM) --prefix ./web build
$(NODE_PATH) $(PNPM) --prefix ./web build:prod
echo "UHS Web Build Complete"
## Yunikorn Web
echo "Removing node modules from yunikorn-web"
Expand All @@ -336,10 +337,7 @@ web-build: node ## build the web components.
echo "Installing yunikorn-web"
$(NODE_PATH) $(PNPM) --prefix ./tmp install
echo "Setting environment variables in yunikorn-web"
localSchedulerWebAddress=$(strip $(call yunikorn_api_url)) \
uhsApiURL=$(strip $(call uhs_api_url)) yunikornApiURL=$(strip $(call yunikorn_api_url)) \
moduleFederationRemoteEntry=$(strip $(call uhs_api_url))/remoteEntry.js \
localUhsComponentsWebAddress=$(strip $(call uhs_api_url)) \
$(NODE_PATH) production=true \
$(NODE_PATH) $(PNPM) --prefix ./tmp setenv:prod
echo "Building yunikorn-web"
$(NODE_PATH) $(PNPM) --prefix ./tmp build:prod
Expand Down
3 changes: 1 addition & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"run:all": "node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js",
"setenv": "npx --yes ts-node ./src/environments/setEnvironmentVariables.ts",
"setenv:prod": "npx --yes ts-node ./src/environments/setEnvironmentVariables.ts prod",
"prebuild:prod": "pnpm set-env-vars",
"start:json-server": "json-server --watch mock-server/db.json --config mock-server/server.json",
"prettify": "prettier --config ./.prettierrc --write 'src/**/*.{js,ts,json,css,scss,md,html}'"
},
Expand Down Expand Up @@ -58,5 +57,5 @@
"pnpm": "9",
"node": "22"
},
"packageManager": "pnpm@9"
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
}
8 changes: 4 additions & 4 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions web/src/app/services/envconfig/envconfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { EnvConfig } from '@app/models/envconfig.model';
import { environment } from 'src/environments/environment';

const ENV_CONFIG_JSON_URL = './assets/config/envconfig.json';

Expand Down Expand Up @@ -47,31 +48,43 @@ export class EnvConfigService {
}

loadEnvConfig(): Promise<void> {
if (environment.production) {
console.log('environment.production', environment.production);
return Promise.resolve();
}

return new Promise((resolve) => {
this.httpClient.get<EnvConfig>(ENV_CONFIG_JSON_URL).subscribe((data) => {
this.envConfig = data;
resolve();
this.httpClient.get<EnvConfig>(ENV_CONFIG_JSON_URL).subscribe({
next: (data) => {
this.envConfig = data;
resolve();
},
error: () => {
console.warn('Failed to load envconfig.json, using default values');
resolve();
},
});
});
}

getYuniKornWebAddress() {
if (this.envConfig.yunikornApiURL) {
return `${this.envConfig.yunikornApiURL}/ws`;
if (!environment.production) {
return `${this.envConfig.yunikornApiURL}/api`;
}

return `${this.uiProtocol}//${this.uiHostname}:${this.uiPort}/ws`;
return `${this.uiProtocol}//${this.uiHostname}:${this.uiPort}/api`;
}

getUHSWebAddress() {
if (this.envConfig.uhsApiURL) {
if (!environment.production) {
return `${this.envConfig.uhsApiURL}/api`;
}

return `${this.uiProtocol}//${this.uiHostname}:${this.uiPort}/api`;
}

getExternalLogsBaseUrl() {
return this.envConfig.externalLogsURL || null;
if (!environment.production) {
return this.envConfig.externalLogsURL || null;
}
return null;
}
}
1 change: 1 addition & 0 deletions web/src/assets/config/envconfig.example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"production": false,
"localUhsComponentsWebAddress": "http://localhost:3100",
"externalLogsURL": "https://logs.example.com?token=abc123&applicationId=",
"yunikornApiURL": "http://localhost:30001",
Expand Down
3 changes: 2 additions & 1 deletion web/src/assets/config/envconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"localUhsComponentsWebAddress": "http://localhost:3100",
"production": false,
"localUhsComponentsWebAddress": "http://localhost:8989",
"externalLogsURL": "https://logs.example.com?token=abc123&applicationId=",
"yunikornApiURL": "http://localhost:30001",
"uhsApiURL": "http://localhost:8989"
Expand Down
16 changes: 2 additions & 14 deletions web/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@
* limitations under the License.
*/

// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false,
production: true,
externalLogsURL: '',
yunikornApiURL: '',
uhsApiURL: '',
localUhsComponentsWebAddress: '',
};

/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

0 comments on commit d45fc18

Please sign in to comment.