Skip to content

Commit 966d758

Browse files
committed
New directory structure
1 parent 89ac911 commit 966d758

File tree

12 files changed

+857
-0
lines changed

12 files changed

+857
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
export OPEN_AI_SUBDOMAIN="magic8ball"
2+
3+
# Variables
4+
acrName="CyanAcr"
5+
acrResourceGrougName="CyanRG"
6+
location="FranceCentral"
7+
attachAcr=false
8+
imageName="magic8ball"
9+
tag="v2"
10+
containerName="magic8ball"
11+
image="$acrName.azurecr.io/$imageName:$tag"
12+
imagePullPolicy="IfNotPresent" # Always, Never, IfNotPresent
13+
managedIdentityName="CyanWorkloadManagedIdentity"
14+
federatedIdentityName="Magic8BallFederatedIdentity"
15+
16+
# Azure Subscription and Tenant
17+
subscriptionId=$(az account show --query id --output tsv)
18+
subscriptionName=$(az account show --query name --output tsv)
19+
tenantId=$(az account show --query tenantId --output tsv)
20+
21+
# Parameters
22+
title="Magic 8 Ball"
23+
label="Pose your question and cross your fingers!"
24+
temperature="0.9"
25+
imageWidth="80"
26+
27+
# OpenAI
28+
openAiName="CyanOpenAi "
29+
openAiResourceGroupName="CyanRG"
30+
openAiType="azure_ad"
31+
openAiBase="https://cyanopenai.openai.azure.com/"
32+
openAiModel="gpt-35-turbo"
33+
openAiDeployment="gpt-35-turbo"
34+
35+
# Nginx Ingress Controller
36+
nginxNamespace="ingress-basic"
37+
nginxRepoName="ingress-nginx"
38+
nginxRepoUrl="https://kubernetes.github.io/ingress-nginx"
39+
nginxChartName="ingress-nginx"
40+
nginxReleaseName="nginx-ingress"
41+
nginxReplicaCount=3
42+
43+
# Certificate Manager
44+
cmNamespace="cert-manager"
45+
cmRepoName="jetstack"
46+
cmRepoUrl="https://charts.jetstack.io"
47+
cmChartName="cert-manager"
48+
cmReleaseName="cert-manager"
49+
50+
# Cluster Issuer
51+
52+
clusterIssuerName="letsencrypt-nginx"
53+
clusterIssuerTemplate="cluster-issuer.yml"
54+
55+
# AKS Cluster
56+
aksClusterName="CyanAks"
57+
aksResourceGroupName="CyanRG"
58+
59+
# Sample Application
60+
namespace="magic8ball"
61+
serviceAccountName="magic8ball-sa"
62+
deploymentTemplate="deployment.yml"
63+
serviceTemplate="service.yml"
64+
configMapTemplate="configMap.yml"
65+
secretTemplate="secret.yml"
66+
67+
# Ingress and DNS
68+
ingressTemplate="ingress.yml"
69+
ingressName="magic8ball-ingress"
70+
dnsZoneName="contoso.com"
71+
dnsZoneResourceGroupName="DnsResourceGroup"
72+
subdomain="magic"
73+
host="$subdomain.$dnsZoneName"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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
13+
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
61+
WORKDIR /app
62+
63+
# Copy the virtual environment from the builder stage
64+
COPY --from=builder /opt/venv /opt/venv
65+
66+
# Set environment variables
67+
ENV PATH="/opt/venv/bin:$PATH"
68+
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
79+
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
94+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]

0 commit comments

Comments
 (0)