diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..b512c09d476623ff4bf8d0d63c29b784925dbdf8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.github/workflows/docker_img.yml b/.github/workflows/docker_img.yml index a25d30c92fe0636dc593c859e224eead06025d52..057a93d7864f37820b14b5cf8f6ce141a6a08f85 100644 --- a/.github/workflows/docker_img.yml +++ b/.github/workflows/docker_img.yml @@ -55,13 +55,6 @@ jobs: - name: 'Set version variable & expmt feature flag' run: | - GIT_HASH=$(git rev-parse --short HEAD) - echo "Setting GIT_HASH: $GIT_HASH" - echo "GIT_HASH=$GIT_HASH" >> $GITHUB_ENV - - VERSION=$(jq -r '.version' package.json) - echo "Setting VERSION: $VERSION" - echo "VERSION=$VERSION" >> $GITHUB_ENV if [[ "$GITHUB_REF" == 'refs/heads/master' ]] || [[ "$GITHUB_REF" == 'refs/heads/staging' ]] then echo "prod/staging build, do not enable experimental features" @@ -74,8 +67,6 @@ jobs: DOCKER_BUILT_TAG=${{ env.DOCKER_REGISTRY }}siibra-explorer:$BRANCH_NAME echo "Building $DOCKER_BUILT_TAG" docker build \ - --build-arg GIT_HASH=$GIT_HASH \ - --build-arg VERSION=$VERSION \ --build-arg MATOMO_URL=$MATOMO_URL \ --build-arg MATOMO_ID=$MATOMO_ID \ --build-arg SIIBRA_API_ENDPOINTS=$SIIBRA_API_ENDPOINTS \ diff --git a/Dockerfile b/Dockerfile index 6d7188d0fa7a6d777a10205b2e366d5f8a25a20f..8425647048ad716c0b86edb66ad609b36aa01a84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,6 @@ ENV EXPERIMENTAL_FEATURE_FLAG=${EXPERIMENTAL_FEATURE_FLAG:-false} ARG ENABLE_LEAP_MOTION ENV ENABLE_LEAP_MOTION=${ENABLE_LEAP_MOTION:-false} -ARG GIT_HASH -ENV GIT_HASH=${GIT_HASH:-unknownhash} - -ARG VERSION -ENV VERSION=${VERSION:-unknownversion} COPY . /iv WORKDIR /iv diff --git a/build_env.md b/build_env.md index 8890c7d324ff25ed8de44a11acb7046d8509eb47..81833e992e2dd7b5e484e0593cee4409e128c603 100644 --- a/build_env.md +++ b/build_env.md @@ -4,7 +4,6 @@ As interactive atlas viewer uses [webpack define plugin](https://webpack.js.org/ | name | description | default | example | | --- | --- | --- | --- | -| `VERSION` | printed in console on viewer startup | `GIT_HASH` \|\| unspecificed hash | v2.2.2 | | `PRODUCTION` | if the build is for production, toggles optimisations such as minification | `undefined` | true | | `BACKEND_URL` | backend that the viewer calls to fetch available template spaces, parcellations, plugins, datasets | `null` | https://interactive-viewer.apps.hbp.eu/ | | ~~`BS_REST_URL`~~ _deprecated. use `SIIBRA_API_ENDPOINTS` instead_ | [siibra-api](https://github.com/FZJ-INM1-BDA/siibra-api) used to fetch different resources | `https://siibra-api-stable.apps.hbp.eu/v1_0` | diff --git a/src/environments/parseEnv.js b/src/environments/parseEnv.js index b1ea57f5573ad1a0797d332d865370064e427d07..a9dd24424e3eb5ad2ef58b2396ac793461d8dd78 100644 --- a/src/environments/parseEnv.js +++ b/src/environments/parseEnv.js @@ -2,7 +2,24 @@ const fs = require('fs') const path = require('path') const { promisify } = require('util') const asyncWrite = promisify(fs.writeFile) +const asyncReadFile = promisify(fs.readFile) const process = require("process") +const { exec } = require("child_process") + + +const getGitHead = () => new Promise((rs, rj) => { + exec(`git rev-parse --short HEAD`, (err, stdout, stderr) => { + if (err) return rj(err) + if (stderr) return rj(stderr) + rs(stdout) + }) +}) + +const getVersion = async () => { + const content = await asyncReadFile("./package.json", "utf-8") + const { version } = JSON.parse(content) + return version +} const main = async () => { const target = process.argv[2] || './environment.prod.ts' @@ -13,29 +30,41 @@ const main = async () => { MATOMO_URL, MATOMO_ID, SIIBRA_API_ENDPOINTS, - VERSION, - GIT_HASH = 'unknown hash', EXPERIMENTAL_FEATURE_FLAG, ENABLE_LEAP_MOTION, } = process.env + const version = JSON.stringify( + await (async () => { + try { + return await getVersion() + } catch (e) { + return "unknown version" + } + })() + ) + const gitHash = JSON.stringify( + await (async () => { + try { + return await getGitHead() + } catch (e) { + return "unknown git hash" + } + })() + ) + console.log(`[parseEnv.js] parse envvar:`, { BACKEND_URL, STRICT_LOCAL, MATOMO_URL, MATOMO_ID, SIIBRA_API_ENDPOINTS, - VERSION, - GIT_HASH, EXPERIMENTAL_FEATURE_FLAG, ENABLE_LEAP_MOTION, + + VERSION: version, + GIT_HASH: gitHash, }) - const version = JSON.stringify( - VERSION || 'unknown version' - ) - const gitHash = JSON.stringify( - GIT_HASH || 'unknown hash' - ) const outputTxt = ` import { environment as commonEnv } from './environment.common'