Skip to content

Commit

Permalink
attempting to fix docker image build by generating frontend version i…
Browse files Browse the repository at this point in the history
…nformation before docker build.
  • Loading branch information
AnalogJ committed May 27, 2022
1 parent cf1bd3e commit 3971b37
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 54 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ jobs:
type=ref,enable=true,event=branch,suffix=-web
type=ref,enable=true,event=tag,suffix=-web
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: "Generate frontend version information"
run: "cd webapp/frontend && ./git.version.sh"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
Expand All @@ -105,10 +106,6 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
GITHUB_SHA=${{ env.GITHUB_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
omnibus:
Expand Down Expand Up @@ -143,7 +140,8 @@ jobs:
type=ref,enable=true,event=branch,suffix=-omnibus
type=ref,enable=true,event=tag,suffix=-omnibus
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: "Generate frontend version information"
run: "cd webapp/frontend && ./git.version.sh"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
Expand All @@ -155,9 +153,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
GITHUB_SHA=${{ env.GITHUB_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 2 additions & 0 deletions .github/workflows/release-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
uses: actions/checkout@v2
with:
ref: ${{github.event.release.tag_name}}
- name: "Generate frontend version information"
run: "cd webapp/frontend && ./git.version.sh"
- name: Build Frontend
run: |
cd webapp/frontend
Expand Down
4 changes: 1 addition & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ RUN go mod vendor && \

########
FROM node:lts-slim as frontendbuild
ARG GITHUB_REF_NAME=""
ARG GITHUB_REF_TYPE=""
ARG GITHUB_SHA=""

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

Expand Down
4 changes: 1 addition & 3 deletions docker/Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ RUN go mod vendor && \

########
FROM node:lts-slim as frontendbuild
ARG GITHUB_REF_NAME=""
ARG GITHUB_REF_TYPE=""
ARG GITHUB_SHA=""

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

Expand Down
33 changes: 33 additions & 0 deletions webapp/frontend/git.version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

if [[ -z "${CI}" ]]; then
echo "running locally (not in Github Actions). generating version file from git client"
GIT_TAG=`git describe --tags`
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`

if [[ "$GIT_BRANCH" == "master" ]]; then
VERSION_INFO="${GIT_TAG}"
else
VERSION_INFO="${GIT_BRANCH}#${GIT_TAG}"
fi
else
echo "running in Github Actions, generating version file from environmental variables"
# https://docs.github.com/en/actions/learn-github-actions/environment-variables
GITHUB_SHA
GITHUB_REF_NAME
GITHUB_REF_TYPE

VERSION_INFO="${GITHUB_REF_NAME}"

if [[ "$GITHUB_REF_TYPE" == "branch" ]]; then
VERSION_INFO="${VERSION_INFO}#${GITHUB_SHA::7}"
fi
fi

echo "writing version file (version: ${VERSION_INFO})"
cat <<EOT > src/environments/versions.ts
// this file is automatically generated by git.version.ts script
export const versionInfo = {
version: '${VERSION_INFO}',
};
EOT
34 changes: 0 additions & 34 deletions webapp/frontend/git.version.ts

This file was deleted.

2 changes: 0 additions & 2 deletions webapp/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"license": "https://themeforest.net/licenses/standard",
"scripts": {
"ng": "ng",
"prestart": "ts-node -O '{\"module\": \"commonjs\"}' git.version.ts",
"start": "ng serve --open",
"start:mem": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng serve --open",
"prebuild:prod": "ts-node -O '{\"module\": \"commonjs\"}' git.version.ts",
"build": "ng build",
"build:prod": "ng build --prod",
"build:prod:mem": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --prod",
Expand Down
3 changes: 1 addition & 2 deletions webapp/frontend/src/environments/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

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

0 comments on commit 3971b37

Please sign in to comment.