-
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.
* use interpolation to add args to the image commands
- Loading branch information
1 parent
76acc60
commit 31f7897
Showing
28 changed files
with
677 additions
and
74 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
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,41 @@ | ||
(ns init | ||
(:require | ||
[babashka.process] | ||
[cheshire.core])) | ||
|
||
(defn output [args] | ||
(try | ||
(-> | ||
(apply babashka.process/process | ||
{:out :string} | ||
args) | ||
(deref) | ||
(babashka.process/check)) | ||
(catch Throwable _ nil))) | ||
|
||
(defn man [t] | ||
(output ["man" t])) | ||
(defn help [t] | ||
(output [t "--help"])) | ||
(defn h [t] | ||
(output [t "-h"])) | ||
|
||
(try | ||
(let [[json-string & extra-args] *command-line-args* | ||
{:keys [args]} (cheshire.core/parse-string json-string true)] | ||
(println | ||
(-> (if (= "man" (first extra-args)) | ||
(let [t "codescope"] (or (man t) (help t) (h t))) | ||
(-> (babashka.process/process | ||
{:out :string} | ||
(format "codescope %s /project" args)) | ||
(deref) | ||
(babashka.process/check))) | ||
(deref) | ||
(babashka.process/check) | ||
:out))) | ||
(catch Throwable t | ||
(binding [*out* *err*] | ||
(println (str "Error: " (.getMessage t))) | ||
(System/exit 1)))) | ||
|
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,29 @@ | ||
# syntax = docker/dockerfile:1.4 | ||
FROM nixos/nix:latest@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder | ||
|
||
WORKDIR /tmp/build | ||
RUN mkdir /tmp/nix-store-closure | ||
|
||
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here | ||
# hadolint ignore=SC2046 | ||
RUN --mount=type=cache,target=/nix,from=nixos/nix:latest@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9,source=/nix \ | ||
--mount=type=cache,target=/root/.cache \ | ||
--mount=type=bind,target=/tmp/build \ | ||
<<EOF | ||
nix \ | ||
--extra-experimental-features "nix-command flakes" \ | ||
--option filter-syscalls false \ | ||
--show-trace \ | ||
--log-format raw \ | ||
build . --out-link /tmp/output/result | ||
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure | ||
EOF | ||
|
||
FROM scratch | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /tmp/nix-store-closure /nix/store | ||
COPY --from=builder /tmp/output/ /app/ | ||
|
||
ENTRYPOINT ["/app/result/bin/entrypoint"] |
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,32 @@ | ||
|
||
|
||
## ROLE assistant | ||
In Node.js, you can access command line arguments via the process.argv array. This will contain the complete command-line. | ||
|
||
Here is a simple program that reads a JavaScript string from the first command line argument and then evaluates it. | ||
|
||
```javascript | ||
// current file name will occupy the 0th index, followed by file name (or execution command e.g "node") on 1st index and user supplied argument from 2nd index onwards | ||
const args = process.argv.slice(2); | ||
|
||
if(args.length == 0) { | ||
console.log("Please provide javascript command as argument."); | ||
process.exit(); | ||
} | ||
|
||
try { | ||
let result = eval(args[0]); | ||
console.log(result); | ||
} catch(e) { | ||
console.error("Error in executing provided javascript command:", e.message); | ||
} | ||
``` | ||
|
||
To use this script, you need to write the JavaScript string as a command line argument. | ||
|
||
```shell | ||
node evalScript.js "console.log('Hello, world!')" | ||
``` | ||
|
||
Note: Using eval() function can be dangerous because it executes the code it's given with the privileges of the caller. Even, it can be harmful when used with user-provided input, leading to potential code injection vulnerabilities. Be cautious while using eval(). | ||
{"done":"stop"} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
{ | ||
description = "javascript runner"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
devshell = { | ||
url = "github:numtide/devshell"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils, devshell }: | ||
|
||
flake-utils.lib.eachDefaultSystem | ||
(system: | ||
let | ||
overlays = [ | ||
devshell.overlays.default | ||
]; | ||
pkgs = import nixpkgs { | ||
inherit system overlays; | ||
}; | ||
|
||
in | ||
rec { | ||
|
||
packages = rec { | ||
|
||
# this derivation just contains the init.clj script | ||
scripts = pkgs.stdenv.mkDerivation { | ||
name = "scripts"; | ||
src = ./.; | ||
installPhase = '' | ||
cp main.js $out | ||
''; | ||
}; | ||
|
||
default = pkgs.writeShellScriptBin "entrypoint" '' | ||
${pkgs.nodejs}/bin/node ${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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
if(process.argv.length > 2) { | ||
// get the first command line argument | ||
var cmdArgument = process.argv[2]; | ||
|
||
// evaluate JS string | ||
try { | ||
var result = eval(cmdArgument); | ||
} catch(e) { | ||
console.error('Error: ' + e.message); | ||
} | ||
} else { | ||
console.error('No JavaScript string provided to evaluate!'); | ||
} | ||
|
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,31 @@ | ||
# prompt user | ||
|
||
Write a javascript program that reads a javascript string from the first command line argument and then evaluates it. | ||
|
||
# build | ||
|
||
```sh | ||
docker build -t vonwig/javascript-runner:latest . | ||
``` | ||
|
||
```sh | ||
docker push vonwig/javascript-runner:latest | ||
``` | ||
|
||
# run | ||
|
||
```sh | ||
docker run --rm -v thread:/thread vonwig/javascript-runner:latest "console.log('gorsh');" | ||
``` | ||
|
||
# multi-platform build | ||
|
||
```sh | ||
docker buildx build \ | ||
--builder hydrobuild \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--tag vonwig/javascript-runner:latest \ | ||
--file Dockerfile \ | ||
--push . | ||
``` | ||
|
File renamed without changes.
File renamed without changes.
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,8 @@ | ||
|
||
```sh | ||
docker build . -t vonwig/node_intersector | ||
``` | ||
|
||
```sh | ||
docker run --mount type=bind,source=$PWD,target=/project --workdir /project vonwig/node_intersector '{"path": "test_file.py", "line": 32}' | ||
``` |
File renamed without changes.
Oops, something went wrong.