Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace is-docker to is-inside-container #544

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Allow async `render()` in the custom engine ([#540](https://github.com/marp-team/marp-cli/pull/540) by [@GuillaumeDesforges](https://github.com/GuillaumeDesforges))

### Changed

- Replace `is-docker` to `is-inside-container` for detecting more virtualized containers ([#543](https://github.com/marp-team/marp-cli/issues/543), [#544](https://github.com/marp-team/marp-cli/pull/544))

## v3.2.0 - 2023-08-04

### Changed
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const esModules = [
'find-up',
'globby',
'import-meta-resolve',
'is-inside-container',
'is-docker',
'lighthouse-logger',
'locate-path',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"image-size": "^1.0.2",
"import-from": "^4.0.0",
"import-meta-resolve": "^3.0.0",
"is-docker": "^3.0.0",
"is-inside-container": "^1.0.0",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest-junit": "^16.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { keywordsAsArray } from './engine/meta-plugin'
import { error, isError } from './error'
import { TemplateOption } from './templates'
import { Theme, ThemeSet } from './theme'
import { isOfficialImage } from './utils/docker'
import { isOfficialDockerImage } from './utils/container'

type Overwrite<T, U> = Omit<T, Extract<keyof T, keyof U>> & U

Expand Down Expand Up @@ -132,7 +132,7 @@ export class MarpCLIConfig {
const preview = (() => {
const p = this.args.preview ?? this.conf.preview ?? false

if (p && isOfficialImage()) {
if (p && isOfficialDockerImage()) {
warn(
`Preview window cannot show within an official docker image. Preview option was ignored.`
)
Expand Down
4 changes: 2 additions & 2 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import templates, {
TemplateResult,
} from './templates/'
import { ThemeSet } from './theme'
import { isOfficialImage } from './utils/docker'
import { isOfficialDockerImage } from './utils/container'
import { pdfLib, setOutline } from './utils/pdf'
import {
generatePuppeteerDataDirPath,
Expand Down Expand Up @@ -545,7 +545,7 @@ export class Converter {
// directory so always create tmp file to home directory if in Linux.
// (There is an exception for an official docker image)
return baseFile.saveTmpFile({
home: process.platform === 'linux' && !isOfficialImage(),
home: process.platform === 'linux' && !isOfficialDockerImage(),
extension: '.html',
})
})()
Expand Down
4 changes: 2 additions & 2 deletions src/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { File, FileType } from './file'
import { Preview, fileToURI } from './preview'
import { Server } from './server'
import templates from './templates'
import { isOfficialImage } from './utils/docker'
import { isOfficialDockerImage } from './utils/container'
import { resetExecutablePath } from './utils/puppeteer'
import version from './version'
import watcher, { Watcher, notifier } from './watcher'
Expand Down Expand Up @@ -109,7 +109,7 @@ export const marpCli = async (
preview: {
alias: 'p',
describe: 'Open preview window',
hidden: isOfficialImage(),
hidden: isOfficialDockerImage(),
group: OptionGroup.Basic,
type: 'boolean',
},
Expand Down
6 changes: 6 additions & 0 deletions src/utils/container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import _isInsideContainer from 'is-inside-container'

export const isInsideContainer = () =>
isOfficialDockerImage() || _isInsideContainer()

export const isOfficialDockerImage = () => !!process.env.MARP_USER
4 changes: 0 additions & 4 deletions src/utils/docker.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { launch } from 'puppeteer-core'
import macDockIcon from '../assets/mac-dock-icon.png'
import { warn } from '../cli'
import { CLIErrorCode, error, isError } from '../error'
import { isDocker } from '../utils/docker'
import { findChromeInstallation } from './chrome-finder'
import { isInsideContainer } from './container'
import { findEdgeInstallation } from './edge-finder'
import { isWSL, resolveWindowsEnv } from './wsl'

Expand Down Expand Up @@ -76,11 +76,11 @@ export const generatePuppeteerLaunchArgs = async () => {
const args = new Set<string>(['--export-tagged-pdf', '--test-type'])

// Docker environment and WSL environment need to disable sandbox. :(
if (isDocker() || isWSL()) args.add('--no-sandbox')
if (isInsideContainer() || isWSL()) args.add('--no-sandbox')

// Workaround for Chrome 73 in docker and unit testing with CircleCI
// https://github.com/GoogleChrome/puppeteer/issues/3774
if (isDocker() || process.env.CI)
if (isInsideContainer() || process.env.CI)
args.add('--disable-features=VizDisplayCompositor')

// Enable View transitions API
Expand Down
8 changes: 4 additions & 4 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Preview } from '../src/preview'
import { Server } from '../src/server'
import { ThemeSet } from '../src/theme'
import * as docker from '../src/utils/docker'
import * as container from '../src/utils/container'
import * as version from '../src/version'
import { Watcher } from '../src/watcher'

Expand Down Expand Up @@ -224,7 +224,7 @@ describe('Marp CLI', () => {
describe('when CLI is running in an official Docker image', () => {
it('does not output help about --preview option', async () => {
const isOfficialImage = jest
.spyOn(docker, 'isOfficialImage')
.spyOn(container, 'isOfficialDockerImage')
.mockReturnValue(true)

try {
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('Marp CLI', () => {
describe('when CLI is running in an official Docker image', () => {
it('ignores --preview option with warning', async () => {
const isOfficialImage = jest
.spyOn(docker, 'isOfficialImage')
.spyOn(container, 'isOfficialDockerImage')
.mockReturnValue(true)
const warn = jest.spyOn(cli, 'warn').mockImplementation()

Expand Down Expand Up @@ -1187,7 +1187,7 @@ describe('Marp CLI', () => {
describe('when CLI is running in an official Docker image', () => {
it('ignores --preview option with warning', async () => {
const isOfficialImage = jest
.spyOn(docker, 'isOfficialImage')
.spyOn(container, 'isOfficialDockerImage')
.mockReturnValue(true)

try {
Expand Down
8 changes: 4 additions & 4 deletions test/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const puppeteerUtils = (): typeof import('../../src/utils/puppeteer') =>
const chromeFinder = (): typeof import('../../src/utils/chrome-finder') =>
require('../../src/utils/chrome-finder')

const docker = (): typeof import('../../src/utils/docker') =>
require('../../src/utils/docker')
const container = (): typeof import('../../src/utils/container') =>
require('../../src/utils/container')

const edgeFinder = (): typeof import('../../src/utils/edge-finder') =>
require('../../src/utils/edge-finder')
Expand Down Expand Up @@ -152,8 +152,8 @@ describe('#generatePuppeteerLaunchArgs', () => {
}
})

it('uses specific settings if running within a Docker container', async () => {
jest.spyOn(docker(), 'isDocker').mockImplementation(() => true)
it('uses specific settings if running within a container image', async () => {
jest.spyOn(container(), 'isInsideContainer').mockImplementation(() => true)
jest
.spyOn(chromeFinder(), 'findChromeInstallation')
.mockResolvedValue('/usr/bin/chromium')
Expand Down