Skip to content

Commit 2cbac0d

Browse files
authored
Sandboxing PDL interpreter in docker container, clis pdl and pdl-local (#79)
* dockerfile, pdl/pdl-local clis Signed-off-by: Mandana Vaziri <[email protected]> * cleanup Signed-off-by: Mandana Vaziri <[email protected]> --------- Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 231f634 commit 2cbac0d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /pdl
6+
7+
# Copy the current directory contents into the container at /app
8+
COPY . /pdl
9+
10+
# Install any needed dependencies specified in requirements.txt
11+
RUN pip install .
12+
RUN pip install '.[all]'
13+
14+
15+
# Run app.py when the container launches
16+
ENTRYPOINT ["pdl-local"]

pdl/pdl_runner.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
WATSONX_APIKEY = "WATSONX_APIKEY=" + os.environ["WATSONX_APIKEY"]
6+
WATSONX_URL = "WATSONX_URL=" + os.environ["WATSONX_URL"]
7+
WATSONX_PROJECT_ID = "WATSONX_PROJECT_ID=" + os.environ["WATSONX_PROJECT_ID"]
8+
LOCAL_DIR = os.getcwd() + ":/local"
9+
10+
11+
def main():
12+
subprocess.run(
13+
[
14+
"docker",
15+
"run",
16+
"-v",
17+
LOCAL_DIR,
18+
"-w",
19+
"/local",
20+
"-e",
21+
WATSONX_APIKEY,
22+
"-e",
23+
WATSONX_URL,
24+
"-e",
25+
WATSONX_PROJECT_ID,
26+
"--rm",
27+
"-it",
28+
"pdl-runner",
29+
*sys.argv[1:],
30+
],
31+
check=True,
32+
)
33+
34+
35+
if __name__ == "__main__":
36+
main()

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ Repository = "https://github.com/IBM/prompt-declaration-language"
6060
Issues = "https://github.com/IBM/prompt-declaration-language/issues"
6161

6262
[project.scripts]
63-
pdl = "pdl.pdl:main"
63+
pdl-local = "pdl.pdl:main"
64+
pdl = "pdl.pdl_runner:main"

0 commit comments

Comments
 (0)