最近,我的工作场所已经从CircleCI过渡到Azure管道,因此,我们一直在迁移所有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'
这会导致无法继续进行的循环。如何获得apt-get命令在Azure Pipelines中运行?我应该注意,此Mac版本无需任何修改或需要docker镜像即可运行。
我如何使apt-get命令在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了解更多详细信息。
希望这会有所帮助。