Skip to content

Commit

Permalink
initial commit: contosotraders
Browse files Browse the repository at this point in the history
  • Loading branch information
mithunshanbhag committed Dec 3, 2022
1 parent 4ffd531 commit 6fca32a
Show file tree
Hide file tree
Showing 728 changed files with 41,303 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sh eol=lf
mvnw eol=lf
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
42 changes: 42 additions & 0 deletions .github/workflows/contoso-traders-app-deployment-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: contoso-traders-app-deployment-legacy

on:
workflow_dispatch:
push:
branches: ["main"]
paths:
[
"src/ContosoTraders.Api.Core/**",
"src/ContosoTraders.Api.Images/**",
"src/ContosoTraders.Api.Products/**",
]

env:
PRODUCTS_WEBAPP_NAME: contoso-traders-products

jobs:
deploy-products-api:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: azure login
uses: azure/login@v1
with:
creds: ${{ secrets.SERVICEPRINCIPAL }}
# @TODO: REMOVE EVERYTHING BELOW THIS LINE AFTER AKS INTEGRATION IS DONE
- name: install dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: dotnet publish
run: dotnet publish -o ../Publish/ContosoTraders.Api.Products -c release
working-directory: src/ContosoTraders.Api.Products
- name: diagnostic output
run: ls -la ./src/Publish/ContosoTraders.Api.Products
- name: deploy to app service
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.PRODUCTS_WEBAPP_NAME }}${{ secrets.ENVIRONMENT }}
package: ./src/Publish/ContosoTraders.Api.Products

264 changes: 264 additions & 0 deletions .github/workflows/contoso-traders-app-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
name: contoso-traders-app-deployment

on:
workflow_dispatch:
push:
branches: ["main"]
paths:
[
"src/ContosoTraders.Api.Carts/**",
"src/ContosoTraders.Api.Core/**",
"src/ContosoTraders.Api.Images/**",
"src/ContosoTraders.Api.Products/**",
"src/ContosoTraders.Ui.Website/**",
]

env:
ACR_NAME: contosotradersacr
AKS_CLUSTER_NAME: contoso-traders-aks
AKS_DNS_LABEL: contoso-traders-products
AKS_NODES_RESOURCE_GROUP_NAME: contoso-traders-aks-nodes-rg
AKS_SECRET_NAME_ACR_PASSWORD: contoso-traders-acr-password
AKS_SECRET_NAME_KV_ENDPOINT: contoso-traders-kv-endpoint
AKS_SECRET_NAME_MI_CLIENTID: contoso-traders-mi-clientid
CARTS_ACA_NAME: contoso-traders-carts
CARTS_ACR_REPOSITORY_NAME: contosotradersapicarts
CDN_PROFILE_NAME: contoso-traders-cdn
KV_NAME: contosotraderskv
PRODUCTS_ACR_REPOSITORY_NAME: contosotradersapiproducts
RESOURCE_GROUP_NAME: contoso-traders-rg
UI_CDN_ENDPOINT_NAME: contoso-traders-ui2
UI_STORAGE_ACCOUNT_NAME: contosotradersui2
USER_ASSIGNED_MANAGED_IDENTITY_NAME: contoso-traders-mi-kv-access

