Skip to content

Commit 9ded2cc

Browse files
authored
fix(flake.nix): synchronize playwright version in nix and package.json (coder#16715)
Ensure that the version of Playwright installed with the Nix flake is equal to the one specified in `site/package.json.` -- This assertion ensures that `pnpm playwright:install` will not attempt to download newer browser versions not present in the Nix image, fixing the startup script and reducing the startup time, as `pnpm playwright:install` will not download or install anything. We also pre-install the required Playwright web browsers in the dogfood Dockerfile. This change prevents us from redownloading system dependencies and Google Chrome each time a workspace starts. Change-Id: I8cc78e842f7d0b1d2a90a4517a186a03636c5559 Signed-off-by: Thomas Kosiewski <tk@coder.com> Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 3005cb4 commit 9ded2cc

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

dogfood/contents/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
244244
RUN npm install -g npm@^10.8
245245
RUN npm install -g pnpm@^9.6
246246

247+
RUN pnpx playwright@1.47.0 install --with-deps chromium
248+
247249
# Ensure PostgreSQL binaries are in the users $PATH.
248250
RUN update-alternatives --install /usr/local/bin/initdb initdb /usr/lib/postgresql/16/bin/initdb 100 && \
249251
update-alternatives --install /usr/local/bin/postgres postgres /usr/lib/postgresql/16/bin/postgres 100

dogfood/contents/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ resource "coder_agent" "dev" {
351351
sleep 1
352352
done
353353
cd "${local.repo_dir}" && make clean
354-
cd "${local.repo_dir}/site" && pnpm install && pnpm playwright:install
354+
cd "${local.repo_dir}/site" && pnpm install
355355
EOT
356356
}
357357

flake.nix

+11-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
(pinnedPkgs.golangci-lint)
122122
gopls
123123
gotestsum
124+
hadolint
124125
jq
125126
kubectl
126127
kubectx
@@ -216,6 +217,14 @@
216217
'';
217218
};
218219
in
220+
# "Keep in mind that you need to use the same version of playwright in your node playwright project as in your nixpkgs, or else playwright will try to use browsers versions that aren't installed!"
221+
# - https://nixos.wiki/wiki/Playwright
222+
assert pkgs.lib.assertMsg
223+
(
224+
(pkgs.lib.importJSON ./site/package.json).devDependencies."@playwright/test"
225+
== pkgs.playwright-driver.version
226+
)
227+
"There is a mismatch between the playwright versions in the ./nix.flake and the ./site/package.json file. Please make sure that they use the exact same version.";
219228
rec {
220229
inherit formatter;
221230

@@ -261,12 +270,13 @@
261270

262271
uname = "coder";
263272
homeDirectory = "/home/${uname}";
273+
releaseName = version;
264274

265275
drv = devShells.default.overrideAttrs (oldAttrs: {
266276
buildInputs =
267277
(with pkgs; [
268278
coreutils
269-
nix
279+
nix.out
270280
curl.bin # Ensure the actual curl binary is included in the PATH
271281
glibc.bin # Ensure the glibc binaries are included in the PATH
272282
jq.bin

nix/docker.nix

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ let
5050
experimental-features = nix-command flakes
5151
'';
5252

53-
etcReleaseName = writeTextDir "etc/coderniximage-release" ''
54-
0.0.0
55-
'';
56-
5753
etcPamdSudoFile = writeText "pam-sudo" ''
5854
# Allow root to bypass authentication (optional)
5955
auth sufficient pam_rootok.so
@@ -115,6 +111,7 @@ let
115111
run ? null,
116112
maxLayers ? 100,
117113
uname ? "nixbld",
114+
releaseName ? "0.0.0",
118115
}:
119116
assert lib.assertMsg (!(drv.drvAttrs.__structuredAttrs or false))
120117
"streamNixShellImage: Does not work with the derivation ${drv.name} because it uses __structuredAttrs";
@@ -207,6 +204,10 @@ let
207204
'';
208205
};
209206

207+
etcReleaseName = writeTextDir "etc/coderniximage-release" ''
208+
${releaseName}
209+
'';
210+
210211
# https://github.com/NixOS/nix/blob/2.8.0/src/libstore/globals.hh#L464-L465
211212
sandboxBuildDir = "/build";
212213

site/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"@biomejs/biome": "1.9.4",
127127
"@chromatic-com/storybook": "3.2.2",
128128
"@octokit/types": "12.3.0",
129-
"@playwright/test": "1.47.2",
129+
"@playwright/test": "1.47.0",
130130
"@storybook/addon-actions": "8.5.2",
131131
"@storybook/addon-essentials": "8.4.6",
132132
"@storybook/addon-interactions": "8.5.3",

site/pnpm-lock.yaml

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)