diff --git a/build-frontend.sh b/build-frontend.sh new file mode 100755 index 00000000..e065f86f --- /dev/null +++ b/build-frontend.sh @@ -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/ diff --git a/frontend/Dockerfile b/frontend/Dockerfile index ef81976b..b44ba867 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -10,6 +10,13 @@ COPY yarn.lock . RUN yarn --frozen-lockfile COPY *.* ./ 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 FROM nginx diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index 62bc8fac..66e54d64 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -17,14 +17,21 @@ const dotEnvPath = path.resolve( ); // Get git info to use as Glitchtip release version -const gitBranch = childProcess - .execSync("git rev-parse --abbrev-ref HEAD") - .toString() - .trim(); -const commitHash = childProcess - .execSync("git rev-parse --short HEAD") - .toString() - .trim(); +const execCommand = (cmd, defValue) => { + try { + return childProcess.execSync(cmd).toString().trim(); + } catch (e) { + return defValue; + } +} + +// 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({ path: dotEnvPath,