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

👷 Pass application version docker build and to the applications #445

Closed
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: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tdrive/backend/node/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"general": {
"version": {
"current": "TWAKE_DRIVE_VERSION"
},
"accounts": {
"type": "ACCOUNTS_TYPE",
"remote": {
Expand Down
3 changes: 3 additions & 0 deletions tdrive/backend/node/config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"general": {
"version": {
"current": "1.0.1"
},
"help_url": false,
"pricing_plan_url": "",
"app_download_url": "https://twake.app/download",
Expand Down
3 changes: 3 additions & 0 deletions tdrive/backend/node/config/test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"version": {
"current": "1.0.1"
},
"database": {
"secret": "",
"mongodb": {
Expand Down
8 changes: 5 additions & 3 deletions tdrive/backend/node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import config from "config";

export default {
current: /* @VERSION_DETAIL */ "2023.Q1.1223",
current: config.get<string>("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",
},
};
9 changes: 8 additions & 1 deletion docker-bake.hcl → tdrive/docker/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

@tk-nguyen tk-nguyen Mar 14, 2024

Choose a reason for hiding this comment

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

This should be "${GITHUB_REF_NAME}" for it to work.

See https://docs.docker.com/build/bake/reference/#interpolate-variables-into-attributes for more details

}
}

target "backend" {
Expand Down
4 changes: 4 additions & 0 deletions tdrive/docker/tdrive-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
4 changes: 4 additions & 0 deletions tdrive/docker/tdrive-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tdrive/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# testing
/coverage
/src/app/environment/environment.ts
/src/app/environment/version.ts
/src/app/environment/*-e

# misc
Expand Down
3 changes: 2 additions & 1 deletion tdrive/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
},
Expand Down
17 changes: 17 additions & 0 deletions tdrive/frontend/scripts/setVersion.js
Original file line number Diff line number Diff line change
@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have a default ? If setting the version and one isn't provided, fail

Copy link
Member Author

Choose a reason for hiding this comment

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

it's for the local build, when you don't need a version


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}`);
});
5 changes: 0 additions & 5 deletions tdrive/frontend/src/app/environment/version.ts

This file was deleted.

Loading