From 32493cfbb4c1627babcbb8ef9fd5a07c9f4ca7d8 Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Mon, 3 Aug 2020 22:09:56 +0530 Subject: [PATCH 1/6] Get backend URL from env Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- ui/src/app/index.js | 3 +-- ui/src/env.js | 7 +++++++ ui/src/index.html | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 ui/src/env.js diff --git a/ui/src/app/index.js b/ui/src/app/index.js index 158f98a3..a61d626e 100755 --- a/ui/src/app/index.js +++ b/ui/src/app/index.js @@ -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) { diff --git a/ui/src/env.js b/ui/src/env.js new file mode 100644 index 00000000..fc31dc44 --- /dev/null +++ b/ui/src/env.js @@ -0,0 +1,7 @@ +(function (window) { + window.__env = window.__env || {}; + + // Bassa API url + window.__env.apiUrl = 'http://localhost:5000'; + +}(this)); \ No newline at end of file diff --git a/ui/src/index.html b/ui/src/index.html index 3fc47d4a..c879a4b5 100644 --- a/ui/src/index.html +++ b/ui/src/index.html @@ -1,6 +1,7 @@ + Bassa From 6ec7b3eac738d0eeabcedde2d1f146dfa2ac69a8 Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Tue, 4 Aug 2020 08:17:22 +0530 Subject: [PATCH 2/6] Take env on static files as well Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- ui/config.ts | 3 --- ui/gulp/build.js | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 ui/config.ts diff --git a/ui/config.ts b/ui/config.ts deleted file mode 100644 index 4cc25912..00000000 --- a/ui/config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export var config = { - "API_URL":"http://localhost:5000", - } \ No newline at end of file diff --git a/ui/gulp/build.js b/ui/gulp/build.js index d9a8e925..2964029c 100644 --- a/ui/gulp/build.js +++ b/ui/gulp/build.js @@ -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; @@ -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()) From e10eaf263f56d2ae6cac2d75a19da2ba6a04cc40 Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Tue, 4 Aug 2020 08:52:27 +0530 Subject: [PATCH 3/6] Add env variables to env.js Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- ui/Dockerfile | 22 ++++++++++++---------- ui/Dockerfile.dev | 20 ++++++++++++-------- ui/env.sh | 5 +++++ ui/src/env.js | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 ui/env.sh diff --git a/ui/Dockerfile b/ui/Dockerfile index d4b6b360..a818438e 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -12,8 +12,10 @@ RUN apt-get update && \ npm install && \ npm install --global bower gulp-cli && \ bower --allow-root install - - + +# Add environment variable values to env.js +# ENV: apiUrl : backend url +RUN sh env.sh # Building the ui component to obtain static files. RUN gulp build @@ -34,11 +36,11 @@ EXPOSE 80 # 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" diff --git a/ui/Dockerfile.dev b/ui/Dockerfile.dev index 40a64a30..86e2c7cc 100644 --- a/ui/Dockerfile.dev +++ b/ui/Dockerfile.dev @@ -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.sh + # Starting gulp server CMD ["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" diff --git a/ui/env.sh b/ui/env.sh new file mode 100644 index 00000000..eba5c5fd --- /dev/null +++ b/ui/env.sh @@ -0,0 +1,5 @@ + +pattern=' window.__env.apiUrl.*' +replacement=" window.__env.apiUrl = '${apiUrl}';" + +sed -i -e 's,'"$pattern"','"$replacement"',' ./src/env.js diff --git a/ui/src/env.js b/ui/src/env.js index fc31dc44..bec0b122 100644 --- a/ui/src/env.js +++ b/ui/src/env.js @@ -4,4 +4,4 @@ // Bassa API url window.__env.apiUrl = 'http://localhost:5000'; -}(this)); \ No newline at end of file +}(this)); From 6cf1ff5e79072cc65ba060df8fcb94f06680d11b Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Tue, 4 Aug 2020 12:58:14 +0530 Subject: [PATCH 4/6] Fix env Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- ui/Dockerfile | 8 ++++---- ui/Dockerfile.dev | 4 ++-- ui/{env.sh => env-dev.sh} | 0 ui/env-prod.sh | 5 +++++ 4 files changed, 11 insertions(+), 6 deletions(-) rename ui/{env.sh => env-dev.sh} (100%) create mode 100644 ui/env-prod.sh diff --git a/ui/Dockerfile b/ui/Dockerfile index a818438e..3fbeac73 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -13,13 +13,11 @@ 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.sh - # Building the ui component to obtain static files. RUN gulp build +RUN mv env-prod.sh /ui/dist/ + #------------------------------ Production FROM nginx:alpine as production @@ -34,6 +32,8 @@ 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" \ diff --git a/ui/Dockerfile.dev b/ui/Dockerfile.dev index 86e2c7cc..b0c67a7d 100644 --- a/ui/Dockerfile.dev +++ b/ui/Dockerfile.dev @@ -21,10 +21,10 @@ RUN apt-get update && \ # Add environment variable values to env.js # ENV: apiUrl : backend url -RUN sh env.sh +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" \ diff --git a/ui/env.sh b/ui/env-dev.sh similarity index 100% rename from ui/env.sh rename to ui/env-dev.sh diff --git a/ui/env-prod.sh b/ui/env-prod.sh new file mode 100644 index 00000000..99359755 --- /dev/null +++ b/ui/env-prod.sh @@ -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 From 5b52cba587ca099683064e79188b5d5efa821c38 Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Wed, 5 Aug 2020 17:52:13 +0530 Subject: [PATCH 5/6] Fix Dockerfile Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- ui/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/Dockerfile b/ui/Dockerfile index 3fbeac73..6287c8fb 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -32,7 +32,7 @@ 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;"] +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" \ From 6393259c9bc774615f4164b89656862ccaacfbf6 Mon Sep 17 00:00:00 2001 From: K mehant <411843@student.nitandhra.ac.in> Date: Wed, 5 Aug 2020 17:56:17 +0530 Subject: [PATCH 6/6] Add env to docker-compose Signed-off-by: K mehant <411843@student.nitandhra.ac.in> --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index b9e2f088..bf89b906 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,8 @@ services: - api depends_on: - db + environment: + apiUrl: http://localhost:5000 aria2c: build: components/aria2c/