From 8ab9c39f8cf6795d3b7d49da012668ba47230e3d Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 18 Dec 2022 12:10:16 +0000 Subject: [PATCH] Skip update check when running in Docker --- .gitlab-ci.yml | 2 +- resources/build/ci-package-json.js | 4 ++++ src/common/update.ts | 7 ++++++- src/util/product.ts | 9 +++++++++ src/util/useragent.ts | 3 ++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f5263b..adf4b63 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,7 +34,7 @@ build-docker: - | [ "$GH_REGISTRY_IMAGE" != "" ] && docker login -u "$GH_REGISTRY_USER" -p "$GH_REGISTRY_PASSWORD" "$GH_REGISTRY" script: - - node resources/build/ci-package-json.js + - node resources/build/ci-package-json.js docker "$CI_REGISTRY_IMAGE:ref-$CI_COMMIT_REF_SLUG" - docker build --pull --no-cache --tag "$CI_REGISTRY_IMAGE:ref-$CI_COMMIT_REF_SLUG" . - | diff --git a/resources/build/ci-package-json.js b/resources/build/ci-package-json.js index 00a54c0..8cc04c2 100644 --- a/resources/build/ci-package-json.js +++ b/resources/build/ci-package-json.js @@ -32,6 +32,10 @@ if (process.argv[2] === 'github') { pkg.version = process.env.VERSION || pkg.version; pkg.__nxapi_release = process.env.CI_COMMIT_TAG; +if (process.argv[2] === 'docker') { + pkg.__nxapi_docker = process.argv[3]; +} + pkg.__nxapi_git = pkg.__nxapi_git ?? { revision, branch: branch && branch !== 'HEAD' ? branch : null, diff --git a/src/common/update.ts b/src/common/update.ts index 070749c..c87ddd9 100644 --- a/src/common/update.ts +++ b/src/common/update.ts @@ -3,7 +3,7 @@ import * as fs from 'node:fs/promises'; import fetch from 'node-fetch'; import createDebug from 'debug'; import mkdirp from 'mkdirp'; -import { dir, version } from '../util/product.js'; +import { dir, docker, version } from '../util/product.js'; import { paths } from '../util/storage.js'; import { timeoutSignal } from '../util/misc.js'; @@ -12,6 +12,11 @@ const debug = createDebug('nxapi:update'); const RELEASES_URL = 'https://api.github.com/repos/samuelthomas2774/nxapi/releases'; export async function checkUpdates() { + if (docker) { + debug('Running in Docker container, skipping update check'); + return null; + } + try { if (!process.versions.electron) { await fs.stat(path.join(dir, '.git')); diff --git a/src/util/product.ts b/src/util/product.ts index f07329c..ba941ee 100644 --- a/src/util/product.ts +++ b/src/util/product.ts @@ -39,6 +39,15 @@ const match = pkg.version.match(/^(\d+\.\d+\.\d+)-next\b/i); export const version: string = match?.[1] ?? pkg.version; export const release: string | null = embedded_release ?? pkg.__nxapi_release ?? null; +export const docker: string | true | null = pkg.__nxapi_docker ?? await (async () => { + try { + await fs.stat('/.dockerenv'); + return true; + } catch (err) { + return null; + } +})(); + export const git = typeof embedded_git !== 'undefined' ? embedded_git : pkg.__nxapi_git ?? await (async () => { try { await fs.stat(path.join(dir, '.git')); diff --git a/src/util/useragent.ts b/src/util/useragent.ts index 190f707..4cea42d 100644 --- a/src/util/useragent.ts +++ b/src/util/useragent.ts @@ -1,10 +1,11 @@ import * as process from 'node:process'; import * as os from 'node:os'; -import { git, release, version } from '../util/product.js'; +import { docker, git, release, version } from '../util/product.js'; const default_useragent = 'nxapi/' + version + ' (' + (!release && git ? 'git ' + git.revision.substr(0, 7) + (git.branch ? ' ' + git.branch : '') + '; ' : !release ? 'no-git; ' : '') + + (typeof docker === 'string' ? 'docker ' + docker + '; ' : docker ? 'docker; ' : '') + 'node ' + process.versions.node + '; ' + process.platform + ' ' + os.release() + ')';