Skip to content

Commit

Permalink
made better
Browse files Browse the repository at this point in the history
  • Loading branch information
bradygaster committed Jun 7, 2020
1 parent fb7bee1 commit 30b6d1a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 32 deletions.
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
80 changes: 50 additions & 30 deletions create-resources.azcli
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
#!/bin/bash

# resourceGroup="covid-screening-app-resources-05" # the name of the resource group
# apimName="screening-apis-05" # the name of the api management resource
# publisherName="Ralphdalf" # the owner name of the API management instance
# publisherEmail="notralphsrealemail@microsoft.com" # the owner email of the API management instance
# cosmosDbName="screeningcosmosdb-05" # the name of the cosmos db resource
# appServicePlanName="covidscreeningappapi-west-plan-05" # the name of the app service plan for the app service
# appServiceName="covidscreeningappapi-west-05" # the name of the app service that'll host the code
# region="westus" # the region in which we want things to be created
resourceGroup="covid-screening-app-resources-08" # the name of the resource group
apimName="screening-apis-08" # the name of the api management resource
cosmosDbName="screeningcosmosdb-08" # the name of the cosmos db resource
appServicePlanName="covidscreeningappapi-west-plan-08" # the name of the app service plan for the app service
appServiceName="covidscreeningappapi-west-08" # the name of the app service that'll host the code
acrName="covidscreeningregistry08" # the acr resource name
region="westus" # the region in which we want things to be created
publisherName="Ralphdalf" # the owner name of the API management instance
publisherEmail="notralphsrealemail@microsoft.com" # the owner email of the API management instance

# build the docker image for the app
docker build --rm --pull -f "./src/COVIDScreeningApi/Dockerfile" -t "covidscreeningapi:latest" "."

# tag the image for acr publish
docker tag "${acrName}.azurecr.io/covidscreeningapi:latest"

# push the image to acr
docker push "${acrName}.azurecr.io/covidscreeningapi:latest"

# create the resource group
echo "Creating the resource group"
az group create --name $resourceGroup --location $region
echo "Created resource group"

# create the acr resource
az acr create --name "$acrName" --resource-group "$resourceGroup" --sku Standard --admin-enabled true

# get the acr password
acrPassword=$(az acr credential show --name "$acrName" --resource-group "$resourceGroup" --query passwords[0].value --output tsv)

# get the acr username
acrUsername=$(az acr credential show --name "$acrName" --resource-group "$resourceGroup" --query username --output tsv)

# create the app service plan for the app
echo "Creating app service plan"
az appservice plan create --name $appServicePlanName --resource-group $resourceGroup --is-linux
echo "Created app service plan"

# create the app service
echo "Creating app service"
az webapp create --name "$appServiceName" --plan "$appServicePlanName" --resource-group "$resourceGroup" -i "${acrName}.azurecr.io/covidscreeningapi:latest"
echo "Created app service"

# get the host name for the site
swaggerHostName="https://$(az webapp show -n $appServiceName -g $resourceGroup --query hostNames --output tsv)"

# set the swagger base url config property
echo "Updating swagger base url"
az webapp config appsettings set \
--settings SwaggerBaseUrl="${swaggerHostName}" \
--name "$appServiceName" \
--resource-group "$resourceGroup"
echo "Updated swagger base url"

# create the apim resource
echo "Creating APIM resource"
az apim create --name $apimName --resource-group $resourceGroup --sku-name Consumption --publisher-email $publisherEmail --publisher-name $publisherName
Expand All @@ -38,19 +78,9 @@ echo "Created Cosmos DB collections"

# get the connection string of the cosmos db resource
echo "Getting Cosmos DB connection string"
cosmosDbConnectionString=$(az cosmosdb keys list -n covid-screening-data -g COVIDScreeningAPI --type connection-strings --query connectionStrings[0].connectionString --output tsv)
cosmosDbConnectionString=$(az cosmosdb keys list -n $cosmosDbName -g $resourceGroup --type connection-strings --query connectionStrings[0].connectionString --output tsv)
echo "Got Cosmos DB connection string"

# create the app service plan for the app
echo "Creating app service plan"
az appservice plan create --name $appServicePlanName --resource-group $resourceGroup
echo "Created app service plan"

# create the app service
echo "Creating app service"
az webapp create --name $appServiceName --plan $appServicePlanName --resource-group $resourceGroup
echo "Created app service"

# set the connection string in the app service
echo "Updating app service connection string"
az webapp config connection-string set \
Expand All @@ -60,15 +90,5 @@ az webapp config connection-string set \
--resource-group "$resourceGroup"
echo "Updated app service connection string"

# get the host name for the site
swaggerHostName="https://$(az webapp show -n $appServiceName -g $resourceGroup --query hostNames --output tsv)"

# set the swagger base url config property
echo "Updating swagger base url"
az webapp config appsettings set \
--settings SwaggerBaseUrl="$cosmosDbConnectionString" \
--name "$appServiceName" \
--resource-group "$resourceGroup"
echo "Updated swagger base url"

# human validation moment
echo "Finished"
5 changes: 3 additions & 2 deletions src/COVIDScreeningApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["COVIDScreeningApi.csproj", ""]
RUN dotnet restore "COVIDScreeningApi.csproj"
COPY ["src/COVIDScreeningApi/COVIDScreeningApi.csproj", "src/COVIDScreeningApi/"]
RUN dotnet restore "src/COVIDScreeningApi/COVIDScreeningApi.csproj"
COPY . .
WORKDIR "/src/src/COVIDScreeningApi"
RUN dotnet build "COVIDScreeningApi.csproj" -c Release -o /app/build

FROM build AS publish
Expand Down

0 comments on commit 30b6d1a

Please sign in to comment.