Skip to content

Commit e3b31b5

Browse files
fix working local
update Dockerfiles update automation also for podman usage update initial user / apikey add logging to application add new folder for example uploadfile
1 parent 9baad9f commit e3b31b5

File tree

10 files changed

+130
-67
lines changed

10 files changed

+130
-67
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ configmap_values.txt
168168

169169
# additional
170170
simple-pipeline-env-3.11
171+
simple-pipeline-env-3
171172
.env
172173
.DS_Store
173174
documentation/~$live-stream.pptx
174175
.vscode/launch.json
175176
additional_notes.md
176177
assistant/additional_information/
178+
code/.env_backup

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ git clone https://github.com/thomassuedbroecker/simple-pipeline.git
3131

3232
```sh
3333
cd simple-pipeline/code
34-
python3.11 -m venv simple-pipeline-env-3.11
35-
source ./simple-pipeline-env-3.11/bin/activate
34+
python3 -m venv simple-pipeline-env-3
35+
source ./simple-pipeline-env-3/bin/activate
3636
```
3737

3838
* Install needed Python libs and create a `requirements.txt` file
@@ -42,19 +42,24 @@ python3 -m pip install --upgrade pip
4242
python3 -m pip install "fastapi[all]"
4343
python3 -m pip install requests
4444
python3 -m pip install pydantic
45-
python3 -m pip install touch
46-
#python3 -m pip install pytorch #Only with GPU
47-
python3 -m pip install torch torchvision
45+
python3 -m pip install torch
4846
python3 -m pip install accelerate
49-
python3 -m pip install auto-gptq
5047
python3 -m pip install typing
5148
python3 -m pip install transformers
52-
python3 -m pip install git+https://github.com/huggingface/transformers
53-
python3 -m pip freeze > requirements.txt
49+
#python3 -m pip install git+https://github.com/huggingface/transformers
5450
```
5551

52+
* Save your configuration in requirements.txt
53+
5654
```sh
5755
python3 -m pip install --upgrade pip
56+
python3 -m pip freeze > requirements.txt
57+
deactivate
58+
```
59+
60+
* Install from configuration from requirements.txt
61+
62+
```sh
5863
python3 -m pip install -r requirements.txt
5964
```
6065

@@ -94,14 +99,15 @@ export IBMCLOUD_APIKEY=
9499
# APP
95100
export APP_USER=admin
96101
export APP_APIKEY=admin
102+
export APPLOG=INFO
97103
```
98104

99105
### 3.3 Run `simple-qa-pipeline` server
100106

101107
```sh
102108
cd code
103-
source ./simple-pipeline-env-3.11/bin/activate
104-
source .env
109+
source ./simple-pipeline-env-3/bin/activate
110+
source ./.env
105111
python3 simple-qa-pipeline.py
106112
```
107113

code/.env-template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export CUSTOM_MODEL_PROMPT="Code:\n\n<<CONTEXT>>\n\nQuestion:\n\n<<QUESTION>>\n\
2222
export IBMCLOUD_APIKEY=
2323
export IBMCLOUD_URL=https://iam.cloud.ibm.com/identity/token
2424
# APP
25-
export APP_USER=admin
26-
export APP_APIKEY=admin
25+
export APP_USER=adm
26+
export APP_APIKEY=admin123
27+
export APPLOG=INFO

code/docker/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ FROM python:3.11.2-slim-buster
22

33
# Install needed environment
44
RUN apt-get -y update; apt-get -y install curl
5-
RUN python -m pip install --upgrade pip
6-
RUN python -m pip install "fastapi[all]"
7-
RUN python -m pip install requests
8-
RUN python -m pip install pydantic
5+
RUN python3 -m pip install --upgrade pip
6+
RUN python3 -m pip install "fastapi[all]"
7+
RUN python3 -m pip install requests
8+
RUN python3 -m pip install pydantic
9+
RUN python3 -m pip install torch
10+
RUN python3 -m pip install accelerate
11+
RUN python3 -m pip install transformers
912
#RUN python -m pip freeze > requirements.txt
1013

1114
RUN addgroup simple_qa_pipeline_group

code/docker/Dockerfile.optimized

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ FROM python:3.11.2-slim-buster as BUILDER_IMAGE
66
WORKDIR /app
77

88
# Install needed environment
9-
RUN python -m pip install --upgrade pip
10-
RUN python -m pip install requests
11-
RUN python -m pip install "fastapi[all]"
12-
RUN python -m pip install pydantic
13-
9+
RUN apt-get -y update; apt-get -y install curl
10+
RUN python3 -m pip install --upgrade pip
11+
RUN python3 -m pip install "fastapi[all]"
12+
RUN python3 -m pip install requests
13+
RUN python3 -m pip install pydantic
14+
RUN python3 -m pip install torch
15+
RUN python3 -m pip install accelerate
16+
RUN python3 -m pip install transformers
1417

