Skip to content

Commit 5cb0fdc

Browse files
authored
Merge pull request #9 from The-Nefarious-Developer/typescript
Implement sap-cap-typescript-node
2 parents e8e9ee9 + 8ea015d commit 5cb0fdc

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Ths repository generates the following docker/devcontainer images using GHCR:
2222
| Image | Base Image | Variants |
2323
|---------------------------|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
2424
| sap-cap-javascript-node | [mcr.microsoft.com/devcontainers/javascript-node](https://hub.docker.com/r/microsoft/devcontainers-javascript-node) | [Versions Available](./src/sap-cap-javascript-node/variants.json) |
25+
| sap-cap-typescript-node | [mcr.microsoft.com/devcontainers/typescript-node](https://hub.docker.com/r/microsoft/devcontainers-typescript-node) | [Versions Available](./src/sap-cap-typescript-node/variants.json) |
2526

2627
## How it works
2728

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ARG VARIANT=22-bookworm
2+
FROM mcr.microsoft.com/devcontainers/typescript-node:${VARIANT}
3+
LABEL org.opencontainers.image.source="https://github.com/The-Nefarious-Developer/devcontainer-images"
4+
5+
ARG CF_PATH=/home/node/.cf
6+
7+
# Set execution user otherwise the CF CLI directory is going to be created by root
8+
# and auth or ownership would need to be granted with "sudo chown -R node $CF_PATH"
9+
USER node
10+
11+
# Place dependencies in non-root user directory, as per documentation:
12+
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
13+
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
14+
ENV PATH=$PATH:/home/node/.npm-global/bin
15+
16+
# This is needed as the common CF CLI installation procedure is not configuring
17+
# the correct path for plugins. More info at https://cli.cloudfoundry.org/en-US/v8/
18+
ENV CF_PLUGIN_HOME=${CF_PATH}/plugins
19+
20+
RUN \
21+
# Avoid getting stuck with interactive prompts
22+
export DEBIAN_FRONTEND=noninteractive \
23+
# Install Cloud Foundry CLI
24+
&& wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - \
25+
&& echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list \
26+
# Cache busting for CF CLI installation
27+
&& sudo apt-get update \
28+
&& sudo apt-get install cf8-cli \
29+
# Install Cloud Foundry Plugins
30+
&& cf install-plugin multiapps -f \
31+
&& cf install-plugin html5-plugin -f \
32+
# Install SAPUI5 CLI
33+
&& npm install --global @ui5/cli \
34+
# Install CAP Tooling
35+
&& npm install --global @sap/cds-dk \
36+
# Install the Cloud MTA Build Tool (MBT)
37+
&& npm install --global mbt \
38+
# Install Yeoman
39+
&& npm install --global yo \
40+
# Install TypeScript
41+
&& npm install --global typescript \
42+
&& npm install --global ts-node \
43+
# Install Typescript CDS lib to avoid constantly precompiling files during dev
44+
&& npm install --global tsx
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "CAP",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
// The variant arg will be replaced by the versions in the variants.json file during the build process
7+
"VARIANT": "__VARIANT__"
8+
}
9+
},
10+
// Configure tool-specific properties
11+
"customizations": {
12+
// Configure properties specific to VS Code
13+
"vscode": {
14+
// Add the IDs of extensions you want installed when the container is created
15+
"extensions": [
16+
"SAPSE.vscode-cds",
17+
"SAPSE.sap-ux-fiori-tools-extension-pack",
18+
"Orta.vscode-jest"
19+
]
20+
}
21+
},
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally
23+
// "forwardPorts": [],
24+
25+
// Use 'postCreateCommand' to run commands after the container is created
26+
// "postCreateCommand": "npm install",
27+
28+
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root
29+
"remoteUser": "node"
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"variants": [
3+
"22-bookworm",
4+
"22-bullseye",
5+
"20-bookworm",
6+
"20-bullseye",
7+
"18-bookworm",
8+
"18-bullseye"
9+
]
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# shellcheck disable=SC1091
4+
source "$(dirname "$0")/../test-utils/harness.sh"
5+
6+
# setup "sap-cap-typescript-node" "22-bookworm"
7+
setup "sap-cap-typescript-node" "$VARIANT"
8+
9+
run_test "Node version is correct" "node -v" "${IMAGE_TAG:0:2}"
10+
run_test "NPM is present" "npm --help" "npm <command>"
11+
run_test "CloudFoundry CLI is present" "cf --version" "cf version 8"
12+
run_test "CAP Development Toolkit is present" "cds version" "@cap-js/asyncapi"
13+
run_test "Typescript is present" "tsc -v" "Version"
14+
run_test "ts-node is present is present" "ts-node -v" "v"
15+
run_test "CAP Typescript Plugin is present" "cds-tsx" ""
16+
run_test "Container defaults to non-root user" "whoami" "node"
17+
run_test "Non-root user is able to sudo" "sudo whoami" "root"

0 commit comments

Comments
 (0)