Skip to content

Commit abcfa9f

Browse files
authored
build(frontend): Build Frontend Version into Image (#474)
* feat(frontend): Inject build version * build(frontend): Use corepack pnpm * chore(frontend): Update corepack * ci(backend): Deploy only when necessary * fix(frontend): Allow build/serve without --define
1 parent f7697fa commit abcfa9f

File tree

9 files changed

+40
-13
lines changed

9 files changed

+40
-13
lines changed

.github/workflows/deploy-backend.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ on:
66
- master
77
tags:
88
- v*
9-
# TODO the backend needs to be deployed every time because it contains the version number
10-
# paths:
11-
# - 'backend/**'
9+
paths:
10+
- 'backend/**'
11+
- '.github/workflows/deploy.sh'
12+
- '.github/workflows/deploy-backend.yml'
1213

1314
concurrency:
1415
group: deploy-backend

.github/workflows/deploy-frontend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
push: true
4343
tags: ${{ secrets.DOCKER_REGISTRY }}/fulib/fulib.org-frontend:${{ steps.deployment.outputs.tag }}
4444
build-args: |
45-
VERSION=${{ steps.deployment.outputs.version }}
45+
BUILD_VERSION=${{ steps.deployment.outputs.version }}
4646
cache-to: type=gha,mode=max
4747
cache-from: type=gha
4848
- name: Deploy to Rancher

frontend/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM node:lts-slim as builder
1+
FROM node:lts-slim AS builder
22
WORKDIR /frontend
3-
RUN npm install -g pnpm
43
COPY package.json pnpm-lock.yaml ./
5-
RUN pnpm install
4+
RUN corepack pnpm install
65
COPY . .
76
ARG CONFIGURATION=production
8-
RUN pnpm run build --configuration $CONFIGURATION
7+
ARG BUILD_VERSION=0.0.0
8+
RUN corepack pnpm run build --configuration $CONFIGURATION --define BUILD_VERSION=\"$BUILD_VERSION\"
99

1010
FROM nginx
1111
COPY nginx.conf /etc/nginx/conf.d/default.conf

frontend/angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"file-saver",
4141
"validator"
4242
],
43+
"define": {
44+
"BUILD_VERSION": "\"0.0.0\""
45+
},
4346
"serviceWorker": "ngsw-config.json",
4447
"scripts": []
4548
},

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"lint": "ng lint"
1111
},
1212
"private": true,
13+
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
1314
"dependencies": {
1415
"@angular/animations": "^19.1.2",
1516
"@angular/cdk": "^19.1.0",
@@ -83,6 +84,5 @@
8384
"webpack-dev-middleware": "^6.1.2",
8485
"cookie@<0.7.0": ">=0.7.0",
8586
"@sentry/browser@<7.119.1": "^7.119.1"
86-
},
87-
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
87+
}
8888
}

frontend/src/app/services/changelog.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {HttpClient} from '@angular/common/http';
22
import {Injectable} from '@angular/core';
3-
import {Observable} from 'rxjs';
4-
import {map, mapTo, tap} from 'rxjs/operators';
3+
import {Observable, of} from 'rxjs';
4+
import {catchError, map, mapTo, tap} from 'rxjs/operators';
55
import {environment} from '../../environments/environment';
66
import {MarkdownService} from './markdown.service';
77

@@ -52,7 +52,21 @@ export class ChangelogService {
5252
}
5353

5454
getCurrentVersions(): Observable<Versions> {
55-
return this.http.get<Versions>(environment.apiURL + '/versions');
55+
return this.http.get<Versions>(environment.apiURL + '/versions').pipe(
56+
tap(versions => {
57+
versions['fulib.org'] = environment.version;
58+
}),
59+
catchError(() => of<Versions>({
60+
'fulib.org': environment.version,
61+
fulib: 'unknown',
62+
fulibGradle: 'unknown',
63+
fulibScenarios: 'unknown',
64+
fulibTables: 'unknown',
65+
fulibTools: 'unknown',
66+
fulibWorkflows: 'unknown',
67+
fulibYaml: 'unknown',
68+
})),
69+
);
5670
}
5771

5872
stripBuildSuffix(versions: Versions): Versions {

frontend/src/environments/environment.prod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
declare const BUILD_VERSION: string;
2+
13
export const environment = {
24
production: true,
5+
version: BUILD_VERSION,
36
sentryDsn: 'https://613fdea31ffd44aa9f21da06ce6346e1@o416265.ingest.sentry.io/4505273320734720',
47
environment: 'production',
58
apiURL: '/api',

frontend/src/environments/environment.standalone.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
declare const BUILD_VERSION: string;
2+
13
export const environment = {
24
production: true,
5+
version: BUILD_VERSION,
36
sentryDsn: '',
47
environment: 'development',
58
apiURL: 'http://localhost:4567/api',

frontend/src/environments/environment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
declare const BUILD_VERSION: string;
2+
13
export const environment = {
24
production: false,
5+
version: BUILD_VERSION,
36
sentryDsn: '',
47
environment: 'development',
58
apiURL: 'http://localhost:4567/api',

0 commit comments

Comments
 (0)