Skip to content

Commit 8569314

Browse files
scmmishravishnu-narayanan
authored and
Diego Santos
committed
fix: Corepack pnpm issue (chatwoot#10840)
So, a while back Circle CI builds and Heroku builds started to fail. From all the threads I read, it seems like the [npm registry rotated it's signing keys](pnpm/pnpm#9014 (comment)) New pnpm versions were signed with the new key. Corepack, however, bundles a static set of trusted keys (from Node’s release), so it continued verifying signatures only against the old key. When it encountered packages signed with the new key, Corepack’s integrity check failed with “Cannot find matching keyid” errors.This mismatch caused Corepack’s integrity check to fail with “Cannot find matching keyid” errors. Workarounds include the following 1. Updating Corepack (to 0.31.0), they [upgraded their package](https://github.com/nodejs/corepack/releases/tag/v0.31.0) to include the new integrity check keys. But we seldom control what's going on with the CI, also, updating this across our scripts is going to be a painful task. Besides Heroku has [made some fixes](heroku/buildpacks-nodejs#1010) around this 2. Disabling integrity checks 🔥 #YOLO 3. Pinning `pnpm` to older versions, or pinning it to a newer version with the checksum in place. Doing the third one here, running `corepack use [email protected]` fixes this, [ref](pnpm/pnpm#9014 (comment)) We can get rid of this over time as CDN caches used by build systems are refreshed. But the change in this PR is not disruptive in anyway, only rigidly secure. Fixes: chatwoot#10832 --- Here are the threads to follow - pnpm/pnpm#9014 - pnpm/pnpm#9029 - nodejs/corepack#612 - nodejs/corepack#616 - heroku/buildpacks-nodejs#1010 --------- Co-authored-by: Vishnu Narayanan <[email protected]>
1 parent 4f8f102 commit 8569314

File tree

8 files changed

+58
-45
lines changed

8 files changed

+58
-45
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- checkout
2121
- node/install:
22-
node-version: '20.12'
22+
node-version: '23.7'
2323
- node/install-pnpm
2424
- node/install-packages:
2525
pkg-manager: pnpm

.devcontainer/docker-compose.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
version: '3'
66

77
services:
8-
base:
8+
base:
99
build:
1010
context: ..
1111
dockerfile: .devcontainer/Dockerfile.base
1212
args:
13-
VARIANT: "ubuntu-22.04"
14-
NODE_VERSION: "20.9.0"
15-
RUBY_VERSION: "3.3.3"
13+
VARIANT: 'ubuntu-22.04'
14+
NODE_VERSION: '23.7.0'
15+
RUBY_VERSION: '3.3.3'
1616
# On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000.
17-
USER_UID: "1000"
18-
USER_GID: "1000"
17+
USER_UID: '1000'
18+
USER_GID: '1000'
1919
image: base:latest
20-
20+
2121
app:
2222
build:
2323
context: ..
2424
dockerfile: .devcontainer/Dockerfile
2525
args:
26-
VARIANT: "ubuntu-22.04"
27-
NODE_VERSION: "20.9.0"
28-
RUBY_VERSION: "3.3.3"
26+
VARIANT: 'ubuntu-22.04'
27+
NODE_VERSION: '23.7.0'
28+
RUBY_VERSION: '3.3.3'
2929
# On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000.
30-
USER_UID: "1000"
31-
USER_GID: "1000"
30+
USER_UID: '1000'
31+
USER_GID: '1000'
3232

3333
volumes:
3434
- ..:/workspace:cached

.github/workflows/frontend-fe.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ jobs:
2323
bundler-cache: true
2424

2525
- uses: pnpm/action-setup@v4
26-
with:
27-
version: 9.3.0
2826

2927
- uses: actions/setup-node@v4
3028
with:
31-
node-version: 20
29+
node-version: 23
3230
cache: 'pnpm'
3331

3432
- name: Install pnpm dependencies

.github/workflows/run_foss_spec.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
- uses: actions/checkout@v4
3939
- uses: pnpm/action-setup@v4
4040
with:
41-
version: 9
4241
ref: ${{ github.event.pull_request.head.ref }}
4342
repository: ${{ github.event.pull_request.head.repo.full_name }}
4443

@@ -48,7 +47,7 @@ jobs:
4847

4948
- uses: actions/setup-node@v4
5049
with:
51-
node-version: 20
50+
node-version: 23
5251
cache: 'pnpm'
5352

5453
- name: Install pnpm dependencies

.github/workflows/size-limit.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ jobs:
1919
with:
2020
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
2121

22-
- uses: pnpm/action-setup@v2
23-
with:
24-
version: 9.3.0
22+
- uses: pnpm/action-setup@v4
2523

2624
- uses: actions/setup-node@v4
2725
with:
28-
node-version: 20
26+
node-version: 23
2927
cache: 'pnpm'
3028

3129
- name: pnpm
@@ -39,13 +37,11 @@ jobs:
3937
- name: setup env
4038
run: |
4139
cp .env.example .env
42-
40+
4341
- name: Run asset compile
4442
run: bundle exec rake assets:precompile
4543
env:
4644
RAILS_ENV: production
4745

4846
- name: Size Check
4947
run: pnpm run size
50-
51-

deployment/setup_20.04.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function install_dependencies() {
177177
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
178178
mkdir -p /etc/apt/keyrings
179179
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
180-
NODE_MAJOR=20
180+
NODE_MAJOR=23
181181
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
182182
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg 16" > /etc/apt/sources.list.d/pgdg.list
183183
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
@@ -779,15 +779,15 @@ function upgrade_node() {
779779
# Parse major version number
780780
major_version=$(echo "$current_version" | cut -d. -f1)
781781

782-
if [ "$major_version" -ge 20 ]; then
783-
echo "Node.js is already version $current_version (>= 20.x). Skipping Node.js upgrade."
782+
if [ "$major_version" -ge 23 ]; then
783+
echo "Node.js is already version $current_version (>= 23.x). Skipping Node.js upgrade."
784784
return
785785
fi
786786

787-
echo "Upgrading Node.js version to v20.x"
787+
echo "Upgrading Node.js version to v23.x"
788788
mkdir -p /etc/apt/keyrings
789789
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
790-
NODE_MAJOR=20
790+
NODE_MAJOR=23
791791
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
792792

793793
apt-get update

docker/Dockerfile

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# pre-build stage
2+
FROM node:23-alpine as node
23
FROM ruby:3.3.3-alpine3.19 AS pre-builder
34

5+
ARG NODE_VERSION="23.7.0"
6+
ARG PNPM_VERSION="10.2.0"
7+
ENV NODE_VERSION=${NODE_VERSION}
8+
ENV PNPM_VERSION=${PNPM_VERSION}
9+
410
# ARG default to production settings
511
# For development docker-compose file overrides ARGS
612
ARG BUNDLE_WITHOUT="development:test"
@@ -25,18 +31,24 @@ RUN apk update && apk add --no-cache \
2531
tzdata \
2632
postgresql-dev \
2733
postgresql-client \
28-
nodejs=20.15.1-r0 \
2934
git \
35+
curl \
36+
xz \
3037
&& mkdir -p /var/app \
3138
&& gem install bundler
3239

33-
# Install pnpm and configure environment
34-
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh - \
35-
&& echo 'export PNPM_HOME="/root/.local/share/pnpm"' >> /root/.shrc \
36-
&& echo 'export PATH="$PNPM_HOME:$PATH"' >> /root/.shrc \
37-
&& export PNPM_HOME="/root/.local/share/pnpm" \
38-
&& export PATH="$PNPM_HOME:$PATH" \
39-
&& pnpm --version
40+
COPY --from=node /usr/local/bin/node /usr/local/bin/
41+
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
42+
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
43+
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
44+
45+
RUN npm install -g pnpm@${PNPM_VERSION}
46+
47+
RUN echo 'export PNPM_HOME="/root/.local/share/pnpm"' >> /root/.shrc \
48+
&& echo 'export PATH="$PNPM_HOME:$PATH"' >> /root/.shrc \
49+
&& export PNPM_HOME="/root/.local/share/pnpm" \
50+
&& export PATH="$PNPM_HOME:$PATH" \
51+
&& pnpm --version
4052

4153
# Persist the environment variables in Docker
4254
ENV PNPM_HOME="/root/.local/share/pnpm"
@@ -86,6 +98,10 @@ RUN rm -rf /gems/ruby/3.3.0/cache/*.gem \
8698
# final build stage
8799
FROM ruby:3.3.3-alpine3.19
88100

101+
ARG NODE_VERSION="23.7.0"
102+
ARG PNPM_VERSION="10.2.0"
103+
ENV NODE_VERSION=${NODE_VERSION}
104+
ENV PNPM_VERSION=${PNPM_VERSION}
89105

90106
ARG BUNDLE_WITHOUT="development:test"
91107
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
@@ -114,11 +130,14 @@ RUN apk update && apk add --no-cache \
114130
vips \
115131
&& gem install bundler
116132

133+
COPY --from=node /usr/local/bin/node /usr/local/bin/
134+
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
135+
117136
RUN if [ "$RAILS_ENV" != "production" ]; then \
118-
apk add --no-cache nodejs=20.15.1-r0; \
119-
# Install pnpm and configure environment
120-
wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh - \
121-
&& source /root/.shrc \
137+
apk add --no-cache curl \
138+
&& ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
139+
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
140+
&& npm install -g pnpm@${PNPM_VERSION} \
122141
&& pnpm --version; \
123142
fi
124143

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@
139139
"vitest": "2.0.1"
140140
},
141141
"engines": {
142-
"node": "20.x",
143-
"pnpm": "9.x"
142+
"node": "23.x",
143+
"pnpm": "10.x"
144144
},
145145
"husky": {
146146
"hooks": {
@@ -162,5 +162,6 @@
162162
"*.scss": [
163163
"scss-lint"
164164
]
165-
}
165+
},
166+
"packageManager": "[email protected]+sha512.0d27364e0139c6aadeed65ada153135e0ca96c8da42123bd50047f961339dc7a758fc2e944b428f52be570d1bd3372455c1c65fa2e7aa0bfbf931190f9552001"
166167
}

0 commit comments

Comments
 (0)