Skip to content

Commit

Permalink
improving deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
yorek committed Sep 23, 2021
1 parent 18d6e81 commit da6bfac
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,8 @@ MigrationBackup/
.ionide/

# Additional files
.env
.env
__queuestorage__/
__azurite*
directus-address.json
test.sh
50 changes: 47 additions & 3 deletions azure-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,55 @@ az group create \
-l $location

echo "Deploying Resources...";
az deployment group create \
uid=`az deployment group create \
--name AzureSQL_Directus \
--resource-group $resourceGroup \
--resource-group "$resourceGroup" \
--template-file azuredeploy.json \
--parameters \
location=$location
location="$location" \
--query "properties.outputs.uniqueId.value" \
--output tsv`

echo "Generated Unique Id: $uid"

echo "Writing client/directus-address.json..."
file="./client/directus-address.json"
site="https://directus-${uid}.azurewebsites.net"
rm -f -- $file
cat << EOF >> $file
[
"$site"
]
EOF

echo "Getting access to created storage account..."
storage="directus${uid}"
AZURE_STORAGE_CONNECTION_STRING=`az storage account show-connection-string -g "$resourceGroup" -n "$storage" --query "connectionString" -o tsv`

echo "Creating container..."
az storage container create \
--connection-string "$AZURE_STORAGE_CONNECTION_STRING" \
-n '$web'

echo "Uploading files..."
az storage blob upload-batch \
--connection-string "$AZURE_STORAGE_CONNECTION_STRING" \
-d '$web' \
-s ./client

echo "Enabling static website..."
az storage blob service-properties update \
--connection-string "$AZURE_STORAGE_CONNECTION_STRING" \
--account-name $storage \
--static-website \
--index-document index.html

website=`az storage account show -g dm-directus-4 -n directusyxxjmrwglmr62 --query "primaryEndpoints.web" -o tsv`

echo "Website available at: $website"

echo "Creating Directus 'Todo' collection..."

echo "Creating sample Todo items..."

echo "Done."
8 changes: 7 additions & 1 deletion azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,11 @@
"publicAccess": "None"
}
}
]
],
"outputs": {
"uniqueId": {
"type": "string",
"value": "[uniqueString(resourceGroup().id)]"
}
}
}
24 changes: 14 additions & 10 deletions client/client-rest.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ <h2>REST style</h2>
</footer>

<script>
API = "/api/todo";
API = "";
API_PATH = "/items/todo";
HEADERS = { 'Accept': 'application/json', 'Content-Type': 'application/json' };

// visibility filters
Expand Down Expand Up @@ -107,13 +108,16 @@ <h2>REST style</h2>
// initialize data
// by loading it from REST API
created: function() {
console.log("Getting API path...");
fetch("directus-address.json")
.then(res => res.json())
.then(res => {
fetch(res[0], {headers: HEADERS, method: "GET"})
.then(res => res.json())
.then(res => { this.todos = res == null ? [] : res; })
})
.then(res => res.json())
.then(res => {
API = res[0]+API_PATH;
console.log(`API: ${API}`)
fetch(API, {headers: HEADERS, method: "GET"})
.then(res => res.json())
.then(res => { this.todos = res == null ? [] : res.data; })
})
},

// computed properties
Expand Down Expand Up @@ -158,17 +162,17 @@ <h2>REST style</h2>
return res.json();
}
}).then(res => {
this.todos.push(res);
this.todos.push(res.data);
})
},

completeTodo: function(todo) {
fetch(API + `/${todo.id}`, {headers: HEADERS, method: "PUT", body: JSON.stringify({completed: todo.completed})});
fetch(API + `/${todo.id}`, {headers: HEADERS, method: "PATCH", body: JSON.stringify({completed: todo.completed})});
},

completeAll: function() {
this.todos.forEach(t => {
fetch(API + `/${t.id}`, {headers: HEADERS, method: "PUT", body: JSON.stringify({completed: t.completed})});
fetch(API + `/${t.id}`, {headers: HEADERS, method: "PATCH", body: JSON.stringify({completed: t.completed})});
})
},

Expand Down
1 change: 0 additions & 1 deletion directus-address.json

This file was deleted.

0 comments on commit da6bfac

Please sign in to comment.