microsoft / entref-spring-boot

A RESTful DAL (Database Abstraction Layer) reference implementation written using Spring.
MIT License
17 stars 22 forks source link

Walkthrough of how to deploy with azure cli #59

Open bengreenier opened 5 years ago

bengreenier commented 5 years ago

We should document the steps required to deploy the entire solution, from 0 to production, using only local commands (no pipeline approach). Here is what i did for reference:

Note: missing tm global endpoint final az group deployment

commands ``` COSMOS_AT=cosmos access token DOCKER_AT=docker access token SUBSCRIPTION_ID=azure subscription id λ az --version azure-cli (2.0.53) acr (2.1.11) acs (2.3.13) advisor (2.0.0) ams (0.3.1) appservice (0.2.9) backup (1.2.1) batch (3.4.1) batchai (0.4.5) billing (0.2.0) botservice (0.1.3) cdn (0.2.0) cloud (2.1.0) cognitiveservices (0.2.4) command-modules-nspkg (2.0.2) configure (2.0.19) consumption (0.4.1) container (0.3.9) core (2.0.53) cosmosdb (0.2.6) dla (0.2.3) dls (0.1.6) dms (0.1.1) eventgrid (0.2.0) eventhubs (0.3.1) extension (0.2.3) feedback (2.1.4) find (0.2.12) hdinsight (0.1.0) interactive (0.4.1) iot (0.3.4) iotcentral (0.1.4) keyvault (2.2.8) lab (0.1.4) maps (0.3.3) monitor (0.2.7) network (2.2.11) nspkg (3.0.3) policyinsights (0.1.0) profile (2.1.2) rdbms (0.3.5) redis (0.3.2) relay (0.1.2) reservations (0.4.1) resource (2.1.7) role (2.1.11) search (0.1.1) servicebus (0.3.2) servicefabric (0.1.9) signalr (1.0.0) sql (2.1.6) storage (2.2.7) telemetry (1.0.0) vm (2.2.10) Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\begreen\.azure\cliextensions' Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)] Legal docs and information: aka.ms/AzureCliLegal C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure\global-resources (master) λ az login Note, we have launched a browser for you to login. For old experience with device code, use "az login --use-device-code" You have logged in. Now let us find all the subscriptions to which you have access... [ ... "name": "CSE Americas Dev Crews", ] C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure\global-resources (master) λ az account set --subscription "CSE Americas Dev Crews" C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure\global-resources (master) λ az group create --name "brgj-global" --location eastus { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-global", "location": "eastus", "managedBy": null, "name": "brgj-global", "properties": { "provisioningState": "Succeeded" }, "tags": null } λ az group deployment create --resource-group "brgj-global" --template-file azuredeploy.json { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-global/providers/Microsoft.Resources/deployments/azuredeploy", "location": null, "name": "azuredeploy", "properties": { "correlationId": "8158bb6d-2988-4c3e-94b2-1cf36c65d6d6", "debugSetting": null, "dependencies": [], "duration": "PT7M37.9171294S", "mode": "Incremental", "onErrorDeployment": null, "outputResources": [ { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-global/providers/Microsoft.ContainerRegistry/registries/acrImages", "resourceGroup": "brgj-global" }, { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-global/providers/Microsoft.DocumentDB/databaseAccounts/wyoqegu7arweacosmos-instance", "resourceGroup": "brgj-global" }, { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-global/providers/Microsoft.Network/trafficManagerProfiles/tm-profiles", "resourceGroup": "brgj-global" } ], "outputs": null, "parameters": { "container_registry_name": { "type": "String", "value": "acrImages" }, "database-name": { "type": "String", "value": "data" }, "database_account_name": { "type": "String", "value": "wyoqegu7arweacosmos-instance" }, "traffic_manager_profiles_name": { "type": "String", "value": "tm-profiles" } }, "parametersLink": null, "providers": [ { "id": null, "namespace": "Microsoft.DocumentDB", "registrationState": null, "resourceTypes": [ { "aliases": null, "apiVersions": null, "locations": [ "eastus" ], "properties": null, "resourceType": "databaseAccounts" } ] }, { "id": null, "namespace": "Microsoft.ContainerRegistry", "registrationState": null, "resourceTypes": [ { "aliases": null, "apiVersions": null, "locations": [ "eastus" ], "properties": null, "resourceType": "registries" } ] }, { "id": null, "namespace": "Microsoft.Network", "registrationState": null, "resourceTypes": [ { "aliases": null, "apiVersions": null, "locations": [ "global" ], "properties": null, "resourceType": "trafficManagerProfiles" } ] } ], "provisioningState": "Succeeded", "template": null, "templateHash": "9709172472397773744", "templateLink": null, "timestamp": "2019-01-02T15:37:03.086351+00:00" }, "resourceGroup": "brgj-global" } C:\Users\begreen\git\containers-rest-cosmos-appservice-java\api (master) λ set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181\ λ c:\bin\maven\bin\mvn package ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:13 min [INFO] Finished at: 2019-01-02T10:45:37-05:00 [INFO] ------------------------------------------------------------------------ C:\Users\begreen\git\containers-rest-cosmos-appservice-java\api (master) λ docker build . Sending build context to Docker daemon 80.46MB Step 1/6 : FROM openjdk:8-jdk-alpine ---> 04060a9dfc39 Step 2/6 : VOLUME /tmp ---> Using cache ---> d6535295ff50 Step 3/6 : EXPOSE 8080 ---> Using cache ---> 92189c40eb21 Step 4/6 : ARG JAR_FILE=target/spring-dal-0.0.1-SNAPSHOT.jar ---> Using cache ---> 8a8b04986396 Step 5/6 : ADD ${JAR_FILE} spring-dal.jar ---> 833565f20850 Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/spring-dal.jar"] ---> Running in 48b4cca8eab9 Removing intermediate container 48b4cca8eab9 ---> d228f816362a Successfully built d228f816362a SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories. C:\Users\begreen\git\containers-rest-cosmos-appservice-java\api (master) λ docker login acrimages.azurecr.io -u acrImages -p DOCKER_AT C:\Users\begreen\git\containers-rest-cosmos-appservice-java\api (master) λ docker tag d228f816362a acrimages.azurecr.io/api:v1.0 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\api (master) λ docker push acrimages.azurecr.io/api The push refers to repository [acrimages.azurecr.io/api] 0a6a26bed14d: Pushed ac1faac0988e: Pushed dbc783c89851: Pushed 7bff100f35cb: Pushed v1.0: digest: sha256:1ddef34574788e7cdce32791e0003df106330682c295d89d28344041d4e9da54 size: 1159 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ npm install C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ npm run build C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ npm run build C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ docker build . Sending build context to Docker daemon 141.3MB Step 1/6 : FROM nginx:1.14.0-alpine 1.14.0-alpine: Pulling from library/nginx c67f3896b22c: Pull complete 428de5b8d58a: Pull complete 7efd417f3e28: Pull complete 61a56b170416: Pull complete Digest: sha256:8976218be775f4244df2a60a169d44606b6978bac4375192074cefc0c7824ddf Status: Downloaded newer image for nginx:1.14.0-alpine ---> 14d4a58e0d2e Step 2/6 : EXPOSE 8080 ---> Running in 339935f8f7bb Removing intermediate container 339935f8f7bb ---> 050fd4df6880 Step 3/6 : RUN rm -rv /etc/nginx/conf.d ---> Running in 35599c72b94d removed '/etc/nginx/conf.d/default.conf' removed directory: '/etc/nginx/conf.d' Removing intermediate container 35599c72b94d ---> 50013d1d467a Step 4/6 : COPY conf /etc/nginx ---> 67a9ccbd18a7 Step 5/6 : WORKDIR /usr/share/nginx/html Removing intermediate container 815b510b076a ---> e93f8998bba2 Step 6/6 : COPY ./dist/ /usr/share/nginx/html ---> 8ba4fdc0425f Successfully built 8ba4fdc0425f SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and direc tories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permiss ions for sensitive files and directories. C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ docker tag 8ba4fdc0425f acrimages.azurecr.io/ui:v1.0 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (master) (projectjacksonclient@1.0.0) λ docker push acrimages.azurecr.io/ui The push refers to repository [acrimages.azurecr.io/ui] 94601a480036: Pushed 578d0edcd27f: Pushed 7cffa3c956c5: Pushed 9a07ffbe3d7d: Pushed 955e7d7f7300: Pushed 95bb4e754f2d: Pushed ebf12965380b: Pushed v1.0: digest: sha256:27b078181780ea1c9d6c29a74150cffb4b184c482a7ffb7d96868cc7f900f116 size: 1777 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (master) λ az group create --name "brgj-eastus-single" --location eastus { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-eastus-single", "location": "eastus", "managedBy": null, "name": "brgj-eastus-single", "properties": { "provisioningState": "Succeeded" }, "tags": null } C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (master) λ az group create --name "brgj-westus-single" --location westus { "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/brgj-westus-single", "location": "westus", "managedBy": null, "name": "brgj-westus-single", "properties": { "provisioningState": "Succeeded" }, "tags": null } C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (hotfix/arm-custom-image) λ az group deployment create --resource-group "brgj-eastus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (hotfix/arm-custom-image) λ az group deployment create --resource-group "brgj-westus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (hotfix/arm-custom-image) λ az ad app create --display-name brgj-single --reply-urls http://tm-profiles.trafficmanager.net/ui --identifier-uris http://tm-profiles.trafficmanager.net/ui --available-to-other-tenants true ... appId: "88e84b81-d1a7-4286-a70b-ce753a986a98" C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (hotfix/arm-custom-image) λ az group deployment create --resource-group "brgj-eastus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true oauth_id=88e84b81-d1a7-4286-a70b-ce753a986a98 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\infrastructure (hotfix/arm-custom-image) λ az group deployment create --resource-group "brgj-westus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true oauth_id=88e84b81-d1a7-4286-a70b-ce753a986a98 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ set WEBPACK_PROP_AAD_CLIENT_ID=88e84b81-d1a7-4286-a70b-ce753a986a98 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ set WEBPACK_PROP_API_BASE_URL=http://tm-profiles.trafficmanager.net C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ set WEBPACK_PROP_UI_BASEPATH=ui C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ npm run build C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ docker build . C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ docker push acrimages.azurecr.io/ui C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ az group deployment create --resource-group "brgj-westus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui docker_ui_tag=v1.1 database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true oauth_id=88e84b81-d1a7-4286-a70b-ce753a986a98 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\ui (hotfix/arm-custom-image) (projectjacksonclient@1.0.0) λ az group deployment create --resource-group "brgj-eastus-single" --template-file azuredeploy.json --parameters docker_registry_username=acrImages docker_registry_password=DOCKER_AT docker_title_url=acrimages.azurecr.io/api docker_person_url=acrimages.azurecr.io/api docker_ui_url=acrimages.azurecr.io/ui docker_ui_tag=v1.1 database_connection_string=mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/?ssl=true oauth_id=88e84b81-d1a7-4286-a70b-ce753a986a98 manually set the aad app id uri (tenant/appid): https://microsoft.onmicrosoft.com/88e84b81-d1a7-4286-a70b-ce753a986a98 switch to bash giving up on bash, running importdata.sh steps manually C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) curl --remote-name-all https://datasets.imdbws.com/{name.basics.tsv.gz,title.basics.tsv.gz,title.principals.tsv.gz} C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) 7z e *.tsv.gz -o* C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb database create -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection create -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name titles --partition-key-path "/'$v'/tconst/'$v'" --throughput 100000 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection create -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name names --partition-key-path "/'$v'/nconst/'$v'" --throughput 100000 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection create -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name principals_mapping --partition-key-path "/'$v'/tconst/'$v'" --throughput 100000 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ mongoimport --uri "mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/IMDb?ssl=true&replicaSet=globaldb" --type tsv title.basics.tsv\data.tsv --headerline --collection titles --numInsertionWorkers 100 --sslAllowInvalidCertificates --ignoreBlanks C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ mongoimport --uri "mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/IMDb?ssl=true&replicaSet=globaldb" --type tsv name.basics.tsv\data.tsv --headerline --collection names --numInsertionWorkers 100 --sslAllowInvalidCertificates --ignoreBlanks C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ mongoimport --uri "mongodb://wyoqegu7arweacosmos-instance:COSMOS_AT@wyoqegu7arweacosmos-instance.documents.azure.com:10255/IMDb?ssl=true&replicaSet=globaldb" --type tsv title.principals.tsv\data.tsv --headerline --collection principals_mapping --numInsertionWorkers 40 --sslAllowInvalidCertificates --ignoreBlanks C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection update -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name names --throughput 10000 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection update -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name titles --throughput 10000 C:\Users\begreen\git\containers-rest-cosmos-appservice-java\data (hotfix/arm-custom-image) λ az cosmosdb collection update -g "brgj-global" -n "wyoqegu7arweacosmos-instance" --db-name "IMDb" --collection-name principals_mapping --throughput 10000 ```
bengreenier commented 5 years ago

those commands can definitely be order optimized a bit.

rickrain commented 5 years ago

There will be two different deployment instructions: