From efa55f881d6ee2681b008847372d69abf350ac21 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 18 Sep 2024 14:24:02 -0700 Subject: [PATCH] Modernize ensure-nodejs The ensure-nodejs role defaults to install nodejs 6 which produces this error currently: Failed to update apt cache: W:The repository 'https://deb.nodesource.com/node_6.x noble Release' does not have a Release file., W:Data from such a repository can't be authenticated and is therefore potentially dangerous to use. We need to make a few changes to bring this ensure-nodejs role up to modern expectations for nodesource usage. First we drop the default nodejs version from ensure-nodejs. Everyone is already setting this value to make this role work or they are broken and will need to change something anyway. This gets us off of the nodejs update treadmill in this role. Then with nodejs 16 and newer there is a new gpg key and no deb-src packages so we need to change the apt configuration if using 16 and newer. We make these changes to match the corresponding setup_16.x etc scripts from nodesource. Change-Id: I0d5c93e4fbcee0be2cc477bf9f625e419a2b9bd1 --- roles/ensure-nodejs/defaults/main.yaml | 2 -- roles/ensure-nodejs/tasks/main.yaml | 11 +++++++++++ zuul-tests.d/js-roles-jobs.yaml | 2 ++ zuul.d/python-jobs.yaml | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) delete mode 100644 roles/ensure-nodejs/defaults/main.yaml diff --git a/roles/ensure-nodejs/defaults/main.yaml b/roles/ensure-nodejs/defaults/main.yaml deleted file mode 100644 index f53b7ceef..000000000 --- a/roles/ensure-nodejs/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -node_version: 6 diff --git a/roles/ensure-nodejs/tasks/main.yaml b/roles/ensure-nodejs/tasks/main.yaml index 3a3715ffb..c97152fc0 100644 --- a/roles/ensure-nodejs/tasks/main.yaml +++ b/roles/ensure-nodejs/tasks/main.yaml @@ -25,6 +25,17 @@ repositories_list: - repo: deb-src https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main - repo: deb https://deb.nodesource.com/node_{{ node_version }}.x {{ ansible_distribution_release }} main + when: node_version | int < 16 + +- name: Add all repositories + include_role: + name: ensure-package-repositories + vars: + repositories_keys: + - url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key + repositories_list: + - repo: deb https://deb.nodesource.com/node_{{ node_version }}.x nodistro main + when: node_version | int >= 16 # Use template so that we can easily update this in the future to be able to # use a mirror location. diff --git a/zuul-tests.d/js-roles-jobs.yaml b/zuul-tests.d/js-roles-jobs.yaml index 587f791ac..85aba50a2 100644 --- a/zuul-tests.d/js-roles-jobs.yaml +++ b/zuul-tests.d/js-roles-jobs.yaml @@ -7,6 +7,7 @@ run: test-playbooks/simple-role-test.yaml vars: role_name: ensure-nodejs + node_version: 20 - job: name: zuul-jobs-test-ensure-yarn @@ -18,6 +19,7 @@ run: test-playbooks/simple-role-test.yaml vars: role_name: ensure-yarn + node_version: 20 - job: name: zuul-jobs-test-fetch-javascript-tarball diff --git a/zuul.d/python-jobs.yaml b/zuul.d/python-jobs.yaml index fdd21e739..796aba2f9 100644 --- a/zuul.d/python-jobs.yaml +++ b/zuul.d/python-jobs.yaml @@ -327,7 +327,7 @@ Command to pass to npm. .. zuul:jobvar:: node_version - :default: 6 + :default: 14 The version of Node to use.