Skip to content

Commit de35561

Browse files
committed
Fixes
1 parent 2eadfac commit de35561

File tree

9 files changed

+36
-292
lines changed

9 files changed

+36
-292
lines changed
Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,12 @@
1-
# app/Dockerfile
2-
3-
# # Stage 1 - Install build dependencies
4-
5-
# A Dockerfile must start with a FROM instruction which sets the base image for the container.
6-
# The Python images come in many flavors, each designed for a specific use case.
7-
# The python:3.11-slim image is a good base image for most applications.
8-
# It is a minimal image built on top of Debian Linux and includes only the necessary packages to run Python.
9-
# The slim image is a good choice because it is small and contains only the packages needed to run Python.
10-
# For more information, see:
11-
# * https://hub.docker.com/_/python
12-
# * https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker
131
FROM python:3.11-slim AS builder
14-
15-
# The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
16-
# If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.
17-
# For more information, see: https://docs.docker.com/engine/reference/builder/#workdir
18-
WORKDIR /app
19-
20-
# Set environment variables.
21-
# The ENV instruction sets the environment variable <key> to the value <value>.
22-
# This value will be in the environment of all “descendant” Dockerfile commands and can be replaced inline in many as well.
23-
# For more information, see: https://docs.docker.com/engine/reference/builder/#env
24-
ENV PYTHONDONTWRITEBYTECODE 1
25-
ENV PYTHONUNBUFFERED 1
26-
27-
# Install git so that we can clone the app code from a remote repo using the RUN instruction.
28-
# The RUN comand has 2 forms:
29-
# * RUN <command> (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
30-
# * RUN ["executable", "param1", "param2"] (exec form)
31-
# The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
32-
# The resulting committed image will be used for the next step in the Dockerfile.
33-
# For more information, see: https://docs.docker.com/engine/reference/builder/#run
34-
RUN apt-get update && apt-get install -y \
35-
build-essential \
36-
curl \
37-
software-properties-common \
38-
git \
39-
&& rm -rf /var/lib/apt/lists/*
40-
41-
# Create a virtualenv to keep dependencies together
42-
RUN python -m venv /opt/venv
43-
ENV PATH="/opt/venv/bin:$PATH"
44-
45-
# Clone the requirements.txt which contains dependencies to WORKDIR
46-
# COPY has two forms:
47-
# * COPY <src> <dest> (this copies the files from the local machine to the container's own filesystem)
48-
# * COPY ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
49-
# For more information, see: https://docs.docker.com/engine/reference/builder/#copy
50-
COPY requirements.txt .
51-
52-
# Install the Python dependencies
53-
RUN pip install --no-cache-dir --no-deps -r requirements.txt
54-
55-
# Stage 2 - Copy only necessary files to the runner stage
56-
57-
# The FROM instruction initializes a new build stage for the application
58-
FROM python:3.11-slim
59-
60-
# Sets the working directory to /app
612
WORKDIR /app
623

63-
# Copy the virtual environment from the builder stage
64-
COPY --from=builder /opt/venv /opt/venv
4+
ENV PYTHONDONTWRITEBYTECODE=1
5+
ENV PYTHONUNBUFFERED=1
656

66-
# Set environment variables
67-
ENV PATH="/opt/venv/bin:$PATH"
7+
COPY requirements.txt ./
8+
RUN pip install --no-cache-dir -r requirements.txt
689

69-
# Clone the app.py containing the application code
70-
COPY app.py .
71-
72-
# Copy the images folder to WORKDIR
73-
# The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>.
74-
# For more information, see: https://docs.docker.com/engine/reference/builder/#add
75-
ADD images ./images
76-
77-
# The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
78-
# For more information, see: https://docs.docker.com/engine/reference/builder/#expose
10+
COPY . .
7911
EXPOSE 8501
80-
81-
# The HEALTHCHECK instruction has two forms:
82-
# * HEALTHCHECK [OPTIONS] CMD command (check container health by running a command inside the container)
83-
# * HEALTHCHECK NONE (disable any healthcheck inherited from the base image)
84-
# The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working.
85-
# This can detect cases such as a web server that is stuck in an infinite loop and unable to handle new connections,
86-
# even though the server process is still running. For more information, see: https://docs.docker.com/engine/reference/builder/#healthcheck
87-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
88-
89-
# The ENTRYPOINT instruction has two forms:
90-
# * ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
91-
# * ENTRYPOINT command param1 param2 (shell form)
92-
# The ENTRYPOINT instruction allows you to configure a container that will run as an executable.
93-
# For more information, see: https://docs.docker.com/engine/reference/builder/#entrypoint
9412
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]

scenarios/AksOpenAiTerraform/scripts/app/app.py

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,13 @@
1-
"""
2-
MIT License
3-
4-
Copyright (c) 2023 Paolo Salvatori
5-
6-
Permission is hereby granted, free of charge, to any person obtaining a copy
7-
of this software and associated documentation files (the "Software"), to deal
8-
in the Software without restriction, including without limitation the rights
9-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
copies of the Software, and to permit persons to whom the Software is
11-
furnished to do so, subject to the following conditions:
12-
13-
The above copyright notice and this permission notice shall be included in all
14-
copies or substantial portions of the Software.
15-
16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
SOFTWARE.
23-
"""
24-
25-
# This sample is based on the following article:
26-
#
271
# - https://levelup.gitconnected.com/its-time-to-create-a-private-chatgpt-for-yourself-today-6503649e7bb6
282
#
29-
# Use pip to install the following packages:
30-
#
31-
# - streamlit
32-
# - openai
33-
# - streamlit-chat
34-
# - azure.identity
35-
# - dotenv
36-
#
373
# Make sure to provide a value for the following environment variables:
384
#
39-
# - AZURE_OPENAI_BASE: the URL of your Azure OpenAI resource, for example https://eastus.api.cognitive.microsoft.com/
40-
# - AZURE_OPENAI_KEY: the key of your Azure OpenAI resource
41-
# - AZURE_OPENAI_DEPLOYMENT: the name of the ChatGPT deployment used by your Azure OpenAI resource
42-
# - AZURE_OPENAI_MODEL: the name of the ChatGPT model used by your Azure OpenAI resource, for example gpt-35-turbo
43-
# - TITLE: the title of the Streamlit app
44-
# - TEMPERATURE: the temperature used by the OpenAI API to generate the response
5+
# - AZURE_OPENAI_BASE (ex: https://eastus.api.cognitive.microsoft.com/)
6+
# - AZURE_OPENAI_KEY
7+
# - AZURE_OPENAI_DEPLOYMENT
8+
# - AZURE_OPENAI_MODEL
9+
# - TITLE
10+
# - TEMPERATURE
4511
# - SYSTEM: give the model instructions about how it should behave and any context it should reference when generating a response.
4612
# Used to describe the assistant's personality.
4713
#
@@ -64,7 +30,6 @@
6430
#
6531
# - streamlit run app.py
6632

67-
# Import packages
6833
import os
6934
import sys
7035
import time
Lines changed: 2 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,5 @@
1-
aiohttp==3.8.4
2-
aiosignal==1.3.1
3-
altair==4.2.2
4-
anyio==3.6.2
5-
async-timeout==4.0.2
6-
attrs==23.1.0
7-
autopep8==1.6.0
8-
azure-core==1.26.4
9-
azure-identity==1.13.0
10-
backoff==2.2.1
11-
blinker==1.6.2
12-
cachetools==5.3.0
13-
certifi==2021.10.8
14-
cffi==1.15.1
15-
charset-normalizer==2.0.7
16-
chromadb==0.3.22
17-
click==8.0.3
18-
clickhouse-connect==0.5.24
19-
cmake==3.26.3
20-
cryptography==40.0.2
21-
dataclasses-json==0.5.7
22-
debugpy==1.6.7
23-
decorator==5.1.1
24-
duckdb==0.7.1
25-
entrypoints==0.4
26-
et-xmlfile==1.1.0
27-
fastapi==0.95.1
28-
filelock==3.12.0
29-
Flask==2.0.2
30-
frozenlist==1.3.3
31-
fsspec==2023.5.0
32-
gitdb==4.0.10
33-
GitPython==3.1.31
34-
greenlet==2.0.2
35-
h11==0.14.0
36-
hnswlib==0.7.0
37-
httptools==0.5.0
38-
huggingface-hub==0.14.1
39-
idna==3.3
40-
importlib-metadata==6.6.0
41-
itsdangerous==2.0.1
42-
jc==1.23.1
43-
Jinja2==3.0.2
44-
joblib==1.2.0
45-
jsonschema==4.17.3
46-
langchain==0.0.169
47-
lit==16.0.3
48-
llama-index==0.6.8
49-
lz4==4.3.2
50-
markdown-it-py==2.2.0
51-
MarkupSafe==2.0.1
52-
marshmallow==3.19.0
53-
marshmallow-enum==1.5.1
54-
mdurl==0.1.2
55-
monotonic==1.6
56-
mpmath==1.3.0
57-
msal==1.22.0
58-
msal-extensions==1.0.0
59-
multidict==6.0.4
60-
mypy-extensions==1.0.0
61-
networkx==3.1
62-
nltk==3.8.1
63-
numexpr==2.8.4
64-
numpy==1.24.3
65-
nvidia-cublas-cu11==11.10.3.66
66-
nvidia-cuda-cupti-cu11==11.7.101
67-
nvidia-cuda-nvrtc-cu11==11.7.99
68-
nvidia-cuda-runtime-cu11==11.7.99
69-
nvidia-cudnn-cu11==8.5.0.96
70-
nvidia-cufft-cu11==10.9.0.58
71-
nvidia-curand-cu11==10.2.10.91
72-
nvidia-cusolver-cu11==11.4.0.1
73-
nvidia-cusparse-cu11==11.7.4.91
74-
nvidia-nccl-cu11==2.14.3
75-
nvidia-nvtx-cu11==11.7.91
76-
openai==0.27.7
77-
openapi-schema-pydantic==1.2.4
78-
openpyxl==3.0.9
79-
packaging==23.1
80-
pandas==2.0.1
81-
pandas-stubs==1.2.0.35
82-
Pillow==9.5.0
83-
pipdeptree==2.7.1
84-
portalocker==2.7.0
85-
posthog==3.0.1
86-
protobuf==3.20.3
87-
pyarrow==12.0.0
88-
pycodestyle==2.8.0
89-
pycparser==2.21
90-
pydantic==1.10.7
91-
pydeck==0.8.1b0
92-
Pygments==2.15.1
93-
PyJWT==2.7.0
94-
Pympler==1.0.1
95-
PyPDF2==3.0.1
96-
pyrsistent==0.19.3
97-
python-dateutil==2.8.2
981
python-dotenv==0.19.2
99-
pytz==2021.3
100-
PyYAML==6.0
101-
regex==2023.5.5
102-
requests==2.29.0
103-
rich==13.3.5
104-
ruamel.yaml==0.17.21
105-
ruamel.yaml.clib==0.2.7
106-
scikit-learn==1.2.2
107-
scipy==1.10.1
108-
sentence-transformers==2.2.2
109-
sentencepiece==0.1.99
110-
six==1.16.0
111-
smmap==5.0.0
112-
sniffio==1.3.0
113-
SQLAlchemy==2.0.13
114-
starlette==0.26.1
1152
streamlit==1.22.0
1163
streamlit-chat==0.0.2.2
117-
sympy==1.12
118-
tenacity==8.2.2
119-
threadpoolctl==3.1.0
120-
tiktoken==0.4.0
121-
tokenizers==0.13.3
122-
toml==0.10.2
123-
toolz==0.12.0
124-
torch==2.0.1
125-
torchvision==0.15.2
126-
tornado==6.3.2
127-
tqdm==4.62.3
128-
transformers==4.29.1
129-
triton==2.0.0
130-
typing-inspect==0.8.0
131-
typing_extensions==4.5.0
132-
tzdata==2023.3
133-
tzlocal==5.0.1
134-
urllib3==1.26.7
135-
uvicorn==0.22.0
136-
uvloop==0.17.0
137-
validators==0.20.0
138-
watchdog==3.0.0
139-
watchfiles==0.19.0
140-
websockets==11.0.3
141-
Werkzeug==2.0.2
142-
xmltodict==0.13.0
143-
yarl==1.9.2
144-
zipp==3.15.0
145-
zstandard==0.21.0
4+
azure-identity==1.13.0
5+
openai==0.27.7

scenarios/AksOpenAiTerraform/scripts/deploy.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
# Variables
1+
#!/bin/bash
2+
23
SUBSCRIPTION_ID=$(az account show --query id --output tsv)
34
TENANT_ID=$(az account show --query tenantId --output tsv)
45
RESOURCE_GROUP=$(terraform output resource_group_name)
56
LOCATION="westus3"
67

7-
# Build/Push App's Docker image
8-
ACR_NAME=$(terraform output resource_group_name)
8+
# Build Image
9+
ACR_NAME=$(terraform output acr_name)
910
az acr login --name $ACR_NAME
1011
ACR_URL=$(az acr show --name $ACR_NAME --query loginServer --output tsv)
11-
docker build -t $ACR_URL/$ACR_NAME.azurecr.io/magic8ball:v1 ./app --push
12+
docker build -t $ACR_URL/magic8ball:v1 ./app --push
1213

13-
# Get AKS credentials
1414
az aks get-credentials \
1515
--admin \
1616
--name $clusterName \
1717
--resource-group $resourceGroupName \
1818
--subscription $subscriptionId \
1919
--only-show-errors
2020

21-
# Install Helm
22-
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 -o get_helm.sh -s
23-
chmod 700 get_helm.sh
24-
./get_helm.sh &>/dev/null
25-
2621
# Install NGINX ingress controller
2722
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
2823
helm install nginx-ingress ingress-nginx/ingress-nginx \

scenarios/AksOpenAiTerraform/terraform/.terraform.lock.hcl

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scenarios/AksOpenAiTerraform/terraform/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module "openai" {
6262
log_analytics_workspace_id = module.log_analytics_workspace.id
6363
}
6464

65-
module "aks_cluster" {
65+
module "aks" {
6666
source = "./modules/aks"
6767
name = "AksCluster"
6868
location = var.location
@@ -252,7 +252,7 @@ resource "azurerm_federated_identity_credential" "this" {
252252
resource_group_name = azurerm_resource_group.main.name
253253

254254
audience = ["api://AzureADTokenExchange"]
255-
issuer = module.aks_cluster.oidc_issuer_url
255+
issuer = module.aks.oidc_issuer_url
256256
parent_id = azurerm_user_assigned_identity.aks_workload.id
257257
subject = "system:serviceaccount:${local.namespace}:${local.service_account_name}"
258258
}
@@ -266,11 +266,11 @@ resource "azurerm_role_assignment" "cognitive_services_user_assignment" {
266266
resource "azurerm_role_assignment" "network_contributor_assignment" {
267267
role_definition_name = "Network Contributor"
268268
scope = azurerm_resource_group.main.id
269-
principal_id = module.aks_cluster.aks_identity_principal_id
269+
principal_id = module.aks.aks_identity_principal_id
270270
}
271271

272272
resource "azurerm_role_assignment" "acr_pull_assignment" {
273273
role_definition_name = "AcrPull"
274274
scope = module.container_registry.id
275-
principal_id = module.aks_cluster.kubelet_identity_object_id
275+
principal_id = module.aks.kubelet_identity_object_id
276276
}

0 commit comments

Comments
 (0)