1518
# Create modeles folder
1619
RUN mkdir modules

code/modules/load_env.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
import os
2+
import logging
3+
import sys
4+
5+
##################################
6+
# Configure Logging
7+
# load config
8+
if (os.environ.get("APP_LOG") == None):
9+
APPLOG = "INFO"
10+
else:
11+
APPLOG = os.environ.get("APP_LOG")
12+
13+
# set logging
14+
if (str(APPLOG)=="DEBUG"):
15+
logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)
16+
elif (str(APPLOG)=="INFO"):
17+
logging.basicConfig(stream=sys.stdout,level=logging.INFO)
18+
elif (str(APPLOG)=="WARNING"):
19+
logging.basicConfig(stream=sys.stdout,level=logging.WARNING)
20+
else:
21+
logging.basicConfig(stream=sys.stdout,level=logging.INFO)
222

323
def load_ibmcloud_env():
424
if (os.environ.get("IBMCLOUD_APIKEY") == None):
@@ -181,6 +201,11 @@ def load_apikey_env():
181201
APIKEY = "apikey"
182202
else:
183203
APIKEY = os.environ.get("APP_APIKEY")
204+
205+
if (os.environ.get("APPLOG") == None):
206+
APPLOG = "INFO"
207+
else:
208+
APPLOG = os.environ.get("APPLOG")
184209

185210
if ((USER=="admin") or
186211
(APIKEY=="apikey")):
@@ -189,7 +214,8 @@ def load_apikey_env():
189214
authenicationStatus = True
190215

191216
authenicationJSON = { "USER": USER,
192-
"APIKEY":APIKEY
217+
"APIKEY":APIKEY,
218+
"APPLOG":APPLOG
193219
}
194220
print(authenicationJSON)
195221

code/requirements.txt

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
1-
annotated-types==0.5.0
2-
anyio==3.7.1
3-
certifi==2023.5.7
4-
charset-normalizer==3.2.0
5-
click==8.1.6
6-
dnspython==2.4.0
7-
email-validator==2.0.0.post2
8-
fastapi==0.100.0
1+
accelerate==0.27.2
2+
annotated-types==0.6.0
3+
anyio==4.3.0
4+
certifi==2024.2.2
5+
charset-normalizer==3.3.2
6+
click==8.1.7
7+
dnspython==2.6.1
8+
email-validator==2.1.0.post1
9+
fastapi==0.109.2
910
filelock==3.13.1
10-
fsspec==2023.12.2
11+
fsspec==2024.2.0
1112
h11==0.14.0
12-
httpcore==0.17.3
13-
httptools==0.6.0
14-
httpx==0.24.1
13+
httpcore==1.0.3
14+
httptools==0.6.1
15+
httpx==0.26.0
1516
huggingface-hub==0.20.3
16-
idna==3.4
17+
idna==3.6
1718
itsdangerous==2.1.2
18-
Jinja2==3.1.2
19-
MarkupSafe==2.1.3
20-
numpy==1.26.3
21-
orjson==3.9.2
19+
Jinja2==3.1.3
20+
MarkupSafe==2.1.5
21+
mpmath==1.3.0
22+
networkx==3.2.1
23+
numpy==1.26.4
24+
orjson==3.9.14
2225
packaging==23.2
23-
pydantic==2.0.3
24-
pydantic-extra-types==2.0.0
25-
pydantic-settings==2.0.2
26-
pydantic_core==2.3.0
27-
python-dotenv==1.0.0
28-
python-multipart==0.0.6
26+
psutil==5.9.8
27+
pydantic==2.6.1
28+
pydantic-extra-types==2.5.0
29+
pydantic-settings==2.2.1
30+
pydantic_core==2.16.2
31+
python-dotenv==1.0.1
32+
python-multipart==0.0.9
2933
PyYAML==6.0.1
3034
regex==2023.12.25
3135
requests==2.31.0
32-
safetensors==0.4.1
36+
safetensors==0.4.2
3337
sniffio==1.3.0
34-
starlette==0.27.0
35-
tokenizers==0.15.0
36-
touch==2020.12.3
37-
tqdm==4.66.1
38-
transformers==4.37.0
38+
starlette==0.36.3
39+
sympy==1.12
40+
tokenizers==0.15.2
41+
torch==2.2.0
42+
tqdm==4.66.2
43+
transformers==4.37.2
3944
typing==3.7.4.3
40-
typing_extensions==4.7.1
41-
ujson==5.8.0
42-
urllib3==2.0.4
43-
uvicorn==0.23.1
44-
uvloop==0.17.0
45-
values==2020.12.3
46-
watchfiles==0.19.0
47-
websockets==11.0.3
45+
typing_extensions==4.9.0
46+
ujson==5.9.0
47+
urllib3==2.2.1
48+
uvicorn==0.27.1
49+
uvloop==0.19.0
50+
watchfiles==0.21.0
51+
websockets==12.0