jobs:
deploy-carts-api:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: azure login
uses: azure/login@v1
with:
creds: ${{ secrets.SERVICEPRINCIPAL }}
- name: extract acr password
uses: azure/CLI@v1
id: extract-acr-password
with:
inlineScript: echo "acrPassword"="$(az acr credential show -n ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }} -g ${{ env.RESOURCE_GROUP_NAME }} --query "passwords[0].value" --output tsv)" >> $GITHUB_OUTPUT
- name: azure container registry login
uses: azure/docker-login@v1
with:
login-server: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io
username: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}
password: ${{ steps.extract-acr-password.outputs.acrPassword }}
- name: docker build
run: docker build src -f ./src/ContosoTraders.Api.Carts/Dockerfile -t ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.CARTS_ACR_REPOSITORY_NAME }}:latest -t ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.CARTS_ACR_REPOSITORY_NAME }}:${{ github.sha }}
- name: docker push (to acr)
run: docker push --all-tags ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.CARTS_ACR_REPOSITORY_NAME }}
- name: deploy to aca
uses: azure/CLI@v1
with:
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az containerapp update -n ${{ env.CARTS_ACA_NAME }}${{ secrets.ENVIRONMENT }} -g ${{ env.RESOURCE_GROUP_NAME }} --image ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.CARTS_ACR_REPOSITORY_NAME }}:${{ github.sha }}
deploy-products-api:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: azure login
uses: azure/login@v1
with:
creds: ${{ secrets.SERVICEPRINCIPAL }}
- name: install helm
uses: Azure/setup-helm@v3
id: install-helm
- name: extract acr password
uses: azure/CLI@v1
id: extract-acr-password
with:
inlineScript: echo "acrPassword"="$(az acr credential show -n ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }} -g ${{ env.RESOURCE_GROUP_NAME }} --query "passwords[0].value" --output tsv)" >> $GITHUB_OUTPUT
- name: azure container registry login
uses: azure/docker-login@v1
with:
login-server: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io
username: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}
password: ${{ steps.extract-acr-password.outputs.acrPassword }}
- name: docker build
run: docker build src -f ./src/ContosoTraders.Api.Products/Dockerfile -t ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.PRODUCTS_ACR_REPOSITORY_NAME }}:latest -t ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.PRODUCTS_ACR_REPOSITORY_NAME }}:${{ github.sha }}
- name: docker push (to acr)
run: docker push --all-tags ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.PRODUCTS_ACR_REPOSITORY_NAME }}
- name: set aks context
uses: azure/aks-set-context@v3
with:
resource-group: ${{ env.RESOURCE_GROUP_NAME }}
cluster-name: ${{ env.AKS_CLUSTER_NAME }}${{ secrets.ENVIRONMENT }}
- name: setup kubectl
uses: azure/setup-kubectl@v3
- name: create kubernetes secret (acr password)
uses: Azure/k8s-create-secret@v3.0
with:
secret-name: ${{ env.AKS_SECRET_NAME_ACR_PASSWORD }}
container-registry-url: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io
container-registry-username: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}
container-registry-password: ${{ steps.extract-acr-password.outputs.acrPassword }}
- name: get managedIdentityClientId
uses: azure/CLI@v1
id: get-managedIdentityClientId
with:
inlineScript: echo "managedIdentityClientId"="$(az identity show -g ${{ env.RESOURCE_GROUP_NAME }} --name ${{ env.USER_ASSIGNED_MANAGED_IDENTITY_NAME }}${{ secrets.ENVIRONMENT }} --query "clientId" -o tsv)" >> $GITHUB_OUTPUT
- name: create kubernetes secret (kv endpoint)
uses: Azure/k8s-create-secret@v3.0
with:
secret-type: "generic"
secret-name: ${{ env.AKS_SECRET_NAME_KV_ENDPOINT }}
string-data: '{ "${{ env.AKS_SECRET_NAME_KV_ENDPOINT }}" : "https://${{ env.KV_NAME }}${{ secrets.ENVIRONMENT }}.vault.azure.net/" }'
- name: create kubernetes secret (managed identity client id)
uses: Azure/k8s-create-secret@v3.0
with:
secret-type: "generic"
secret-name: ${{ env.AKS_SECRET_NAME_MI_CLIENTID }}
string-data: '{ "${{ env.AKS_SECRET_NAME_MI_CLIENTID }}" : "${{ steps.get-managedIdentityClientId.outputs.managedIdentityClientId }}" }'
- name: substitute tokens in deployment manifest
uses: cschleiden/replace-tokens@v1.2
with:
tokenPrefix: "{"
tokenSuffix: "}"
files: ./src/ContosoTraders.Api.Products/Manifests/Deployment.yaml
env:
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
- name: lint deployment manifest
uses: azure/k8s-lint@v1
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Deployment.yaml
- name: apply deployment manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Deployment.yaml
images: ${{ env.ACR_NAME }}${{ secrets.ENVIRONMENT }}.azurecr.io/${{ env.PRODUCTS_ACR_REPOSITORY_NAME }}:${{ github.sha }}
imagepullsecrets: ${{ env.AKS_SECRET_NAME_ACR_PASSWORD }}
force: true
- name: apply service manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Service.yaml
force: true
# create the ingress controller
- name: create ingress controller
run: |
az aks get-credentials --resource-group ${{ env.RESOURCE_GROUP_NAME }} --name ${{ env.AKS_CLUSTER_NAME }}${{ secrets.ENVIRONMENT }}
${{ steps.install-helm.outputs.helm-path }} repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
${{ steps.install-helm.outputs.helm-path }} repo update
${{ steps.install-helm.outputs.helm-path }} upgrade --install nginx-ingress ingress-nginx/ingress-nginx \
--set controller.replicaCount=1 \
--set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set controller.admissionWebhooks.patch.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set controller.service.externalTrafficPolicy=Local
- name: set dns label on public ip
uses: azure/CLI@v1
with:
inlineScript: az network public-ip update --dns-name ${{ env.AKS_DNS_LABEL }}${{ secrets.ENVIRONMENT }} -g ${{ env.AKS_NODES_RESOURCE_GROUP_NAME }} -n $(az network public-ip list --query "[?starts_with(name,'kubernetes-') ].name" -o tsv -g ${{ env.AKS_NODES_RESOURCE_GROUP_NAME }})
# hack: extract the full fqdn / dns label of the aks app's public IP address
- name: get aks-fqdn
uses: azure/CLI@v1
id: get-aks-fqdn
with:
# note: There should be a whitespace between ')' and ']'. More details: https://stackoverflow.com/a/59154958
inlineScript: echo "aksFqdn"="$(az network public-ip list --query "[?starts_with(name,'kubernetes-') ].dnsSettings.fqdn" -o tsv -g ${{ env.AKS_NODES_RESOURCE_GROUP_NAME }})" >> $GITHUB_OUTPUT
# install cert-manager
- name: apply namespace manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Namespace.yaml
force: true
- name: install cert-manager
run: |
az aks get-credentials --resource-group ${{ env.RESOURCE_GROUP_NAME }} --name ${{ env.AKS_CLUSTER_NAME }}${{ secrets.ENVIRONMENT }}
kubectl apply --validate=false -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml
- name: apply clusterIssuer manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/ClusterIssuer.yaml
force: true
- name: substitute tokens in certificate manifest
uses: cschleiden/replace-tokens@v1.2
with:
tokenPrefix: "{"
tokenSuffix: "}"
files: ./src/ContosoTraders.Api.Products/Manifests/Certificate.yaml
env:
AKS_FQDN: ${{ steps.get-aks-fqdn.outputs.aksFqdn }}
- name: apply certificate manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Certificate.yaml
force: true
- name: substitute tokens in ingress manifest
uses: cschleiden/replace-tokens@v1.2
with:
tokenPrefix: "{"
tokenSuffix: "}"
files: ./src/ContosoTraders.Api.Products/Manifests/Ingress.yaml
env:
AKS_FQDN: ${{ steps.get-aks-fqdn.outputs.aksFqdn }}
- name: apply ingress manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/Ingress.yaml
force: true
- name: apply clusterRole manifest
uses: Azure/k8s-deploy@v4
with:
manifests: ./src/ContosoTraders.Api.Products/Manifests/ClusterRole.yaml
force: true
- name: set productsApiEndpoint in kv
uses: azure/CLI@v1
with:
inlineScript: az keyvault secret set --vault-name ${{ env.KV_NAME }}${{ secrets.ENVIRONMENT }} --name productsApiEndpoint --value ${{ steps.get-aks-fqdn.outputs.aksFqdn }} --description "endpoint url (fqdn) of the products api"

