Development Containers (CAP)
This article describes approaches for developing of SAP Cloud Application Programming Model (CAP) by utilizing development containers.
There are two major container an
Docker Desktop
This following approach is based on:
- https://containers.dev/
- https://qmacro.org/blog/posts/2024/01/15/developing-cap-in-containers-three-ways/
It requires a local installation of Docker Desktop.
Configuration of Development Repository
Create a subfolder .devcontainer with the following files
.devcontainer |-- Dockerfile `-- devcontainer.json
Contents of Dockerfile:
# syntax=docker/dockerfile:1
ARG VARIANT="20"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
# Install some generally useful tools
RUN apt-get update && apt-get -y install --no-install-recommends curl git sqlite3
# Install SAP CAP SDK globally
USER node
RUN npm install -g @sap/cds-dk
WORKDIR /home/node
Contents of devcontainer.json
{
"name": "Portfolio Manager",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "20" }
},
"customizations": {
"vscode": {
"extensions": [
"sapse.vscode-cds",
"dbaeumer.vscode-eslint",
"humao.rest-client",
"qwtel.sqlite-viewer",
"mechatroner.rainbow-csv"
]
}
},
"forwardPorts": [ 4004 ],
"remoteUser": "node"
}
VSCode Extensions
Install VSCode Extension "Dev Containers".
When opening a repository directory in VSCode, a bubble message should appear providing the options to reopen the directory within the docker container or even to clone it in the docker container.
The local VSCode installation then only acts as a client and a server part will be deployed and runs on the docker, to which the VSCode connects as a client.
WSL2 / Windows Subsystem for Linux
For installation and management of WSL see Windows Subsystem For Linux (WSL)
Developing on WSL with Node.js
The following approach for utilizing WSL as a container environment for developing node.js is based on the following article: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
Install curl:
sudo apt-get install curl
Install nvm, with:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Verify installation, enter:
command -v nvm
The response should be "nvm". If there is no response or an error, then restart the WSL.
Install Node LTS:
nvm install --lts
List installed Node versions:
nvm ls
Check installed versions:
node --version npm --version
You can also use the which commant to see the path used for the default versions:
which node which npm
VSCode Extensions
Install VSCode Extension "Remote Development Extension Pack", which contains the following extensions:
- Dev Containers
- Remote - SSH
- WSL
- Remote - Tunnels
The local VSCode installation then only acts as a client and a server part will be deployed and runs on the docker, to which the VSCode connects as a client.