Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get backend URL from env #927

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ services:
- api
depends_on:
- db
environment:
apiUrl: http://localhost:5000

aria2c:
build: components/aria2c/
Expand Down
22 changes: 12 additions & 10 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ RUN apt-get update && \
npm install && \
npm install --global bower gulp-cli && \
bower --allow-root install



# Building the ui component to obtain static files.
RUN gulp build

RUN mv env-prod.sh /ui/dist/

#------------------------------ Production
FROM nginx:alpine as production

Expand All @@ -32,13 +32,15 @@ COPY --from=builder /ui/dist/ /usr/share/nginx/html
# Expose ports
EXPOSE 80

CMD sh /usr/share/nginx/html/env-prod.sh && nginx -g 'daemon off;'

# Adding metadata as docker labels
LABEL scorelab.bassa.name="Bassa Web production server" \
scorelab.bassa.description="Dockerfile for Bassa Web Nginx server" \
scorelab.bassa.url="https://github.com/scorelab/Bassa/wiki" \
scorelab.bassa.vcs-url="https://github.com/scorelab/Bassa" \
scorelab.bassa.vcs-ref=$VCS_REF \
scorelab.bassa.build-date=$BUILD_DATE \
scorelab.bassa.vendor="Sustainable Computing Research Group" \
scorelab.bassa.version="1.0" \
scorelab.bassa.schema-version="1.0"
scorelab.bassa.description="Dockerfile for Bassa Web Nginx server" \
scorelab.bassa.url="https://github.com/scorelab/Bassa/wiki" \
scorelab.bassa.vcs-url="https://github.com/scorelab/Bassa" \
scorelab.bassa.vcs-ref=$VCS_REF \
scorelab.bassa.build-date=$BUILD_DATE \
scorelab.bassa.vendor="Sustainable Computing Research Group" \
scorelab.bassa.version="1.0" \
scorelab.bassa.schema-version="1.0"
22 changes: 13 additions & 9 deletions ui/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ RUN apt-get update && \
npm install --global bower gulp-cli && \
bower --allow-root install

# Add environment variable values to env.js
# ENV: apiUrl : backend url
RUN sh env-dev.sh

# Starting gulp server
CMD ["gulp", "serve"]
CMD ["sh env-dev.sh &&" ,"gulp", "serve"]

# labels to dockerfile
LABEL scorelab.bassa.name="Bassa Web development server" \
scorelab.bassa.description="Dockerfile for Bassa Web" \
scorelab.bassa.url="https://github.com/scorelab/Bassa/wiki" \
scorelab.bassa.vcs-url="https://github.com/scorelab/Bassa" \
scorelab.bassa.vcs-ref=$VCS_REF \
scorelab.bassa.build-date=$BUILD_DATE \
scorelab.bassa.vendor="Sustainable Computing Research Group" \
scorelab.bassa.version="1.0" \
scorelab.bassa.schema-version="1.0"
scorelab.bassa.description="Dockerfile for Bassa Web" \
scorelab.bassa.url="https://github.com/scorelab/Bassa/wiki" \
scorelab.bassa.vcs-url="https://github.com/scorelab/Bassa" \
scorelab.bassa.vcs-ref=$VCS_REF \
scorelab.bassa.build-date=$BUILD_DATE \
scorelab.bassa.vendor="Sustainable Computing Research Group" \
scorelab.bassa.version="1.0" \
scorelab.bassa.schema-version="1.0"
3 changes: 0 additions & 3 deletions ui/config.ts

This file was deleted.

5 changes: 5 additions & 0 deletions ui/env-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

pattern=' window.__env.apiUrl.*'
replacement=" window.__env.apiUrl = '${apiUrl}';"

sed -i -e 's,'"$pattern"','"$replacement"',' ./src/env.js
5 changes: 5 additions & 0 deletions ui/env-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

pattern=' window.__env.apiUrl.*'
replacement=" window.__env.apiUrl = '${apiUrl}';"

sed -i -e 's,'"$pattern"','"$replacement"',' /usr/share/nginx/html/env.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not possible to move this to a .json file and patch that accordingly or change it accordingly? What is the reason for patching a .js file?

Copy link
Collaborator Author

@kmehant kmehant Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaDogg Actually I used the javascript file which is imported in static HTML file so that whenever the homepage is loaded, the JS script is run and the variables are as well loaded.

5 changes: 5 additions & 0 deletions ui/gulp/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gulp.task('html', ['inject', 'partials'], function () {

var htmlFilter = $.filter('*.html');
var jsFilter = $.filter('**/*.js');
var envFilter = $.filter('*.js');
var cssFilter = $.filter('**/*.css');
var assets;

Expand All @@ -47,6 +48,10 @@ gulp.task('html', ['inject', 'partials'], function () {
.pipe($.ngAnnotate())
.pipe(uglify())
.pipe(jsFilter.restore())
.pipe(envFilter)
.pipe($.ngAnnotate())
.pipe(uglify())
.pipe(envFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
// import { constants } from "./config";

angular.module('bassa', ['ngAnimate', 'ngCookies', 'ngTouch',
'ngSanitize', 'ui.router', 'ngMaterial', 'nvd3', 'app'])

.value('BassaUrl', "http://localhost:5000")
.value('BassaUrl', window.__env.apiUrl)

.config(function ($stateProvider, $httpProvider, $urlRouterProvider, $mdThemingProvider,
$mdIconProvider, $qProvider) {
Expand Down
7 changes: 7 additions & 0 deletions ui/src/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (window) {
window.__env = window.__env || {};

// Bassa API url
window.__env.apiUrl = 'http://localhost:5000';

}(this));
1 change: 1 addition & 0 deletions ui/src/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html class="no-js" ng-app="bassa">
<head>
<script src="env.js"></script>
<meta charset="utf-8">
<title>Bassa</title>
<meta name="description" content="Automated Download Queue for Enterprise to take the best use of Internet bandwidth">
Expand Down