deploy-ui:
runs-on: ubuntu-latest
needs: [deploy-carts-api, deploy-products-api]
steps:
- name: checkout code
uses: actions/checkout@v3
- name: azure login
uses: azure/login@v1
with:
creds: ${{ secrets.SERVICEPRINCIPAL }}
- name: get carts api endpoint
uses: azure/CLI@v1
id: get-cartsApiEndpoint
with:
inlineScript: echo "cartsApiEndpoint"="$(az keyvault secret show --vault-name ${{ env.KV_NAME }}${{ secrets.ENVIRONMENT }} --name cartsApiEndpoint --query value -o tsv)" >> $GITHUB_OUTPUT
- name: get products api endpoint
uses: azure/CLI@v1
id: get-productsApiEndpoint
with:
inlineScript: echo "productsApiEndpoint"="$(az keyvault secret show --vault-name ${{ env.KV_NAME }}${{ secrets.ENVIRONMENT }} --name productsApiEndpoint --query value -o tsv)" >> $GITHUB_OUTPUT
- name: substitute tokens in ui configuration
uses: cschleiden/replace-tokens@v1.2
with:
tokenPrefix: "{{"
tokenSuffix: "}}"
files: ./src/ContosoTraders.Ui.Website/src/services/configService.js
env:
CARTS_API_ENDPOINT: ${{ steps.get-cartsApiEndpoint.outputs.cartsApiEndpoint }}
PRODUCTS_API_ENDPOINT: ${{ steps.get-productsApiEndpoint.outputs.productsApiEndpoint }}
- name: npm install
run: npm install
working-directory: src/ContosoTraders.Ui.Website
- name: npm run build
run: npm run build
working-directory: src/ContosoTraders.Ui.Website
- name: deploy to storage
uses: azure/CLI@v1
with:
inlineScript: az storage blob sync --account-name '${{ env.UI_STORAGE_ACCOUNT_NAME }}${{ secrets.ENVIRONMENT }}' -c '$web' -s 'src/ContosoTraders.Ui.Website/build'
- name: purge CDN endpoint
uses: azure/CLI@v1
with:
inlineScript: az cdn endpoint purge --no-wait --content-paths '/*' -n '${{ env.UI_CDN_ENDPOINT_NAME }}${{ secrets.ENVIRONMENT }}' -g '${{ env.RESOURCE_GROUP_NAME }}' --profile-name '${{ env.CDN_PROFILE_NAME }}${{ secrets.ENVIRONMENT }}'
Loading

0 comments on commit 6fca32a

Please sign in to comment.