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/ diff --git a/ui/Dockerfile b/ui/Dockerfile index d4b6b360..6287c8fb 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -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 @@ -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" diff --git a/ui/Dockerfile.dev b/ui/Dockerfile.dev index 40a64a30..b0c67a7d 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-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" 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/env-dev.sh b/ui/env-dev.sh new file mode 100644 index 00000000..eba5c5fd --- /dev/null +++ b/ui/env-dev.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/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 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()) 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..bec0b122 --- /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)); 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