运行 apt-get 在 Azure Pipelines 中的 Docker 图像中
Run apt-get in a Docker Image within Azure Pipelines
最近我的工作场所已经从 CircleCI 迁移到 Azure Pipelines,因此我们一直在迁移我们所有的 CI。虽然大多数都有些直截了当,但这个特定的管道需要 运行 在 docker 图像中完成我们的 linux 工作。这是 CircleCI:
中的内容
build:
docker:
- image: electronuserland/builder:wine-03.18
steps:
- run: apt-get update
- run: apt-get install -y libgnome-keyring-dev icnsutils graphicsmagick xz-utils rpm bsdtar
- run: yarn install
# run tests!
- run: yarn test -- -u
- run: yarn test -- --maxWorkers 2
# Build the React app and the Electron app
- run:
name: yarn run electron-pack
VERSION=$(node -p "var ipVer = require('./package.json').version; \
var semVer = require('semver'); \
var sprintf = require('sprintf-js').sprintf; \
sprintf('%s.%s.%s%s', semVer.major(ipVer), semVer.minor(ipVer), semVer.patch(ipVer), '$ReleaseVAR');")
yarn version --no-git-tag-version --new-version VERSION
yarn run electron-pack
# Move the packages into a separate directory
- run: mkdir dist/packages
- run: mv dist/*.exe dist/packages
- run: mv dist/*.AppImage dist/packages
- run: mv dist/*.deb dist/packages
- run: mv dist/*.rpm dist/packages
这是它在 Azure Pipelines 中的当前样子:
jobs:
- job: Linux
pool:
name: 'Hosted Ubuntu 1604'
vmImage: 'ubuntu-16.04'
container:
image: electronuserland/builder:wine-03.18
options: --privileged
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: 'Install Node.js'
#- script: apt-get update
# displayName: apt-get update
#- script: sudo apt-get install -y libgnome-keyring-dev icnsutils graphicsmagick xz-utils rpm bsdtar
# displayName: apt-get install
#- script: sudo apt-get -f install
#- script: sudo apt-get install -y wine
- task: Npm@1
inputs:
command: 'install'
- script: yarn test -- -u --coverage
displayName: yarn -u
- script: yarn test -- --maxWorkers 2 --coverage
displayName: yarn maxWorkers 2
- script: |
VER=$(node -p "var ipVer = require('./package.json').version; \
var semVer = require('semver'); \
var sprintf = require('sprintf-js').sprintf; \
sprintf('%s.%s.%s%s', semVer.major(ipVer), semVer.minor(ipVer), semVer.patch(ipVer), '$(Build.BuildNumber)');")
yarn version --no-git-tag-version --new-version $(VER)
yarn run electron-pack
任何尝试 运行 没有 'apt-get' 行的脚本在最后一个脚本期间失败,产生 Error: Exit code: ENOENT. spawn icns2png ENOENT 错误。
尝试 to run those lines, gives a
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?]
错误,并尝试 运行 'sudo apt-get' 给出
/__w/_temp/ac8e299a-ba1c-4e18-8baa-93d3f4a189e3.sh: line 1: sudo: command not found
错误。但是要安装 sudo 我需要能够 运行 'apt-get install sudo -y'
这样就造成无法进行的循环。如何在 Azure Pipelines 中获取到 运行 的 apt-get 命令?我应该注意到这个 运行 的 Mac 版本不需要任何修改或需要 docker 图像。
How can I get the apt-get commands to run inside the Azure Pipelines?
这似乎与 docker 图片有关。正如我们所知,Docker 图像通常没有 sudo
,默认情况下我们始终以 root
运行。在这种情况下,我们可以直接使用命令apt-get
。
但此映像似乎以非 root 身份运行,因此对于 root 访问权限,您必须切换到 root 身份。在 Dockerfile
中,您可以使用 USER 指令简单地切换用户身份;这通常默认为 运行 作为 root:
USER root
要解决此问题,您可能需要根据 image: electronuserland/builder:wine-03.18
.
自定义 docker 图像
您可以尝试查看 this thread 了解更多详情。
希望对您有所帮助。
最近我的工作场所已经从 CircleCI 迁移到 Azure Pipelines,因此我们一直在迁移我们所有的 CI。虽然大多数都有些直截了当,但这个特定的管道需要 运行 在 docker 图像中完成我们的 linux 工作。这是 CircleCI:
中的内容build:
docker:
- image: electronuserland/builder:wine-03.18
steps:
- run: apt-get update
- run: apt-get install -y libgnome-keyring-dev icnsutils graphicsmagick xz-utils rpm bsdtar
- run: yarn install
# run tests!
- run: yarn test -- -u
- run: yarn test -- --maxWorkers 2
# Build the React app and the Electron app
- run:
name: yarn run electron-pack
VERSION=$(node -p "var ipVer = require('./package.json').version; \
var semVer = require('semver'); \
var sprintf = require('sprintf-js').sprintf; \
sprintf('%s.%s.%s%s', semVer.major(ipVer), semVer.minor(ipVer), semVer.patch(ipVer), '$ReleaseVAR');")
yarn version --no-git-tag-version --new-version VERSION
yarn run electron-pack
# Move the packages into a separate directory
- run: mkdir dist/packages
- run: mv dist/*.exe dist/packages
- run: mv dist/*.AppImage dist/packages
- run: mv dist/*.deb dist/packages
- run: mv dist/*.rpm dist/packages
这是它在 Azure Pipelines 中的当前样子:
jobs:
- job: Linux
pool:
name: 'Hosted Ubuntu 1604'
vmImage: 'ubuntu-16.04'
container:
image: electronuserland/builder:wine-03.18
options: --privileged
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: 'Install Node.js'
#- script: apt-get update
# displayName: apt-get update
#- script: sudo apt-get install -y libgnome-keyring-dev icnsutils graphicsmagick xz-utils rpm bsdtar
# displayName: apt-get install
#- script: sudo apt-get -f install
#- script: sudo apt-get install -y wine
- task: Npm@1
inputs:
command: 'install'
- script: yarn test -- -u --coverage
displayName: yarn -u
- script: yarn test -- --maxWorkers 2 --coverage
displayName: yarn maxWorkers 2
- script: |
VER=$(node -p "var ipVer = require('./package.json').version; \
var semVer = require('semver'); \
var sprintf = require('sprintf-js').sprintf; \
sprintf('%s.%s.%s%s', semVer.major(ipVer), semVer.minor(ipVer), semVer.patch(ipVer), '$(Build.BuildNumber)');")
yarn version --no-git-tag-version --new-version $(VER)
yarn run electron-pack
任何尝试 运行 没有 'apt-get' 行的脚本在最后一个脚本期间失败,产生 Error: Exit code: ENOENT. spawn icns2png ENOENT 错误。 尝试 to run those lines, gives a
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?]
错误,并尝试 运行 'sudo apt-get' 给出
/__w/_temp/ac8e299a-ba1c-4e18-8baa-93d3f4a189e3.sh: line 1: sudo: command not found
错误。但是要安装 sudo 我需要能够 运行 'apt-get install sudo -y'
这样就造成无法进行的循环。如何在 Azure Pipelines 中获取到 运行 的 apt-get 命令?我应该注意到这个 运行 的 Mac 版本不需要任何修改或需要 docker 图像。
How can I get the apt-get commands to run inside the Azure Pipelines?
这似乎与 docker 图片有关。正如我们所知,Docker 图像通常没有 sudo
,默认情况下我们始终以 root
运行。在这种情况下,我们可以直接使用命令apt-get
。
但此映像似乎以非 root 身份运行,因此对于 root 访问权限,您必须切换到 root 身份。在 Dockerfile
中,您可以使用 USER 指令简单地切换用户身份;这通常默认为 运行 作为 root:
USER root
要解决此问题,您可能需要根据 image: electronuserland/builder:wine-03.18
.
您可以尝试查看 this thread 了解更多详情。
希望对您有所帮助。