PowerShell / PowerShell/PowerShell-Docker

Add `entrypoint` routing, which supports routing string-based commands to different executables, with special logic for `pwsh`

未关闭
#398 13 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@TravisEz13 已经在做这个了。

开始于 2020年3月27日。

Breaking Change Committee-Reviewed Issue-Enhancement
主要语言
Dockerfile
星标
449
派生
158
平均合并
3 天 10 小时
30 天内合并 PR
1

描述

Goal

Add entrypoint routing, which supports routing string-based commands to different executables, with special logic for pwsh. In order to:

  • Provide actionable error messages. Users should know that the entrypoint syntax they used failed in PowerShell, in Bash (or other shell), or in the script itself.
  • Support on Linux and Windows (a number of these appear like general concerns, not Linux-specific).
  • This avoids needing to
    • use the --entrypoint syntax to specify an executable, and
    • split the entrypoint (an argument to docker run) from its arguments (arguments to the container; they show up last).

Background

The best practice in docker is for an image to run the product in contains.
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint

Currently our images only run PowerShell when no command is specified. This is specified in the CMD entry in the Dockerfile.

Unfortunately, making the change causes a breaking change to the image in what is hopefully a corner case.

Customer requests for this are in #274 and #394

Proof of concept is here: https://github.com/PowerShell/PowerShell-Docker/pull/399

Other Language images
  • Work similar to the proposal
    • php
    • node
  • Like our current image
    • perl (perldebug)
    • python
  • Dumps you in bash
    • golang

Proposal

  1. Add a shell script that will detect if you are running pwsh (or similar), if so, send it to bash, otherwise run pwsh -nologo -l -c "$@"
  2. set that script as the ENTRYPOINT
  3. SetCMD to [ "pwsh" ]
  • Maintain the most features
  • Achieves the goals of the best practices
New Scenario

Note the lack of pwsh -c.

docker  run --rm  mcr.microsoft.com/powershell:7.1.0-preview.1-ubuntu-18.04 '$psversiontable.PSVersion.ToString()'
Will continue to work
docker  run --rm  mcr.microsoft.com/powershell:7.1.0-preview.1-ubuntu-18.04 pwsh -c '$psversiontable.PSVersion.ToString()'

Breaking change

Scenario - Running PowerShell using container
Working command with current images
docker  run --rm  mcr.microsoft.com/powershell:7.1.0-preview.1-ubuntu-18.04 /opt/microsoft/powershell/7-preview/pwsh -c '$psversiontable.PSVersion.ToString()'
Scenario - Expected result (with current image)
7.1.0-preview.1
Actual result (with private build with change)
ParserError: 
Line |
   1 |  7.1.0-preview.1
     |       ~~~~~~~~
     | Unexpected token '-preview' in expression or statement.
Workaround

Use --% to prevent the new PowerShell entrypoint from parsing the command.

docker  run --rm  mcr.microsoft.com/powershell:7.1.0-preview.1-ubuntu-18.04 /opt/microsoft/powershell/7-preview/pwsh --% -c '$psversiontable.PSVersion.ToString()'
Entry point script - Ubuntu
#!/bin/sh
set -e

# first arg is `pwsh` or similar
if ! { [ $1 = 'pwsh' ] || [ $1 = 'pwsh-preview' ]; }; then
 set -- pwsh -nologo -l -c "$@"
fi

exec "$@"

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。