npm install -g in onCreateCommand doesn't work in GitHub Actions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với devcontainer.json và cdk.yml được hiển thị, sau đó kiểm tra bước devcontainers/ci cùng với người dùng, HOME và môi trường npm mà bước này tạo ra. Tái hiện lệnh npm install --global ở cục bộ và trong GitHub Actions, đồng thời so sánh người dùng thực tế và các đường dẫn home. Hoàn tất khi phiên bản npm đã cấu hình được cài đặt thành công trong cả hai môi trường mà không gặp lỗi quyền /home/runner.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I'm not sure if this is an issue with devcontainers/ci, GitHub Actions, npm, or what, but I'm hoping that someone here can provide some insight.
Here is my setup:
My devcontainer.json
{
"name": "Jekyll Site With AWS Backend",
"image": "mcr.microsoft.com/devcontainers/jekyll:2.2.7-3.4-bookworm",
"features": {
"ghcr.io/devcontainers/features/git:1": {
"version": "os-provided"
},
"ghcr.io/devcontainers/features/git-lfs:1": {
"autoPull": true,
"installDirectlyFromGitHubRelease": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/aws-cli:1": {
"version": "2.34.12"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "24"
}
},
"forwardPorts": [
4000, // Jekyll server
9229 // Node.js debugging
],
// Ensure the ~/.gnupg dir exists, otherwise the bind mount below will fail.
// mkdir -p option ensures no error if the dir already exists.
"initializeCommand": "mkdir -p ${localEnv:HOME}${localEnv:USERPROFILE}/.gnupg/",
"onCreateCommand": {
"updateNpm": "npm install --global [email protected]",
"aptUpdate": "sudo apt-get update && sudo apt-get upgrade --yes"
},
"updateContentCommand": {
"npm": "cd cdk/ && npm install",
"bundle": "cd web/ && bundle install"
},
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.gnupg/,target=/home/vscode/.gnupg/,type=bind"
]
}
My GitHub Actions workflow definition (`cdk.yml`)
name: CDK Synth and Deploy
on:
push:
branches: [main]
paths: [cdk/**, ".github/workflows/cdk.yml", ".devcontainer/**"]
pull_request:
branches: [main]
paths: [cdk/**, ".github/workflows/cdk.yml", ".devcontainer/**"]
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
cdk:
runs-on: ubuntu-latest # Ubuntu version doesn't matter, everything will be running in our devcontainer anyway
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'test' }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
lfs: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step builds the devcontainer and runs commands inside it, so CI env matches developer machines.
- name: CDK Synth and Deploy in Devcontainer
uses: devcontainers/[email protected]
env:
IMAGE_NAME: ghcr.io/dansite/devcontainer
with:
imageName: ${{ env.IMAGE_NAME }}
cacheFrom: ${{ env.IMAGE_NAME }} # Pre-build devcontainer image
inheritEnv: true
skipContainerUserIdUpdate: true # Don't update the user of the devcontainer to match the host (i.e., keep it `vscode` not `runner`)
runCmd: |
cd cdk/
npm ci
# Do other stuff
When building and opening this devcontainer locally in VS Code on Windows, everything works fine. However, when the devcontainers/ci step runs in GitHub Actions, I get the following error logs):
Error message
npm error code EACCES
npm error syscall mkdir
npm error path /home/runner
npm error errno EACCES
npm error FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/npm: EACCES: permission denied, mkdir '/home/runner'
npm error at /usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:174:15
npm error at async Response.json (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/node_modules/minipass-fetch/lib/body.js:75:17)
npm error at async RegistryFetcher.packument (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/node_modules/pacote/lib/registry.js:98:25)
npm error at async RegistryFetcher.manifest (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/node_modules/pacote/lib/registry.js:128:23)
npm error at async Install.exec (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/lib/commands/install.js:114:27)
npm error at async Npm.exec (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/lib/npm.js:209:9)
npm error at async module.exports (/usr/local/share/nvm/versions/node/v24.14.1/lib/node_modules/npm/lib/cli/entry.js:67:5) {
npm error code: 'EACCES',
npm error errno: 'EACCES',
npm error syscall: 'mkdir',
npm error path: '/home/runner',
npm error type: 'system'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error Log files were not written due to an error writing to the directory: /home/runner/.npm/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
The EACCES: permission denied, mkdir '/home/runner' part is super confusing to me. If commands in my devcontainer are running as the default vscode user, then why is npm trying to create a directory at /home/runner, especially when I have skipContainerUserIdUpdate: true set on the GitHub Actions step? For that matter, why is npm trying to create a home directory at all? How can I modify the above files to ensure that my devcontainer has the latest npm version both locally and in GitHub Actions workflows? Thanks in advance!
- Ngôn ngữ chính
- TypeScript
- Star
- 499
- Fork
- 101
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của devcontainers/ci
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
devcontainers/ci#446 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
devcontainers/ci#445 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
devcontainers/ci#444 · 2 bình luận · 3 reaction ·
-
Inputs are wrong in post step when action is called through a nested composite actionCó thể làm lại được @v-Kaniska244 đã nhận 61 ngày trước và không có pull request nào đang mở. Đang mở
devcontainers/ci#442 · 1 người được giao ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
devcontainers/ci#430 ·
Tất cả issue của devcontainers/ci
Issue tương tự
-
feat(subscription): add Manage Subscription (Stripe portal) to the Subscription tab plan cardĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature] 通知栏合并重复消息并显示次数Đang mởarea:ui enhancement issue-form:feature platform:cross-platform review: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
1lck/Lithe-IDEA#1092 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
developmentseed/deck.gl-raster#693 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Marker-Inc-Korea/AutoRAG#1801 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
iii-hq/iii#2278 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày