-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from docker/cm/eslint-testing
NPM testing
- Loading branch information
Showing
15 changed files
with
288 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Build and Push NPM Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.TEMP_DOCKER_USERNAME }} | ||
password: ${{ secrets.TEMP_DOCKER_PAT }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: prompts/npm | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: vonwig/extractor-node:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,41 @@ | ||
You are an assistant who specializes in making runbooks for NPM projects, | ||
allowing any developer to quickly run a docker project locally for development. | ||
You are an assistant who specializes in making runbooks for NPM projects, allowing any developer to quickly run a docker project locally for development. | ||
|
||
Since you are an expert and know about their project, be definitive about recommendations. | ||
|
||
A runbook for an npm project contains the following steps: | ||
A runbook for an npm project contains the following: | ||
|
||
# Setup: | ||
|
||
NVM: | ||
Check for NVM or install it with the system's package manager. | ||
Example: | ||
```sh | ||
brew install nvm | ||
``` | ||
|
||
Node and NPM: | ||
Prepare node using nvm, and select the correct package manager | ||
|
||
Run Package Manager: | ||
Depending on npm vs yarn, run an install | ||
|
||
# Run: | ||
Analyze package.json for scripts. | ||
Then, for each node root, you need to do the following: | ||
|
||
# Node Root | ||
|
||
{{#project.node_roots}} | ||
The project has a node root package.json at {{path}} with the contents {{content}}. | ||
Because there is already a root, the project does not need to be converted to npm. | ||
{{/project.node_roots}} | ||
{{^project.node_roots}} | ||
The project does not have a node root, so the user should run `npm init` | ||
{{/project.node_roots}} | ||
Add a block to cd into the node root | ||
|
||
```sh | ||
cd $node_root | ||
``` | ||
|
||
Node and NPM: | ||
Prepare node using nvm, and select the correct package manager. | ||
Example: | ||
```sh | ||
nvm use 20 | ||
``` | ||
|
||
{{#project.version_artifacts}} | ||
The project has a version declaration file {{path}} with the contents {{content}} | ||
{{/project.version_artifacts}} | ||
{{^project.version_artifacts}} | ||
The project does not have any version artifacts, so default to latest node LTS | ||
{{/project.version_artifacts}} | ||
|
||
The user has the following top level project files: | ||
|
||
{{#project.files}} | ||
{{.}} | ||
{{/project.files}} | ||
|
||
If there is a yarn.lock, use `yarn` in place of npm commands. | ||
Run Package Manager: | ||
Depending on npm vs yarn, run an install | ||
Example | ||
```sh | ||
yarn install | ||
``` | ||
|
||
Run `npm install` | ||
Run scripts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
I would like to run this node project. | ||
I have the following project open: | ||
|
||
--- Project --- | ||
|
||
My project has these files: | ||
{{#project.files}} | ||
{{.}} | ||
{{/project.files}} | ||
|
||
If you see that I have a yarn.lock, please use `yarn` in place of npm commands. | ||
|
||
{{#project.node_roots}} | ||
--- Node Root --- | ||
My project has a node root package.json at {{path}} and uses node version {{version}}. | ||
The node root has the following scripts | ||
{{scripts}} | ||
----------------- | ||
{{/project.node_roots}} | ||
{{^project.node_roots}} | ||
The project does not have a node root, so help me run `npm init` | ||
{{/project.node_roots}} | ||
|
||
Please generate a runbook for me. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
FROM ubuntu:20.04 | ||
FROM alpine:3.20 | ||
|
||
WORKDIR /app | ||
# Get bash, jq, fdfind | ||
RUN apk add --no-cache bash jq fd | ||
|
||
RUN <<EOF | ||
cat > /app/run.sh <<'EOF2' | ||
#!/bin/bash | ||
VOLUME /project | ||
|
||
echo '{"project": {"node_roots": [{"path": "package.json", "content": "some stuff"}]}}' | ||
EOF2 | ||
chmod 755 /app/run.sh | ||
EOF | ||
WORKDIR / | ||
|
||
COPY ./scripts/build-node-roots.sh /build-node-roots.sh | ||
|
||
# MAke the thing executable | ||
RUN chmod +x build-node-roots.sh | ||
|
||
COPY ./scripts/payload.json /payload.json | ||
# when the container is running the project is mounted at /project read-only | ||
ENTRYPOINT ["/app/run.sh"] | ||
ENTRYPOINT ["/build-node-roots.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
function get_node_version() { | ||
local DEFAULT_NODE_VERSION=20 | ||
local NODE_VERSION=DEFAULT_NODE_VERSION | ||
local NODE_VERSION_FILE=null | ||
local NODE_VERSION_FILE_PATH=null | ||
local NODE_VERSION_FILE_NAME=null | ||
|
||
if [ -f ".node-version" ]; then | ||
NODE_VERSION_FILE=".node-version" | ||
elif [ -f ".nvmrc" ]; then | ||
NODE_VERSION_FILE=".nvmrc" | ||
elif [ -f "package.json" ]; then | ||
NODE_VERSION_FILE="package.json" | ||
fi | ||
|
||
if [ $NODE_VERSION_FILE == "package.json" ]; then | ||
NODE_VERSION=$(jq -r '.engines.node' "$NODE_VERSION_FILE") | ||
else | ||
NODE_VERSION=$(cat $NODE_VERSION_FILE) | ||
fi | ||
|
||
NODE_VERSION_FILE_PATH=$(pwd) | ||
NODE_VERSION_FILE_NAME=$NODE_VERSION_FILE | ||
|
||
if [ $NODE_VERSION == null ]; then | ||
NODE_VERSION=DEFAULT_NODE_VERSION | ||
NODE_VERSION_FILE=null | ||
NODE_VERSION_FILE_PATH=null | ||
fi | ||
|
||
# Strip non-numeric and non-dot characters | ||
NODE_VERSION=$(echo $NODE_VERSION | tr -dc '0-9.') | ||
|
||
# Echo json payload | ||
echo "{\"node_version\": \"$NODE_VERSION\", \"node_version_file\": \"$NODE_VERSION_FILE_NAME\", \"node_version_file_path\": \"$NODE_VERSION_FILE_PATH\"}" | ||
} | ||
|
||
|
||
PROJECT_DIR="/project" | ||
|
||
cd $PROJECT_DIR | ||
|
||
# If package.json at root level | ||
if [ -f package.json ]; then | ||
NODE_ROOTS="$PROJECT_DIR/package.json" | ||
else | ||
#TODO if a package.json found contains workspaces, ignore those roots | ||
NODE_ROOTS=$(fd -d 3 package.json) # newline separated | ||
fi | ||
|
||
PAYLOAD_NODE_ROOTS=() | ||
|
||
# CD into each node root | ||
for NODE_ROOT in $NODE_ROOTS; do | ||
root_dirname=$(dirname $NODE_ROOT) | ||
root_dirname="$PROJECT_DIR/$root_dirname" | ||
cd $root_dirname | ||
# Version is json payload | ||
node_root_version=$(get_node_version | tr -d '\n' | tr -d '\r') | ||
|
||
node_root_path=$root_dirname | ||
|
||
node_root_scripts=$(jq -r '.scripts' package.json) | ||
# Append json payload | ||
PAYLOAD_NODE_ROOTS+=("{\"node_root_path\": \"$node_root_path\", \"version\": $node_root_version, \"node_root_scripts\": $node_root_scripts},") | ||
done | ||
|
||
# Remove trailing comma from last element | ||
PAYLOAD_NODE_ROOTS[-1]=${PAYLOAD_NODE_ROOTS[-1]%?} | ||
|
||
# Echo project.node_roots json payload, comma separated | ||
echo "{\"project\": {\"node_roots\": [${PAYLOAD_NODE_ROOTS[@]}]}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"project": { | ||
"node_roots": [ | ||
{ | ||
"path": "client/package.json", | ||
"version": "18", | ||
"scripts": { | ||
"vscode:prepublish": "yarn run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"pretest": "yarn run compile && yarn run lint", | ||
"lint": "eslint src --ext ts", | ||
"test": "vscode-test", | ||
"package": "vsce package" | ||
} | ||
}, | ||
{ | ||
"path": "client/desktop-ui/package.json", | ||
"version": "18", | ||
"scripts": { | ||
"vscode:prepublish": "yarn run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"pretest": "yarn run compile && yarn run lint", | ||
"lint": "eslint src --ext ts", | ||
"test": "vscode-test", | ||
"package": "vsce package" | ||
} | ||
}, | ||
{ | ||
"path": "client/desktop/package.json", | ||
"version": "20", | ||
"scripts": { | ||
"vscode:prepublish": "yarn run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"pretest": "yarn run compile && yarn run lint", | ||
"lint": "eslint src --ext ts", | ||
"test": "vscode-test", | ||
"package": "vsce package" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM alpine:3.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
extractors: | ||
- image: vonwig/readme-extractor:latest | ||
entrypoint: /project | ||
- image: vonwig/extractor-node:latest | ||
--- | ||
|
||
## Description | ||
|
||
The prompts for docker rely only on the classic lsp project extraction function. | ||
|
||
The output of running this container is a json document that will be merged into the | ||
context that is provided to the moustache template based prompts. | ||
|
||
It relies on an image to extract some additional facts about the project | ||
|
||
## Building the extraction image | ||
|
||
```sh | ||
#docker:command=build-npm-extractor | ||
docker build -t vonwig/extractor-node -f ./npm/Dockerfile ./npm | ||
``` | ||
|
||
## Running the extraction image | ||
|
||
```sh | ||
#docker:command=run-npm-extractor | ||
docker run --rm -v $PWD:/project:ro vonwig/extractor-node | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.