Skip to content

Commit

Permalink
trying to fix docker build, so it includes git sha info.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed May 27, 2022
1 parent d7ddf01 commit c7c55ab
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_VERSION=${{ github.ref_type == "tag" && github.ref_name || github.ref_name + "#" + github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
omnibus:
Expand Down Expand Up @@ -151,5 +153,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_VERSION=${{ github.ref_type == "tag" && github.ref_name || github.ref_name + "#" + github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 3 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ RUN go mod vendor && \

########
FROM node:lts-slim as frontendbuild

ARG GIT_VERSION=""
#reduce logging, disable angular-cli analytics for ci environment
ENV NPM_CONFIG_LOGLEVEL=warn NG_CLI_ANALYTICS=false

WORKDIR /opt/scrutiny/src
COPY . /opt/scrutiny/src
COPY webapp/frontend /opt/scrutiny/src

RUN apt-get update && apt-get install -y git && \
cd webapp/frontend && \
npm install -g @angular/cli@9.1.4 && \
RUN npm install -g @angular/cli@9.1.4 && \
mkdir -p /scrutiny/dist && \
npm install && \
npm run build:prod -- --output-path=/opt/scrutiny/dist
Expand Down
9 changes: 4 additions & 5 deletions docker/Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ RUN go mod vendor && \

########
FROM node:lts-slim as frontendbuild

ARG GIT_VERSION=""
ENV
#reduce logging, disable angular-cli analytics for ci environment
ENV NPM_CONFIG_LOGLEVEL=warn NG_CLI_ANALYTICS=false

WORKDIR /opt/scrutiny/src
COPY . /opt/scrutiny/src
COPY webapp/frontend /opt/scrutiny/src

RUN apt-get update && apt-get install -y git && \
cd webapp/frontend && \
npm install -g @angular/cli@9.1.4 && \
RUN npm install -g @angular/cli@9.1.4 && \
mkdir -p /opt/scrutiny/dist && \
npm install && \
npm run build:prod -- --output-path=/opt/scrutiny/dist
Expand Down
20 changes: 12 additions & 8 deletions webapp/frontend/git.version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import * as child from 'child_process';
const exec = promisify(child.exec);

async function createVersionsFile(filename: string) {
const tag = (await exec('git describe --tags')).stdout.toString().trim();
const revision = (await exec('git rev-parse --short HEAD')).stdout.toString().trim();
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
let versionInfo = ''
if(process.env.GIT_VERSION){
versionInfo = process.env.GIT_VERSION
} else {
const tag = (await exec('git describe --tags')).stdout.toString().trim();
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();

versionInfo = (branch === 'master' ? tag : branch + '#' + tag)
}


console.log(`version: '${process.env.npm_package_version}', revision: '${revision}', branch: '${branch}'`);

const content = dedent`
// this file is automatically generated by git.version.ts script
export const versions = {
version: '${tag}',
revision: '${revision}',
branch: '${branch}'
export const versionInfo = {
version: '${versionInfo}',
};`;

writeFileSync(filename, content, {encoding: 'utf8'});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { TreoMediaWatcherService } from '@treo/services/media-watcher';
import { TreoNavigationService } from '@treo/components/navigation';
import {versions} from 'environments/versions';
import {versionInfo} from 'environments/versions';

@Component({
selector : 'material-layout',
Expand Down Expand Up @@ -49,7 +49,7 @@ export class MaterialLayoutComponent implements OnInit, OnDestroy
this.fixedHeader = false;
this.fixedFooter = false;

this.appVersion = `${versions.version}${versions.branch === 'master' ? '' : '#' + versions.branch}`
this.appVersion = versionInfo.version
}

// -----------------------------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions webapp/frontend/src/environments/versions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

// this file is automatically generated by git.version.ts script
export const versions = {
export const versionInfo = {
version: 'v0.0.0',
revision: 'abcdef123',
branch: 'master'
};

0 comments on commit c7c55ab

Please sign in to comment.