Anyone had success using VC Code Dev Containers for developing custom workspace components with now-cli?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 01:09 AM
I like using VS Code DEV Containers. It's a great feature to create specific development environments that can be shared among the team and across devices. The now-cli getting started documentation states that nodejs v12.16.1 and npm v6.13.4 is required. However, my local machine is on a newer version of nodejs. So I thought I'd try a devcontainer.
EDIT: I realised that the CLI tools for custom component development has changed so I don't want to mislead anyone into using now-cli when they should be using snc. See my reply to this post for where I have gotten with creating a VS Code development container for use with snc.
These are steps taken to setup a container for the deprecated now-cli utility.
I created the container with the following files in the folder ./devcontainer
.devcontainer.json
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "12-bullseye" }
},
"settings": {},
"extensions": ["dbaeumer.vscode-eslint", "servicenow.now-vscode"],
"remoteUser": "node",
"features": {
"git": "os-provided"
}
}
Dockerfile
ARG VARIANT="12-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libsecret-1-0
ARG EXTRA_NODE_VERSION=12.16.1
RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
RUN su node -c "npm install --unsafe-perm=true -g @servicenow/cli"
This creates a container with the correct version of node. now-cli is installed and ready to go.
But when I attempt to login to an instance with the command now-cli login [host] [method] [username] [password]
I get an error.
⠼ Checking connection...
COULD NOT VALIDATE INSTANCE VERSION BY ACCESSING: https://xxx.service-now.com/stats.do
INSTANCE VERSION COULD NOT BE VALIDATED!
✖ Connection to 'https://xxx.service-now.com' failed. Credentials not saved.
Cannot autolaunch D-Bus without X11 $DISPLAY
I can confirm the container is able to access the stats.do page of the instance by running curl.
This has been bugging me to get working today. I'm wondering if anyone had attempted this and got it working or have some suggestions?
- Labels:
-
Now Experience UI Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 05:05 PM
Realising after writing the original post that now-cli has been replaced with snc I attempted again to setup a development container but this time with the new tool. There is an issue with saving credentials to access the ServiceNow instance which is preventing this from being usable. The issue seems to be a known problem with using gnome-keyring on headless machines.
I'm sharing where I got with this here in case anyone wants to attempt it and/or suggest a fix for the credentials.
So in my project folder, I have the following structure;
.devcontainer/
- Dockerfile
- devcontainer.json
- snc-1.1.0-linux-x64-installer.run
The snc installer was downloaded from the ServiceNow Store, unzipped and placed in the folder.
The contents of the text files
devcontainer.json
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "12-bullseye" }
},
"settings": {},
"extensions": ["dbaeumer.vscode-eslint", "servicenow.now-vscode"],
"remoteUser": "node",
"features": {
"git": "os-provided"
},
"runArgs": ["--cap-add=IPC_LOCK"]
}
Here in devcontainer.json I am using the standard nodejs v12 image and including the ServiceNow and ESLint Vs Code extensions. I have added an argument to be passed to docker when running the container to enable IPC_LOCK. This is required to allow dbus to work which is required for gnome-keyring.
Dockerfile
ARG VARIANT="12-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends dbus-x11 gnome-keyring
WORKDIR /tmp/servicenow
COPY snc-1.1.0-linux-x64-installer.run .
RUN ./snc-1.1.0-linux-x64-installer.run --mode unattended
RUN . ~/.profile && snc extension add --name ui-component
ENV PATH="${PATH}:/opt/ServiceNow CLI/bin"
In the dockerfile I am using the Microsoft provided NodeJS v12 image. I then install dbus and gnome-keyring which are used by snc to store credentials on linux operating systems. After this the snc installer is copied to a temporary folder and run. The user's path variable is updated by the command . ~/.profile followed by running snc to add the ui-component extension
Finally, the PATH environment variable in the image is updated to include the path to the servicenow cli binaries so they are accessible by non-root users.
After building this image and starting the container the first step is to create a profile by the command;
snc configure profile set
This is where an issue with gnome-keyring appears. After providing a host and a user account the following response is given.
✔ Connection to https://xyz.service-now.com successful.
✗ This instance does not support dynamic commands. Functionality will be limited.
Profile default has been saved
Error saving credentials, failed to unlock correct collection '/org/freedesktop/secrets/aliases/default'
I'm interested to hear any suggestions people may have in resolving this. While using my local machine for development is working, I think there is a benefit to be able to create reproducible development environments for this work. So I will persist with this and if I discover anything further I will post it here too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:18 AM
Great initiative, did you manage to resolve this issue?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2022 11:25 AM
Did you get any further with this?
It would be great if we could get the SNC CLI to run. in a docker container so we don't have to maintain an ancient old node version just for this simple CLI.