From 295902db3a32ca8520c27219a8c14f0d0714b09c Mon Sep 17 00:00:00 2001 From: Anton SHEPILOV Date: Wed, 13 Mar 2024 15:43:53 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7Pass=20application=20version=20dock?= =?UTF-8?q?er=20build=20and=20to=20the=20applications=20themselves?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 2 +- .../config/custom-environment-variables.json | 3 +++ tdrive/backend/node/config/default.json | 3 +++ tdrive/backend/node/config/test.json | 3 +++ tdrive/backend/node/src/version.ts | 8 +++++--- .../docker/docker-bake.hcl | 9 ++++++++- tdrive/docker/tdrive-frontend/Dockerfile | 4 ++++ tdrive/docker/tdrive-node/Dockerfile | 4 ++++ tdrive/frontend/.gitignore | 1 + tdrive/frontend/package.json | 3 ++- tdrive/frontend/scripts/setVersion.js | 17 +++++++++++++++++ tdrive/frontend/src/app/environment/version.ts | 5 ----- 12 files changed, 51 insertions(+), 11 deletions(-) rename docker-bake.hcl => tdrive/docker/docker-bake.hcl (92%) create mode 100644 tdrive/frontend/scripts/setVersion.js delete mode 100644 tdrive/frontend/src/app/environment/version.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 779d8a0ef..088af6f6b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -80,7 +80,7 @@ jobs: uses: docker/bake-action@v4 with: files: | - ./docker-bake.hcl + ./tdrive/docker/docker-bake.hcl ${{ steps.meta.outputs.bake-file-annotations }} ${{ steps.meta.outputs.bake-file }} push: true diff --git a/tdrive/backend/node/config/custom-environment-variables.json b/tdrive/backend/node/config/custom-environment-variables.json index bb7df14f5..8e3a918ce 100644 --- a/tdrive/backend/node/config/custom-environment-variables.json +++ b/tdrive/backend/node/config/custom-environment-variables.json @@ -1,5 +1,8 @@ { "general": { + "version": { + "current": "TWAKE_DRIVE_VERSION" + }, "accounts": { "type": "ACCOUNTS_TYPE", "remote": { diff --git a/tdrive/backend/node/config/default.json b/tdrive/backend/node/config/default.json index dbd532784..8e22bea42 100644 --- a/tdrive/backend/node/config/default.json +++ b/tdrive/backend/node/config/default.json @@ -1,5 +1,8 @@ { "general": { + "version": { + "current": "1.0.1" + }, "help_url": false, "pricing_plan_url": "", "app_download_url": "https://twake.app/download", diff --git a/tdrive/backend/node/config/test.json b/tdrive/backend/node/config/test.json index 851c4e700..b1620a199 100644 --- a/tdrive/backend/node/config/test.json +++ b/tdrive/backend/node/config/test.json @@ -1,4 +1,7 @@ { + "version": { + "current": "1.0.1" + }, "database": { "secret": "", "mongodb": { diff --git a/tdrive/backend/node/src/version.ts b/tdrive/backend/node/src/version.ts index 7166ce9be..0f386d9c6 100644 --- a/tdrive/backend/node/src/version.ts +++ b/tdrive/backend/node/src/version.ts @@ -1,7 +1,9 @@ +import config from "config"; + export default { - current: /* @VERSION_DETAIL */ "2023.Q1.1223", + current: config.get("general.version.current") || "1.0.1", minimal: { - web: /* @MIN_VERSION_WEB */ "2022.Q2.975", - mobile: /* @MIN_VERSION_MOBILE */ "2022.Q2.975", + web: /* @MIN_VERSION_WEB */ "1.0.0", + mobile: /* @MIN_VERSION_MOBILE */ "1.0.0", }, }; diff --git a/docker-bake.hcl b/tdrive/docker/docker-bake.hcl similarity index 92% rename from docker-bake.hcl rename to tdrive/docker/docker-bake.hcl index 79bc11f6f..533e532db 100644 --- a/docker-bake.hcl +++ b/tdrive/docker/docker-bake.hcl @@ -3,12 +3,19 @@ function "generate_tags" { result = formatlist("%s:%s", image, tags) } -target "docker-metadata-action" {} +variable "GITHUB_REF_NAME" { + default = "$GITHUB_REF_NAME" +} + +target "docker-metadata-action" { tags = ["latest"] } target "_common" { platforms = ["linux/amd64", "linux/arm64"] context = "tdrive" inherits = ["docker-metadata-action"] + args = { + VERSION = "$GITHUB_REF_NAME" + } } target "backend" { diff --git a/tdrive/docker/tdrive-frontend/Dockerfile b/tdrive/docker/tdrive-frontend/Dockerfile index 496be1aee..2cd867984 100755 --- a/tdrive/docker/tdrive-frontend/Dockerfile +++ b/tdrive/docker/tdrive-frontend/Dockerfile @@ -1,6 +1,10 @@ # First stage: building frontend FROM node:lts AS build +ARG VERSION +ENV TWAKE_DRIVE_VERSION=$VERSION +RUN echo "Set application version to $TWAKE_DRIVE_VERSION" + RUN yarn global add webpack webpack-cli COPY frontend /tdrive-react/ diff --git a/tdrive/docker/tdrive-node/Dockerfile b/tdrive/docker/tdrive-node/Dockerfile index 3a5c03dba..58e85fcd4 100755 --- a/tdrive/docker/tdrive-node/Dockerfile +++ b/tdrive/docker/tdrive-node/Dockerfile @@ -21,6 +21,10 @@ COPY backend/node/ . # Add frontend Stage FROM node-base as installed-libs +ARG VERSION +ENV TWAKE_DRIVE_VERSION=$VERSION +RUN echo "Set application version to $TWAKE_DRIVE_VERSION" + COPY backend/node/ . #Install dev dependancies for build RUN export NODE_ENV=development diff --git a/tdrive/frontend/.gitignore b/tdrive/frontend/.gitignore index 9b9a9e1a8..7797eb305 100644 --- a/tdrive/frontend/.gitignore +++ b/tdrive/frontend/.gitignore @@ -7,6 +7,7 @@ # testing /coverage /src/app/environment/environment.ts +/src/app/environment/version.ts /src/app/environment/*-e # misc diff --git a/tdrive/frontend/package.json b/tdrive/frontend/package.json index be8c9dfdc..586c94abd 100644 --- a/tdrive/frontend/package.json +++ b/tdrive/frontend/package.json @@ -12,7 +12,8 @@ "dev:linter": "eslint src/", "test": "CI=true craco test --passWithNoTests", "start": "npm run dev:start", - "build": "npm run build-storybook && CI=false craco --max_old_space_size=4096 --optimize-for-size build", + "set:version": "node ./scripts/setVersion.js", + "build": "npm run set:version && npm run build-storybook && CI=false craco --max_old_space_size=4096 --optimize-for-size build", "build-storybook": "build-storybook -o public/storybook", "storybook": "concurrently \"start-storybook -p 6006 -s public\" \"npm run dev:tailwind\"" }, diff --git a/tdrive/frontend/scripts/setVersion.js b/tdrive/frontend/scripts/setVersion.js new file mode 100644 index 000000000..09899d0d3 --- /dev/null +++ b/tdrive/frontend/scripts/setVersion.js @@ -0,0 +1,17 @@ +const fs = require('fs'); + +const targetPath = `${__dirname}/../src/app/environment/version.ts`; +const appVersion = process.env.TWAKE_DRIVE_VERSION || '1.0.0'; + +const updatedData = `export default { + version: /* @VERSION */ '${appVersion}', + version_detail: /* @VERSION_DISPLAY_NAME */ '${appVersion}', + version_name: /* @VERSION_NAME */ 'Ghost-Dog', +};`; +fs.writeFile(targetPath, updatedData,(err) => { + if (err) { + console.error(`Error writing file: ${targetPath}`, err); + process.exit(1); + } + console.log(`Version set to: ${appVersion}`); +}); diff --git a/tdrive/frontend/src/app/environment/version.ts b/tdrive/frontend/src/app/environment/version.ts deleted file mode 100644 index 77e3e2a8b..000000000 --- a/tdrive/frontend/src/app/environment/version.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default { - version: /* @VERSION */ '2023.Q3.012', - version_detail: /* @VERSION_DETAIL */ '2023.Q3.012', - version_name: /* @VERSION_NAME */ 'Ghost-Dog', -};