code/simple-qa-pipeline.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from fastapi.security import HTTPBasic, HTTPBasicCredentials
44
from starlette.status import HTTP_401_UNAUTHORIZED
55
from fastapi.openapi.utils import get_openapi
6+
import logging
7+
import sys
8+
69
##################################
710
# Custom modules
811
from modules.load_env import load_watson_discovery_env, load_apikey_env, load_watson_x_env
@@ -14,6 +17,18 @@
1417
from modules.requests_watsonx_deployments import get_answer_from_watsonx_deployment
1518
from modules.requests_local_custom_model import custom_model_simple_prompt
1619

20+
##################################
21+
# Configure Logging
22+
log_config, log_validation = load_apikey_env()
23+
if (str(log_config["APPLOG"])=="DEBUG"):
24+
logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)
25+
elif (str(log_config["APPLOG"])=="INFO"):
26+
logging.basicConfig(stream=sys.stdout,level=logging.INFO)
27+
elif (str(log_config["APPLOG"])=="WARNING"):
28+
logging.basicConfig(stream=sys.stdout,level=logging.WARNING)
29+
else:
30+
logging.basicConfig(stream=sys.stdout,level=logging.INFO)
31+
1732
##################################
1833
# Set basic auth as security
1934
security = HTTPBasic()

scripts/ce-deployment/deploy-to-code-engine.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export REUSE_REPO_URL=${3:-"no_repo_url_id"}
1515
export REUSE_REPO_ENV_NAME=${4:-"no_env_file_name"}
1616
export REUSE="false"
1717

18+
#export ENGINE=docker
19+
export ENGINE=podman
20+
1821
# Optional to change
1922
export CODEENGINE_CR_ACCESS_NAME=$CR
2023
export CODEENGINE_CR_SERVER_NAME=$CR
@@ -36,11 +39,11 @@ export FOLDERNAME=""
3639
# **********************************************************************************
3740

3841
function check_docker () {
39-
ERROR=$(docker ps 2>&1)
42+
ERROR=$(${ENGINE} ps 2>&1)
4043
RESULT=$(echo $ERROR | grep 'Cannot' | awk '{print $1;}')
4144
VERIFY="Cannot"
4245
if [ "$RESULT" == "$VERIFY" ]; then
43-
echo "Docker is not running. Stop script execution."
46+
echo "${ENGINE} is not running. Stop script execution."
4447
exit 1
4548
fi
4649
}
@@ -96,7 +99,7 @@ function build_and_push_container () {
9699
# 3. Build container image
97100
echo "****** BUILD *********"
98101
cd "$HOME_PATH"/../../code
99-
docker build -f "$HOME_PATH"/../../code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" .
102+
${ENGINE} build -f "$HOME_PATH"/../../code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" .
100103
cd "$HOME_PATH"
101104

102105
# 4. Login to IBM Cloud Container Registry
@@ -122,8 +125,8 @@ function build_and_push_container () {
122125
# 8. Create new container image if it doesn't exists
123126
CURR_CONTAINER_IMAGE=$(ibmcloud cr image-list | grep $CI_TAG | awk '{print $2;}')
124127
if [ "$CI_TAG" != "$CURR_CONTAINER_IMAGE" ]; then
125-
docker login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION
126-
docker push "$CODEENGINE_APP_IMAGE_URL"
128+
${ENGINE} login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION
129+
${ENGINE} push "$CODEENGINE_APP_IMAGE_URL"
127130
else
128131
echo "Container exists: ($CODEENGINE_APP_IMAGE_URL)"
129132
fi
@@ -334,7 +337,7 @@ function build_and_push_container_reuse () {
334337

335338
# Build from restore code
336339
cd "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code
337-
docker build -f "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" .
340+
${ENGINE} build -f "$TEMP_REUSE_FOLDER"/simple-qa-pipeline/code/docker/"$QA_DOCKERFILE_NAME" -t "$CODEENGINE_APP_IMAGE_URL" .
338341

339342
cd "$HOME_PATH"
340343

@@ -360,8 +363,8 @@ function build_and_push_container_reuse () {
360363
# Create new container image if it doesn't exists
361364
CURR_CONTAINER_IMAGE=$(ibmcloud cr image-list | grep $CI_TAG | awk '{print $2;}')
362365
if [ "$CI_TAG" != "$CURR_CONTAINER_IMAGE" ]; then
363-
docker login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION
364-
docker push "$CODEENGINE_APP_IMAGE_URL"
366+
${ENGINE} login -u iamapikey -p $IBM_CLOUD_API_KEY $CR_REGION
367+
${ENGINE} push "$CODEENGINE_APP_IMAGE_URL"
365368
else
366369
echo "Container exists: ($CODEENGINE_APP_IMAGE_URL)"
367370
fi
File renamed without changes.

0 commit comments

Comments
 (0)