docker image fix (#151)

* frontend docker build: pass GIT_COMMIT_HASH and GIT_BRANCH_NAME as env vars to remove dependency on git in webpack.config.js (for glitchtip)
fixes #150

* default to "unknown" if git and env vars not available

* add comment about error reporting for local use

Co-authored-by: sua yoo <sua@suayoo.com>
This commit is contained in:
Ilya Kreymer 2022-02-22 10:52:27 -08:00 committed by GitHub
parent 9bd402fa17
commit 8ede386a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

2
build-frontend.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
docker buildx build --build-arg GIT_COMMIT_HASH="$(git rev-parse --short HEAD)" --build-arg GIT_BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)" --build-arg RWP_BASE_URL="https://replayweb.page/" --platform linux/amd64 --push -t registry.digitalocean.com/btrix/webrecorder/browsertrix-frontend ./frontend/

View File

@ -10,6 +10,13 @@ COPY yarn.lock .
RUN yarn --frozen-lockfile RUN yarn --frozen-lockfile
COPY *.* ./ COPY *.* ./
COPY src ./src/ COPY src ./src/
ARG GIT_COMMIT_HASH
ENV GIT_COMMIT_HASH=${GIT_COMMIT_HASH}
ARG GIT_BRANCH_NAME
ENV GIT_BRANCH_NAME=${GIT_BRANCH_NAME}
RUN yarn build RUN yarn build
FROM nginx FROM nginx

View File

@ -17,14 +17,21 @@ const dotEnvPath = path.resolve(
); );
// Get git info to use as Glitchtip release version // Get git info to use as Glitchtip release version
const gitBranch = childProcess const execCommand = (cmd, defValue) => {
.execSync("git rev-parse --abbrev-ref HEAD") try {
.toString() return childProcess.execSync(cmd).toString().trim();
.trim(); } catch (e) {
const commitHash = childProcess return defValue;
.execSync("git rev-parse --short HEAD") }
.toString() }
.trim();
// Local dev only
// Git branch and commit hash is used to add build info to error reporter when running locally
const gitBranch = process.env.GIT_BRANCH_NAME ||
execCommand("git rev-parse --abbrev-ref HEAD", "unknown");
const commitHash = process.env.GIT_COMMIT_HASH ||
execCommand("git rev-parse --short HEAD", "unknown");
require("dotenv").config({ require("dotenv").config({
path: dotEnvPath, path: dotEnvPath,