Skip to content

Commit

Permalink
Dockerfile-aks, nginx conf for aca and aks, Working on easy auth, wor…
Browse files Browse the repository at this point in the history
…king on cert manager
  • Loading branch information
dminkovski committed Feb 23, 2024
1 parent 14da150 commit efe0d95
Show file tree
Hide file tree
Showing 24 changed files with 853 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ static/

# Generated manifests
app/backend/manifests/azd-env-configmap.yml
deploy/aks/easyauth/config-output.md
5 changes: 2 additions & 3 deletions app/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ FROM nginx:alpine

WORKDIR /usr/share/nginx/html
COPY --from=build /app/build .
COPY --from=build /app/nginx/default.conf /etc/nginx/conf.d
COPY --from=build /app/nginx/nginx.conf.template /etc/nginx/conf.d

EXPOSE 80

#CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g \"daemon off;\""]
CMD ["/bin/sh", "-c", "nginx -g \"daemon off;\""]
CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g \"daemon off;\""]
21 changes: 21 additions & 0 deletions app/frontend/Dockerfile-aks
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:18-alpine AS build

# make the 'app' folder the current working directory
WORKDIR /app

COPY . .


# install project dependencies
RUN npm install
RUN npm run build

FROM nginx:alpine

WORKDIR /usr/share/nginx/html
COPY --from=build /app/build .
COPY --from=build /app/nginx/default.conf /etc/nginx/conf.d

EXPOSE 80

CMD ["/bin/sh", "-c", "nginx -g \"daemon off;\""]
18 changes: 18 additions & 0 deletions app/frontend/nginx/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80;

access_log /var/log/nginx/default.access.log;
error_log /var/log/nginx/default.error.log;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ =404;
}

location /api {
proxy_ssl_server_name on;
proxy_http_version 1.1;
proxy_pass $REACT_APP_API_BASE_URL;
}
}
21 changes: 20 additions & 1 deletion deploy/aks/azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ services:
host: aks
k8s:
namespace: azure-open-ai
docker:
path: ./Dockerfile-aks

infra:
path: ./infra
Expand All @@ -35,7 +37,12 @@ hooks:
run: ./scripts/predeploy.ps1
interactive: true
continueOnError: false
postprovision:
posix:
shell: sh
run: ./scripts/predeploy.sh
interactive: true
continueOnError: false
postdeploy:
windows:
shell: pwsh
run: ./scripts/prepdocs.ps1
Expand All @@ -46,3 +53,15 @@ hooks:
run: ./scripts/prepdocs.sh
interactive: true
continueOnError: false
postup:
windows:
shell: pwsh
run: ./scripts/easyauth.ps1
interactive: true
continueOnError: false
postdown:
windows:
shell: pwsh
run: ./scripts/easyauth-down.ps1
interactive: true
continueOnError: false
18 changes: 18 additions & 0 deletions deploy/aks/easyauth/cluster-issuer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt
solvers:
- http01:
ingress:
class: nginx
podTemplate:
spec:
nodeSelector:
"kubernetes.io/os": linux
35 changes: 35 additions & 0 deletions deploy/aks/easyauth/easyauth-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: easyauth-ingress-default
annotations:
nginx.ingress.kubernetes.io/auth-url: "https://$host/easyauth/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://$host/easyauth/login"
nginx.ingress.kubernetes.io/auth-response-headers: "x-injected-userinfo,x-injected-name,x-injected-oid,x-injected-preferred-username,x-injected-sub,x-injected-tid,x-injected-email,x-injected-groups,x-injected-scp,x-injected-roles,x-injected-graph"
cert-manager.io/cluster-issuer: letsencrypt
#nginx.ingress.kubernetes.io/rewrite-target: "/$1"
kubernetes.io/ingress.class: "nginx"
spec:
ingressClassName: nginx
tls:
- hosts:
- aks-openai-easy-auth-proxy.westeurope.cloudapp.azure.com
secretName: aks-openai-easy-auth-proxy.westeurope.cloudapp.azure.com-tls
rules:
- host: aks-openai-easy-auth-proxy.westeurope.cloudapp.azure.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: backend-service
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
23 changes: 23 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: easyauth-proxy
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.0.2
21 changes: 21 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "easyauth-proxy.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "easyauth-proxy.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "easyauth-proxy.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "easyauth-proxy.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
63 changes: 63 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "easyauth-proxy.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "easyauth-proxy.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "easyauth-proxy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "easyauth-proxy.labels" -}}
helm.sh/chart: {{ include "easyauth-proxy.chart" . }}
{{ include "easyauth-proxy.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "easyauth-proxy.selectorLabels" -}}
app.kubernetes.io/name: {{ include "easyauth-proxy.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "easyauth-proxy.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "easyauth-proxy.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "easyauth-proxy.fullname" . }}
labels:
{{- include "easyauth-proxy.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "easyauth-proxy.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "easyauth-proxy.fullname" . }}-ingress
labels:
{{- include "easyauth-proxy.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
tls:
- hosts:
- {{ .Values.appHostName }}
secretName: {{ .Values.tlsSecretName }}
rules:
- host: {{ .Values.appHostName }}
http:
paths:
- path: {{ .Values.basePath }}
pathType: Prefix
backend:
service:
name: {{ include "easyauth-proxy.fullname" . }}
port:
number: {{ .Values.service.port }}
#{{- end }}
11 changes: 11 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.claimName }}
spec:
accessModes:
- ReadWriteMany
storageClassName: azurefile
resources:
requests:
storage: 5Gi
7 changes: 7 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.secret.name}}
type: Opaque
data:
CLIENT_SECRET: {{ .Values.secret.azureclientsecret | b64enc }}
15 changes: 15 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "easyauth-proxy.fullname" . }}
labels:
{{- include "easyauth-proxy.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "easyauth-proxy.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions deploy/aks/easyauth/easyauth-proxy/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "easyauth-proxy.serviceAccountName" . }}
labels:
{{- include "easyauth-proxy.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit efe0d95

Please sign in to comment.