@webship.co/workspace-azure 0.0.0-stage → 1.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/commands/cmd-tools-azure.sh +22 -0
- package/config/plugin.azure.settings.yml +11 -0
- package/config/settings.labels.yml +13 -0
- package/ddev/docker-compose.azure-cli.yaml +9 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +24 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/link.d.ts +11 -0
- package/dist/src/lib/link.js +42 -0
- package/dist/src/lib/link.js.map +1 -0
- package/dist/src/lib/provider.d.ts +11 -0
- package/dist/src/lib/provider.js +100 -0
- package/dist/src/lib/provider.js.map +1 -0
- package/features/azure.feature +20 -0
- package/host-mounts.txt +2 -0
- package/package.json +86 -4
- package/scripts/args/arg-azure.sh +35 -0
- package/scripts/functions/fun-azure-tool.sh +173 -0
- package/scripts/functions/fun-azure.sh +98 -0
- package/scripts/host-install.sh +31 -0
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @webship.co/workspace-azure
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Azure for the [Webship Workspace](https://github.com/webship/workspace) dashboard: the **AZURE**
|
|
4
|
+
menu on every site row, a live-site chip on the project card, "Link to Azure" when a new folder is
|
|
5
|
+
made, and the `cmd-tools-azure.sh` command in every site workspace. A provider of
|
|
6
|
+
[`@webship.co/workspace-hosting`](https://github.com/webship/workspace-hosting), which draws the menu,
|
|
7
|
+
the environments modal, the get-database-and-files flow and the New-folder section for every host.
|
|
8
|
+
|
|
9
|
+
App Service is the Azure product with environments the way the family understands them: a web app (production) and its deployment slots, each with a host name and a state. A deploy is a zip deploy of the current code to the chosen slot; the logs are `az webapp log tail`; the history is the deployment list. Azure Database for MySQL is not reachable generically from a laptop and App Service has no files mount of its own, so there is no `--pull-db` or `--pull-files`.
|
|
10
|
+
|
|
11
|
+
## Use it
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd ~/workspace
|
|
15
|
+
bash core/scripts/plugins.sh --require github:webship/workspace-azure
|
|
16
|
+
bash core/scripts/plugins.sh --activate azure
|
|
17
|
+
bash core/scripts/plugins.sh --install azure
|
|
18
|
+
bash core/scripts/plugins.sh --configure azure # core/config/plugin.azure.settings.yml
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The same four steps are buttons on the dashboard's **Settings → Plugins** page.
|
|
22
|
+
|
|
23
|
+
## The command
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cd ~/workspace/dev
|
|
27
|
+
bash cmd-tools-azure.sh <project> [verb]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Verb | What it does |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `--link` <value> | Link the project to an App Service web app: resource-group/app-name (az webapp list). |
|
|
33
|
+
| `--push` | Deploy: zip the current code (git archive) and push it to the selected slot (az webapp deploy --type zip). Outward-facing: asks before deploying. |
|
|
34
|
+
| `--environment` <value> | Slot for THIS run: production, or a deployment slot's name. Default: the one remembered by --select. |
|
|
35
|
+
| `--environments` | List the web app and its deployment slots with their state and host name. |
|
|
36
|
+
| `--select` <value> | Remember which slot this project works against (in .azure/workspace.yml, git-excluded). Checked against the real list. |
|
|
37
|
+
| `--logs` | Tail the selected slot's logs (az webapp log tail). |
|
|
38
|
+
| `--activities` | List the last 10 deployments of the web app (az webapp log deployment list). |
|
|
39
|
+
| `--force` | Allow --link to relink a project that already points at a different web app. |
|
|
40
|
+
|
|
41
|
+
The link lives in the project's `.azure/workspace.yml` (git-excluded); the dashboard reads it to know
|
|
42
|
+
the project is linked and which environment it works against.
|
|
43
|
+
|
|
44
|
+
## What the package holds
|
|
45
|
+
|
|
46
|
+
| Path | What it is |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `src/index.ts` | `register(api)`: `registerHosting(api, azureProvider(api))` |
|
|
49
|
+
| `src/lib/provider.ts` | The Azure provider: the credentials, the environments and their URLs, the verbs, the pulls, the console |
|
|
50
|
+
| `src/lib/link.ts` | The link file reader |
|
|
51
|
+
| `commands/cmd-tools-azure.sh` | The per-workspace command |
|
|
52
|
+
| `scripts/functions/fun-azure.sh` | The provider's bash hooks (az) |
|
|
53
|
+
| `scripts/functions/fun-azure-tool.sh` | The family's dispatcher: link file, environment selection, safety export, status |
|
|
54
|
+
| `scripts/args/arg-azure.sh` | Its argparse |
|
|
55
|
+
| `scripts/host-install.sh` | The host side: the CLI and the credential check |
|
|
56
|
+
| `config/plugin.azure.settings.yml` | The settings template |
|
|
57
|
+
|
|
58
|
+
The `workspacePlugin` block in `package.json` is the manifest the installer reads.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Installed by the Azure plugin (plugins.sh --install azure); __WORKSPACE__ is the workspace it was installed into.
|
|
4
|
+
#
|
|
5
|
+
# The local ⇄ cloud bridge for one project on Azure: show its link and environments, link it,
|
|
6
|
+
# bring a database and files down into DDEV, deploy, read logs.
|
|
7
|
+
|
|
8
|
+
# Bootstrap.
|
|
9
|
+
# Find the workspace tooling from this script, so a fresh clone needs no setup.
|
|
10
|
+
WORKSPACE_SCRIPTS="${WORKSPACE_SCRIPTS:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../core/scripts" && pwd)}";
|
|
11
|
+
source ${WORKSPACE_SCRIPTS}/bootstrap.sh || exit 1 ;
|
|
12
|
+
|
|
13
|
+
# Load workspace settings and extra lists.
|
|
14
|
+
eval $(parse_yaml ${WORKSPACE_CONFIG}/workspace.__WORKSPACE__.settings.yml);
|
|
15
|
+
|
|
16
|
+
ARGPARSE_DESCRIPTION="Show, link, pull from or deploy a __WORKSPACE__ project on Azure"
|
|
17
|
+
# The args file comes with the plugin: core/scripts/plugins/azure/ is where plugins.sh --install puts it.
|
|
18
|
+
source ${WORKSPACE_SCRIPTS}/plugins/azure/args/arg-azure.sh || exit 1 ;
|
|
19
|
+
|
|
20
|
+
shift $#;
|
|
21
|
+
|
|
22
|
+
azure_project_tool ;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Azure — core/config/plugin.azure.settings.yml
|
|
2
|
+
#
|
|
3
|
+
# The az CLI inside the dashboard container. Either the host's ~/.azure login (mounted) or a service principal for the dashboard; injected only into Azure jobs, never printed.
|
|
4
|
+
# The subscription id or name the web apps live in (az account list).
|
|
5
|
+
subscription: CHANGE_ME
|
|
6
|
+
# The Entra tenant of the service principal (optional when the host login is mounted).
|
|
7
|
+
tenant_id: CHANGE_ME
|
|
8
|
+
# An app registration with Contributor on the resource groups (optional when the host login is mounted). Read as AZURE_CLIENT_ID.
|
|
9
|
+
client_id: CHANGE_ME
|
|
10
|
+
# Its secret. Read as AZURE_CLIENT_SECRET.
|
|
11
|
+
client_secret: CHANGE_ME
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Labels for core/config/plugin.azure.settings.yml, merged into the Settings page.
|
|
2
|
+
subscription:
|
|
3
|
+
label: Subscription
|
|
4
|
+
info: 'The subscription id or name the web apps live in (az account list).'
|
|
5
|
+
tenant_id:
|
|
6
|
+
label: Tenant id
|
|
7
|
+
info: 'The Entra tenant of the service principal (optional when the host login is mounted).'
|
|
8
|
+
client_id:
|
|
9
|
+
label: Service principal client id
|
|
10
|
+
info: 'An app registration with Contributor on the resource groups (optional when the host login is mounted). Read as AZURE_CLIENT_ID.'
|
|
11
|
+
client_secret:
|
|
12
|
+
label: Service principal secret
|
|
13
|
+
info: 'Its secret. Read as AZURE_CLIENT_SECRET.'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# The az CLI and its session, shared FROM THE HOST: one login, token refreshes land on
|
|
2
|
+
# the host, rebuilds keep it. The bin DIRECTORY is mounted, not the file, so an update on the host
|
|
3
|
+
# is live in the container at once. A machine without the CLI mounts an empty dir and the actions
|
|
4
|
+
# say so.
|
|
5
|
+
services:
|
|
6
|
+
web:
|
|
7
|
+
volumes:
|
|
8
|
+
- "${HOME}/.local/bin:/host-local-bin:ro"
|
|
9
|
+
- "${HOME}/.azure:/home/${USER}/.azure:rw"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure for Webship Workspace.
|
|
3
|
+
*
|
|
4
|
+
* The AZURE menu on every site row, a live-site chip, the New-folder link option and the
|
|
5
|
+
* `/azure-site/<workspace>/<project>` jump: all of it is the hosting family's surface
|
|
6
|
+
* (@webship.co/workspace-hosting). This package is the Azure provider plus what the installer places
|
|
7
|
+
* (the per-workspace command, its bash functions, the settings template, the host install).
|
|
8
|
+
*
|
|
9
|
+
* Everything the dashboard is asked for goes through `api`; this package requires nothing from
|
|
10
|
+
* the dashboard's own files.
|
|
11
|
+
*/
|
|
12
|
+
import type { PluginApi } from '@webship.co/workspace-plugin-api';
|
|
13
|
+
import { azureProvider } from './lib/provider';
|
|
14
|
+
export { azureProvider };
|
|
15
|
+
export { azureLinkOf } from './lib/link';
|
|
16
|
+
export declare function register(api: PluginApi): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Azure for Webship Workspace.
|
|
4
|
+
*
|
|
5
|
+
* The AZURE menu on every site row, a live-site chip, the New-folder link option and the
|
|
6
|
+
* `/azure-site/<workspace>/<project>` jump: all of it is the hosting family's surface
|
|
7
|
+
* (@webship.co/workspace-hosting). This package is the Azure provider plus what the installer places
|
|
8
|
+
* (the per-workspace command, its bash functions, the settings template, the host install).
|
|
9
|
+
*
|
|
10
|
+
* Everything the dashboard is asked for goes through `api`; this package requires nothing from
|
|
11
|
+
* the dashboard's own files.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.azureLinkOf = exports.azureProvider = void 0;
|
|
15
|
+
exports.register = register;
|
|
16
|
+
const workspace_hosting_1 = require("@webship.co/workspace-hosting");
|
|
17
|
+
const provider_1 = require("./lib/provider");
|
|
18
|
+
Object.defineProperty(exports, "azureProvider", { enumerable: true, get: function () { return provider_1.azureProvider; } });
|
|
19
|
+
var link_1 = require("./lib/link");
|
|
20
|
+
Object.defineProperty(exports, "azureLinkOf", { enumerable: true, get: function () { return link_1.azureLinkOf; } });
|
|
21
|
+
function register(api) {
|
|
22
|
+
(0, workspace_hosting_1.registerHosting)(api, (0, provider_1.azureProvider)(api));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAUH,4BAEC;AATD,qEAAgE;AAEhE,6CAA+C;AAEtC,8FAFA,wBAAa,OAEA;AACtB,mCAAyC;AAAhC,mGAAA,WAAW,OAAA;AAEpB,SAAgB,QAAQ,CAAC,GAAc;IACrC,IAAA,mCAAe,EAAC,GAAG,EAAE,IAAA,wBAAa,EAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a project is linked to Azure, and to what: the `.azure/workspace.yml` file that
|
|
3
|
+
* `cmd-tools-azure.sh --link` writes (git-excluded), plus the branch the local code is on.
|
|
4
|
+
*/
|
|
5
|
+
import type { HostingLink } from '@webship.co/workspace-hosting';
|
|
6
|
+
export interface AzureLink extends HostingLink {
|
|
7
|
+
/** Every key of the link file, for the provider's own needs (region, resource group, host…). */
|
|
8
|
+
fields: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare function readLinkFile(projectDir: string): Record<string, string> | null;
|
|
11
|
+
export declare function azureLinkOf(projectDir: string): AzureLink | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a project is linked to Azure, and to what: the `.azure/workspace.yml` file that
|
|
4
|
+
* `cmd-tools-azure.sh --link` writes (git-excluded), plus the branch the local code is on.
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.readLinkFile = readLinkFile;
|
|
11
|
+
exports.azureLinkOf = azureLinkOf;
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
function readLinkFile(projectDir) {
|
|
15
|
+
let text;
|
|
16
|
+
try {
|
|
17
|
+
text = fs_1.default.readFileSync(path_1.default.join(projectDir, '.azure', 'workspace.yml'), 'utf8');
|
|
18
|
+
}
|
|
19
|
+
catch (_) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const fields = {};
|
|
23
|
+
for (const line of text.split('\n')) {
|
|
24
|
+
const m = line.match(/^([a-z_]+):\s*(.*?)\s*$/);
|
|
25
|
+
if (m)
|
|
26
|
+
fields[m[1]] = m[2].replace(/^["']|["']$/g, '');
|
|
27
|
+
}
|
|
28
|
+
return fields;
|
|
29
|
+
}
|
|
30
|
+
function azureLinkOf(projectDir) {
|
|
31
|
+
const fields = readLinkFile(projectDir);
|
|
32
|
+
if (!fields || !fields.id)
|
|
33
|
+
return null;
|
|
34
|
+
let branch = null;
|
|
35
|
+
try {
|
|
36
|
+
const head = fs_1.default.readFileSync(path_1.default.join(projectDir, '.git', 'HEAD'), 'utf8').trim();
|
|
37
|
+
branch = (head.match(/^ref: refs\/heads\/(.+)$/) || [])[1] || null;
|
|
38
|
+
}
|
|
39
|
+
catch (_) { /* not a git clone */ }
|
|
40
|
+
return { id: fields.id, env: fields.env || null, branch, fields };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["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AI,IAAI,CAAC;IACrE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAC,qBAAqB,CAAC,CAAC;IACrC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure App Service, as a hosting provider.
|
|
3
|
+
*
|
|
4
|
+
* The link is `.azure/workspace.yml` (resource group and web app name); the web app and its
|
|
5
|
+
* deployment slots come from `az webapp` with the host login or the service principal from
|
|
6
|
+
* plugin.azure.settings.yml; the zip deploy, the log tail and the deployment history go through
|
|
7
|
+
* cmd-tools-azure.sh in a screen session. No database or files pull: neither is reachable generically.
|
|
8
|
+
*/
|
|
9
|
+
import type { PluginApi } from '@webship.co/workspace-plugin-api';
|
|
10
|
+
import type { HostingProvider } from '@webship.co/workspace-hosting';
|
|
11
|
+
export declare function azureProvider(api: PluginApi): HostingProvider;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Azure App Service, as a hosting provider.
|
|
4
|
+
*
|
|
5
|
+
* The link is `.azure/workspace.yml` (resource group and web app name); the web app and its
|
|
6
|
+
* deployment slots come from `az webapp` with the host login or the service principal from
|
|
7
|
+
* plugin.azure.settings.yml; the zip deploy, the log tail and the deployment history go through
|
|
8
|
+
* cmd-tools-azure.sh in a screen session. No database or files pull: neither is reachable generically.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.azureProvider = azureProvider;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const workspace_hosting_1 = require("@webship.co/workspace-hosting");
|
|
18
|
+
const link_1 = require("./link");
|
|
19
|
+
function azureProvider(api) {
|
|
20
|
+
const settings = () => api.settings.read() || {};
|
|
21
|
+
const bin = () => (0, workspace_hosting_1.findCli)('az') || 'az';
|
|
22
|
+
const parts = (link) => { const f = link.fields || {}; return { rg: f.resource_group || String(link.id || '').split('/')[0], app: f.app || String(link.id || '').split('/')[1] }; };
|
|
23
|
+
// Either a service principal for the dashboard, or the host's ~/.azure mounted into the container.
|
|
24
|
+
const jobEnv = () => {
|
|
25
|
+
const s = settings();
|
|
26
|
+
const base = { ...process.env, AZURE_CORE_OUTPUT: 'json', AZURE_CORE_ONLY_SHOW_ERRORS: 'true' };
|
|
27
|
+
const sub = (0, workspace_hosting_1.configured)(s.subscription);
|
|
28
|
+
if (sub)
|
|
29
|
+
base.AZURE_SUBSCRIPTION = sub;
|
|
30
|
+
const cid = (0, workspace_hosting_1.configured)(s.client_id);
|
|
31
|
+
const sec = (0, workspace_hosting_1.configured)(s.client_secret);
|
|
32
|
+
const ten = (0, workspace_hosting_1.configured)(s.tenant_id);
|
|
33
|
+
if (cid && sec && ten)
|
|
34
|
+
return { ...base, AZURE_CLIENT_ID: cid, AZURE_CLIENT_SECRET: sec, AZURE_TENANT_ID: ten };
|
|
35
|
+
if (fs_1.default.existsSync(path_1.default.join(process.env.HOME || '', '.azure', 'azureProfile.json')))
|
|
36
|
+
return base;
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
async function environments(link, lib, env) {
|
|
40
|
+
const id = link.id;
|
|
41
|
+
const { rg, app } = parts(link);
|
|
42
|
+
const sub = env.AZURE_SUBSCRIPTION ? ['--subscription', env.AZURE_SUBSCRIPTION] : [];
|
|
43
|
+
const main = await lib.run(bin(), ['webapp', 'show', '-g', rg, '-n', app, ...sub, '-o', 'json', '--query', '{name:name,state:state,host:defaultHostName}'], process.env.HOME, { timeoutMs: 60 * 1000, env });
|
|
44
|
+
if (!main.ok)
|
|
45
|
+
return { id, rows: [], why: 'list failed' };
|
|
46
|
+
const rows = [];
|
|
47
|
+
try {
|
|
48
|
+
const m = JSON.parse(String(main.stdout));
|
|
49
|
+
rows.push({ title: `${m.name} (production)`, envId: 'production', status: /^running$/i.test(m.state) ? 'active' : String(m.state || 'unknown').toLowerCase(), url: m.host ? `https://${m.host}` : undefined });
|
|
50
|
+
}
|
|
51
|
+
catch (_) {
|
|
52
|
+
return { id, rows: [], why: 'list failed' };
|
|
53
|
+
}
|
|
54
|
+
const slots = await lib.run(bin(), ['webapp', 'deployment', 'slot', 'list', '-g', rg, '-n', app, ...sub, '-o', 'json', '--query', '[].{name:name,state:state,host:defaultHostName}'], process.env.HOME, { timeoutMs: 60 * 1000, env });
|
|
55
|
+
if (slots.ok) {
|
|
56
|
+
try {
|
|
57
|
+
for (const s of JSON.parse(String(slots.stdout))) {
|
|
58
|
+
rows.push({ title: s.name, envId: s.name, status: /^running$/i.test(s.state) ? 'active' : String(s.state || 'unknown').toLowerCase(), url: s.host ? `https://${s.host}` : undefined });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (_) { /* no slots */ }
|
|
62
|
+
}
|
|
63
|
+
return { id, rows };
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
id: 'azure',
|
|
67
|
+
label: 'AZURE',
|
|
68
|
+
title: 'Azure',
|
|
69
|
+
cli: 'az',
|
|
70
|
+
script: 'cmd-tools-azure.sh',
|
|
71
|
+
detect: (projectDir) => (0, link_1.azureLinkOf)(projectDir),
|
|
72
|
+
linkHint: (project) => `bash cmd-tools-azure.sh ${project} --link <resource-group>/<web-app>`,
|
|
73
|
+
consoleUrl: (link) => {
|
|
74
|
+
if (!link.id)
|
|
75
|
+
return null;
|
|
76
|
+
const { rg, app } = parts(link);
|
|
77
|
+
const sub = (0, workspace_hosting_1.configured)(settings().subscription);
|
|
78
|
+
return sub ? `https://portal.azure.com/#@/resource/subscriptions/${encodeURIComponent(sub)}/resourceGroups/${encodeURIComponent(rg)}/providers/Microsoft.Web/sites/${encodeURIComponent(app)}` : 'https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.Web%2Fsites';
|
|
79
|
+
},
|
|
80
|
+
jobEnv,
|
|
81
|
+
tokenHint: 'the host ~/.azure login, or the service principal in core/config/plugin.azure.settings.yml',
|
|
82
|
+
environments,
|
|
83
|
+
tools: {
|
|
84
|
+
status: { verb: 'azure', label: 'Link and slots', icon: 'info', args: [] },
|
|
85
|
+
activities: { verb: 'azure-activities', label: 'Last 10 deployments', icon: 'list', args: ['--activities'] },
|
|
86
|
+
logs: { verb: 'azure-logs', label: 'Tail the slot logs', icon: 'file-text', args: ['--logs'] },
|
|
87
|
+
deploy: { verb: 'azure-push', label: 'Deploy (zip deploy to the slot)…', icon: 'push', args: ['--push'] },
|
|
88
|
+
},
|
|
89
|
+
errorHint: (msg) => (/AADSTS|Please run 'az login'|not logged in|authentication/i.test(msg)
|
|
90
|
+
? `${msg}\n\nThe dashboard reaches Azure with the host's ~/.azure login (mounted) or the service principal in core/config/plugin.azure.settings.yml.`
|
|
91
|
+
: msg),
|
|
92
|
+
folder: {
|
|
93
|
+
idPattern: /^[A-Za-z0-9._()-]+\/[A-Za-z0-9-]{2,60}$/,
|
|
94
|
+
idPlaceholder: 'webship-rg/webship-demo',
|
|
95
|
+
idHelp: 'An App Service link is resource-group/web-app-name (az webapp list).',
|
|
96
|
+
},
|
|
97
|
+
menuNote: 'No database or files pull: Azure Database and App Service storage are not reached from here',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/lib/provider.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AAUH,sCAwEC;AAhFD,4CAAoB;AACpB,gDAAwB;AAExB,qEAAoE;AAGpE,iCAAqC;AAErC,SAAgB,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AAE;YACL,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;YAC1E,UAAU,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE;YAC5G,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE;YAC9F,MAAM,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE;SAC1G;QACD,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,4DAA4D,CAAC,IAAI,CAAC,GAAG,CAAC;YACzF,CAAC,CAAC,GAAG,GAAG,6IAA6I;YACrJ,CAAC,CAAC,GAAG,CAAC;QACR,MAAM,EAAE;YACN,SAAS,EAAE,yCAAyC;YACpD,aAAa,EAAE,yBAAyB;YACxC,MAAM,EAAE,sEAAsE;SAC/E;QACD,QAAQ,EAAE,6FAA6F;KACxG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Feature: The Azure plugin on a project row
|
|
2
|
+
Once the plugin is activated and installed, every site row carries the AZURE menu, and the Plugins
|
|
3
|
+
page lists the plugin with its four steps.
|
|
4
|
+
|
|
5
|
+
Scenario: A site row offers the AZURE menu, captioned with its link state
|
|
6
|
+
Given I am on "/dev"
|
|
7
|
+
Then the element ".act-menu-azure" should be displayed
|
|
8
|
+
And I should see "AZURE"
|
|
9
|
+
And the element ".act-menu-azure + .act-status" should be displayed
|
|
10
|
+
|
|
11
|
+
Scenario: An unlinked project's menu opens and says how to link it
|
|
12
|
+
Given I am on "/dev"
|
|
13
|
+
And I click on the element ".project-row .act-menu-azure button"
|
|
14
|
+
Then ".uk-dropdown.uk-open" should be visible
|
|
15
|
+
And I should see "Not linked to Azure"
|
|
16
|
+
|
|
17
|
+
Scenario: The plugin is listed on the Plugins page
|
|
18
|
+
Given I am on "/settings/plugins"
|
|
19
|
+
Then I should see "Azure"
|
|
20
|
+
And I should see "@webship.co/workspace-azure"
|
package/host-mounts.txt
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webship.co/workspace-azure",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-beta1",
|
|
4
|
+
"description": "Azure App Service for Webship Workspace: the AZURE menu on every site row, the web app and its deployment slots with their URLs, zip deploy, log tail, deployment history. A provider of @webship.co/workspace-hosting.",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/webship/workspace-azure.git"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/src",
|
|
14
|
+
"commands",
|
|
15
|
+
"config",
|
|
16
|
+
"features",
|
|
17
|
+
"scripts",
|
|
18
|
+
"README.md",
|
|
19
|
+
"ddev",
|
|
20
|
+
"host-mounts.txt"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.json",
|
|
24
|
+
"prepare": "npm run build",
|
|
25
|
+
"test": "npm run build && node --test dist/tests/*.test.js",
|
|
26
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"workspacePlugin": {
|
|
29
|
+
"name": "azure",
|
|
30
|
+
"label": "Azure",
|
|
31
|
+
"settingsFile": "plugin.azure.settings.yml",
|
|
32
|
+
"settingsTemplate": "config/plugin.azure.settings.yml",
|
|
33
|
+
"labels": "config/settings.labels.yml",
|
|
34
|
+
"legacySettingsKey": "azure",
|
|
35
|
+
"typeActions": {
|
|
36
|
+
"azure": [
|
|
37
|
+
"sites"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"commands": {
|
|
41
|
+
"types": [
|
|
42
|
+
"sites"
|
|
43
|
+
],
|
|
44
|
+
"workspaces": [
|
|
45
|
+
"dev",
|
|
46
|
+
"test",
|
|
47
|
+
"demos",
|
|
48
|
+
"sandboxes",
|
|
49
|
+
"projects"
|
|
50
|
+
],
|
|
51
|
+
"files": [
|
|
52
|
+
"commands/cmd-tools-azure.sh"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"functions": [
|
|
57
|
+
"scripts/functions/fun-azure.sh",
|
|
58
|
+
"scripts/functions/fun-azure-tool.sh"
|
|
59
|
+
],
|
|
60
|
+
"args": [
|
|
61
|
+
"scripts/args/arg-azure.sh"
|
|
62
|
+
],
|
|
63
|
+
"hostInstall": "scripts/host-install.sh"
|
|
64
|
+
},
|
|
65
|
+
"features": [
|
|
66
|
+
"features/azure.feature"
|
|
67
|
+
],
|
|
68
|
+
"ddev": {
|
|
69
|
+
"compose": [
|
|
70
|
+
"ddev/docker-compose.azure-cli.yaml"
|
|
71
|
+
],
|
|
72
|
+
"hostMounts": [
|
|
73
|
+
"~/.azure"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@webship.co/workspace-hosting": "^1.0.0-beta1"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@types/node": "^24.0.0",
|
|
82
|
+
"@webship.co/workspace-plugin-api": "^1.0.0-beta1",
|
|
83
|
+
"typescript": "^5.9.0"
|
|
84
|
+
},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
argparse "$@" <<ARGEOF || exit 1
|
|
4
|
+
parser.add_argument('PROJECT_NAME',
|
|
5
|
+
help='The project directory in this workspace.')
|
|
6
|
+
parser.add_argument('-l', '--link',
|
|
7
|
+
default="_none_",
|
|
8
|
+
help='Link the project to an App Service web app: resource-group/app-name (az webapp list).')
|
|
9
|
+
parser.add_argument('-p', '--push',
|
|
10
|
+
action='store_true',
|
|
11
|
+
default=False,
|
|
12
|
+
help='Deploy: zip the current code (git archive) and push it to the selected slot (az webapp deploy --type zip). Outward-facing: asks before deploying.')
|
|
13
|
+
parser.add_argument('-e', '--environment',
|
|
14
|
+
default="_none_",
|
|
15
|
+
help='Slot for THIS run: production, or a deployment slot's name. Default: the one remembered by --select.')
|
|
16
|
+
parser.add_argument('-E', '--environments',
|
|
17
|
+
action='store_true',
|
|
18
|
+
default=False,
|
|
19
|
+
help='List the web app and its deployment slots with their state and host name.')
|
|
20
|
+
parser.add_argument('-s', '--select',
|
|
21
|
+
default="_none_",
|
|
22
|
+
help='Remember which slot this project works against (in .azure/workspace.yml, git-excluded). Checked against the real list.')
|
|
23
|
+
parser.add_argument('-g', '--logs',
|
|
24
|
+
action='store_true',
|
|
25
|
+
default=False,
|
|
26
|
+
help='Tail the selected slot's logs (az webapp log tail).')
|
|
27
|
+
parser.add_argument('-a', '--activities',
|
|
28
|
+
action='store_true',
|
|
29
|
+
default=False,
|
|
30
|
+
help='List the last 10 deployments of the web app (az webapp log deployment list).')
|
|
31
|
+
parser.add_argument('-f', '--force',
|
|
32
|
+
action='store_true',
|
|
33
|
+
default=False,
|
|
34
|
+
help='Allow --link to relink a project that already points at a different web app.')
|
|
35
|
+
ARGEOF
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# The Azure tool's dispatcher: generated by the hosting family's scaffolder, the same for every
|
|
4
|
+
# provider. The provider's own hooks live in fun-azure.sh:
|
|
5
|
+
# ensure_azure the CLI and credentials are usable, or say how
|
|
6
|
+
# azure_do_link <project_path> <id> link the project (writes the link file through azure_link_set)
|
|
7
|
+
# azure_list_environments <id> one environment id per line (for --select's check)
|
|
8
|
+
# azure_do_environments <id> print the environments for a person
|
|
9
|
+
# azure_pull_db <project_path> <id> <env> dump the environment's database to stdout path given in $1… (see fun-azure.sh)
|
|
10
|
+
# azure_pull_files <project_path> <id> <env>
|
|
11
|
+
# azure_do_push <project_path> <id> <env> deploy
|
|
12
|
+
# azure_do_logs <project_path> <id> <env>
|
|
13
|
+
# azure_do_activities <project_path> <id>
|
|
14
|
+
# azure_status <project_path> <id> the closing status block
|
|
15
|
+
|
|
16
|
+
AZURE_LINK_FILE=".azure/workspace.yml";
|
|
17
|
+
|
|
18
|
+
# One key of the link file, or nothing.
|
|
19
|
+
function azure_link_get() {
|
|
20
|
+
local project_path="$1" key="$2";
|
|
21
|
+
[ -f "${project_path}/${AZURE_LINK_FILE}" ] || return 0 ;
|
|
22
|
+
grep -E "^${key}:" "${project_path}/${AZURE_LINK_FILE}" | head -1 | sed -E 's/^[a-z_]+:[[:space:]]*//; s/^"//; s/"$//' ;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Set one key of the link file, creating it (git-excluded: it is this machine's, not the repo's).
|
|
26
|
+
function azure_link_set() {
|
|
27
|
+
local project_path="$1" key="$2" value="$3" file;
|
|
28
|
+
file="${project_path}/${AZURE_LINK_FILE}";
|
|
29
|
+
mkdir -p "$(dirname "${file}")" ;
|
|
30
|
+
touch "${file}" ;
|
|
31
|
+
if grep -qE "^${key}:" "${file}" ; then
|
|
32
|
+
sed -i -E "s|^${key}:.*|${key}: ${value}|" "${file}" ;
|
|
33
|
+
else
|
|
34
|
+
printf '%s: %s\n' "${key}" "${value}" >> "${file}" ;
|
|
35
|
+
fi
|
|
36
|
+
if [ -d "${project_path}/.git" ] && ! grep -qx "/.azure/" "${project_path}/.git/info/exclude" 2>/dev/null ; then
|
|
37
|
+
mkdir -p "${project_path}/.git/info" && printf '/.azure/\n' >> "${project_path}/.git/info/exclude" ;
|
|
38
|
+
fi
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function azure_linked_id() { azure_link_get "$1" id ; }
|
|
42
|
+
function azure_selected_env() { azure_link_get "$1" env ; }
|
|
43
|
+
|
|
44
|
+
# Which environment a run acts on: --environment for this run, else the remembered selection, else
|
|
45
|
+
# nothing. Deliberately NOT defaulting to production: pulling live data because nobody said
|
|
46
|
+
# otherwise is exactly the accident worth preventing.
|
|
47
|
+
function azure_target_env() {
|
|
48
|
+
if [ ! "${ENVIRONMENT:-_none_}" == '_none_' ] ; then printf '%s' "${ENVIRONMENT}"; return 0 ; fi
|
|
49
|
+
azure_selected_env "$1";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Where this project serves from: Drupal's two conventions, plus the flat case.
|
|
53
|
+
function azure_docroot() {
|
|
54
|
+
for candidate in web docroot ; do
|
|
55
|
+
[ -d "$1/${candidate}" ] && { printf '%s' "${candidate}"; return 0 ; }
|
|
56
|
+
done
|
|
57
|
+
printf '%s' "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# The local database is replaced by a pull, so it is exported first unless --no-safety-backup.
|
|
61
|
+
function azure_safety_export() {
|
|
62
|
+
local project_path="$1" safety="$2";
|
|
63
|
+
if [ "${NO_SAFETY_BACKUP:-no}" == 'yes' ] ; then
|
|
64
|
+
echo "Skipping the local database export, as asked. The current local data will be lost.";
|
|
65
|
+
else
|
|
66
|
+
echo "Exporting the current local database first.";
|
|
67
|
+
(cd "${project_path}" && ddev export-db --file="${safety}") \
|
|
68
|
+
|| echo " (no local database to export yet — continuing)";
|
|
69
|
+
fi
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function azure_import_dump() {
|
|
73
|
+
local project_path="$1" dump="$2";
|
|
74
|
+
echo "Importing it into DDEV.";
|
|
75
|
+
(cd "${project_path}" && ddev start -y > /dev/null && ddev import-db --file="${dump}") || return 1 ;
|
|
76
|
+
echo " Drupal sites usually need: ddev drush updb -y && ddev drush cr";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function azure_project_tool() {
|
|
80
|
+
local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
|
|
81
|
+
local linked_id="";
|
|
82
|
+
|
|
83
|
+
if [ ! -d "${project_path}" ]; then
|
|
84
|
+
echo "No such project: ${project_path}";
|
|
85
|
+
return 1 ;
|
|
86
|
+
fi
|
|
87
|
+
cd "${project_path}" ;
|
|
88
|
+
linked_id="$(azure_linked_id "${project_path}")" ;
|
|
89
|
+
|
|
90
|
+
if [ ! "${LINK:-_none_}" == '_none_' ] ; then
|
|
91
|
+
ensure_azure || return 1 ;
|
|
92
|
+
if [ -n "${linked_id}" ] && [ ! "${linked_id}" == "${LINK}" ] && [ ! "${FORCE:-no}" == 'yes' ] ; then
|
|
93
|
+
echo "${doc_name}/${PROJECT_NAME} is already linked to Azure ${linked_id}." ;
|
|
94
|
+
echo "Re-run with --force to relink it to ${LINK}." ;
|
|
95
|
+
return 1 ;
|
|
96
|
+
fi
|
|
97
|
+
azure_do_link "${project_path}" "${LINK}" || return 1 ;
|
|
98
|
+
linked_id="$(azure_linked_id "${project_path}")" ;
|
|
99
|
+
echo "Linked ${doc_name}/${PROJECT_NAME} → ${linked_id}." ;
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
local needs_link="";
|
|
103
|
+
for flag in "${ENVIRONMENTS:-no}" "${PULL_DB:-no}" "${PULL_FILES:-no}" "${PUSH:-no}" "${LOGS:-no}" "${ACTIVITIES:-no}" ; do
|
|
104
|
+
[ "${flag}" == 'yes' ] && needs_link=yes ;
|
|
105
|
+
done
|
|
106
|
+
[ ! "${SELECT:-_none_}" == '_none_' ] && needs_link=yes ;
|
|
107
|
+
if [ -n "${needs_link}" ] ; then
|
|
108
|
+
if [ -z "${linked_id}" ] ; then
|
|
109
|
+
echo "Not linked to Azure — run with --link <id> first." ;
|
|
110
|
+
return 1 ;
|
|
111
|
+
fi
|
|
112
|
+
ensure_azure || return 1 ;
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
if [ "${ENVIRONMENTS:-no}" == 'yes' ] ; then
|
|
116
|
+
azure_do_environments "${project_path}" "${linked_id}" || return 1 ;
|
|
117
|
+
echo "";
|
|
118
|
+
echo " Select one: bash cmd-tools-azure.sh ${PROJECT_NAME} --select <environment>";
|
|
119
|
+
fi
|
|
120
|
+
|
|
121
|
+
if [ ! "${SELECT:-_none_}" == '_none_' ] ; then
|
|
122
|
+
# Checked against the real list rather than taken on trust: a typo would otherwise be
|
|
123
|
+
# discovered by a pull that dumps the wrong environment, or none.
|
|
124
|
+
if ! azure_list_environments "${project_path}" "${linked_id}" 2>/dev/null | grep -qx "${SELECT}" ; then
|
|
125
|
+
echo "Azure ${linked_id} has no environment called '${SELECT}'." ;
|
|
126
|
+
echo " List them: bash cmd-tools-azure.sh ${PROJECT_NAME} --environments" ;
|
|
127
|
+
return 1 ;
|
|
128
|
+
fi
|
|
129
|
+
azure_link_set "${project_path}" env "${SELECT}" ;
|
|
130
|
+
echo "${doc_name}/${PROJECT_NAME} now works against the ${SELECT} environment." ;
|
|
131
|
+
fi
|
|
132
|
+
|
|
133
|
+
if [ "${PULL_DB:-no}" == 'yes' ] || [ "${PULL_FILES:-no}" == 'yes' ] || [ "${PUSH:-no}" == 'yes' ] ; then
|
|
134
|
+
local target_env;
|
|
135
|
+
target_env="$(azure_target_env "${project_path}")";
|
|
136
|
+
if [ -z "${target_env}" ] ; then
|
|
137
|
+
echo "No environment selected. Pick one first — a pull or a deploy must never guess which environment it targets:" ;
|
|
138
|
+
echo " bash cmd-tools-azure.sh ${PROJECT_NAME} --environments" ;
|
|
139
|
+
echo " bash cmd-tools-azure.sh ${PROJECT_NAME} --select <environment>" ;
|
|
140
|
+
echo " (or name it for this run: --environment <environment>)" ;
|
|
141
|
+
return 1 ;
|
|
142
|
+
fi
|
|
143
|
+
[ "${PULL_DB:-no}" == 'yes' ] && { azure_pull_db "${project_path}" "${linked_id}" "${target_env}" || return 1 ; }
|
|
144
|
+
[ "${PULL_FILES:-no}" == 'yes' ] && { azure_pull_files "${project_path}" "${linked_id}" "${target_env}" || return 1 ; }
|
|
145
|
+
[ "${PUSH:-no}" == 'yes' ] && { azure_do_push "${project_path}" "${linked_id}" "${target_env}" || return 1 ; }
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
if [ "${LOGS:-no}" == 'yes' ] ; then
|
|
149
|
+
azure_do_logs "${project_path}" "${linked_id}" "$(azure_target_env "${project_path}")" || true ;
|
|
150
|
+
fi
|
|
151
|
+
if [ "${ACTIVITIES:-no}" == 'yes' ] ; then
|
|
152
|
+
azure_do_activities "${project_path}" "${linked_id}" || true ;
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
# Default (and after any verb): status.
|
|
156
|
+
echo "";
|
|
157
|
+
echo "*---------------------------------------------------------------------*";
|
|
158
|
+
echo " ${doc_name}/${PROJECT_NAME} on Azure";
|
|
159
|
+
if [ -z "${linked_id}" ]; then
|
|
160
|
+
echo " not linked. Link it with:";
|
|
161
|
+
echo " bash cmd-tools-azure.sh ${PROJECT_NAME} --link <id>";
|
|
162
|
+
azure_status "${project_path}" "" ;
|
|
163
|
+
else
|
|
164
|
+
echo " linked: ${linked_id}";
|
|
165
|
+
local selected;
|
|
166
|
+
selected="$(azure_selected_env "${project_path}")";
|
|
167
|
+
echo " env: ${selected:-none selected — --environments then --select <name>}";
|
|
168
|
+
azure_status "${project_path}" "${linked_id}" ;
|
|
169
|
+
fi
|
|
170
|
+
echo "*---------------------------------------------------------------------*";
|
|
171
|
+
|
|
172
|
+
cd "${WORKSPACE_ROOT}/${doc_name}";
|
|
173
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Azure App Service through the az CLI. The hooks the hosting dispatcher (fun-azure-tool.sh) calls
|
|
4
|
+
# for one project directory. Everything defaults to read-only; --link and --push each demand their
|
|
5
|
+
# flag, and nothing here ever creates or deletes a web app or a slot.
|
|
6
|
+
|
|
7
|
+
function azure_rg() { azure_link_get "$1" resource_group ; }
|
|
8
|
+
function azure_app() { azure_link_get "$1" app ; }
|
|
9
|
+
function azure_sub() { [ -n "${AZURE_SUBSCRIPTION:-${subscription:-}}" ] && [ ! "${AZURE_SUBSCRIPTION:-${subscription:-}}" == 'CHANGE_ME' ] && printf -- '--subscription %s' "${AZURE_SUBSCRIPTION:-${subscription}}" ; }
|
|
10
|
+
|
|
11
|
+
function ensure_azure() {
|
|
12
|
+
if command -v az > /dev/null 2>&1 ; then
|
|
13
|
+
if ! az account show > /dev/null 2>&1 ; then
|
|
14
|
+
if [ -n "${AZURE_CLIENT_ID:-}" ] && [ -n "${AZURE_CLIENT_SECRET:-}" ] && [ -n "${AZURE_TENANT_ID:-}" ] ; then
|
|
15
|
+
az login --service-principal -u "${AZURE_CLIENT_ID}" -p "${AZURE_CLIENT_SECRET}" --tenant "${AZURE_TENANT_ID}" > /dev/null || return 1 ;
|
|
16
|
+
else
|
|
17
|
+
echo "az is installed but not logged in. On the host: az login; in the dashboard: the service principal in the plugin settings." ;
|
|
18
|
+
return 1 ;
|
|
19
|
+
fi
|
|
20
|
+
fi
|
|
21
|
+
return 0 ;
|
|
22
|
+
fi
|
|
23
|
+
echo "The az CLI is not installed. Install it first: https://learn.microsoft.com/cli/azure/install-azure-cli (pipx install azure-cli)" ;
|
|
24
|
+
return 1 ;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function azure_do_link() {
|
|
28
|
+
local project_path="$1" spec="$2" rg app;
|
|
29
|
+
[[ "${spec}" =~ ^([^/]+)/([^/]+)$ ]] || { echo "An App Service link is resource-group/web-app-name, got: ${spec}"; return 1; } ;
|
|
30
|
+
rg="${BASH_REMATCH[1]}"; app="${BASH_REMATCH[2]}";
|
|
31
|
+
# shellcheck disable=SC2046
|
|
32
|
+
az webapp show -g "${rg}" -n "${app}" $(azure_sub) -o none 2>/dev/null || { echo "No web app ${app} in resource group ${rg} (az webapp list)."; return 1; } ;
|
|
33
|
+
azure_link_set "${project_path}" id "${rg}/${app}" ;
|
|
34
|
+
azure_link_set "${project_path}" resource_group "${rg}" ;
|
|
35
|
+
azure_link_set "${project_path}" app "${app}" ;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function azure_list_environments() {
|
|
39
|
+
echo production ;
|
|
40
|
+
# shellcheck disable=SC2046
|
|
41
|
+
az webapp deployment slot list -g "$(azure_rg "$1")" -n "$(azure_app "$1")" $(azure_sub) -o tsv --query '[].name' 2>/dev/null ;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function azure_do_environments() {
|
|
45
|
+
local project_path="$1";
|
|
46
|
+
# shellcheck disable=SC2046
|
|
47
|
+
az webapp show -g "$(azure_rg "${project_path}")" -n "$(azure_app "${project_path}")" $(azure_sub) -o tsv --query '[name, state, defaultHostName]' 2>/dev/null \
|
|
48
|
+
| awk '{ printf " %-24s %-10s https://%s\n", "production", tolower($2), $3 }' || { echo " (could not read the web app — check az account show)"; return 1; } ;
|
|
49
|
+
# shellcheck disable=SC2046
|
|
50
|
+
az webapp deployment slot list -g "$(azure_rg "${project_path}")" -n "$(azure_app "${project_path}")" $(azure_sub) -o tsv --query '[].[name, state, defaultHostName]' 2>/dev/null \
|
|
51
|
+
| awk '{ printf " %-24s %-10s https://%s\n", $1, tolower($2), $3 }' ;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function azure_slot_arg() { [ -n "$1" ] && [ ! "$1" == 'production' ] && printf -- '--slot %s' "$1" ; }
|
|
55
|
+
|
|
56
|
+
function azure_pull_db() { echo "Azure Database is not reached from here: there is no --pull-db."; return 1 ; }
|
|
57
|
+
function azure_pull_files() { echo "App Service has no files mount this tool syncs: there is no --pull-files."; return 1 ; }
|
|
58
|
+
|
|
59
|
+
function azure_do_push() {
|
|
60
|
+
local project_path="$1" id="$2" env="$3" zip a;
|
|
61
|
+
echo "Deploy ${doc_name}/${PROJECT_NAME} → ${id} (${env})";
|
|
62
|
+
echo " git archive HEAD → zip → az webapp deploy --type zip. The live slot changes.";
|
|
63
|
+
read -r -p " Continue? [y/N] " a < /dev/tty || return 1 ;
|
|
64
|
+
[[ "${a}" =~ ^[Yy] ]] || { echo "Not deployed."; return 1; } ;
|
|
65
|
+
zip="$(mktemp -d)/${PROJECT_NAME}.zip";
|
|
66
|
+
(cd "${project_path}" && git archive --format=zip -o "${zip}" HEAD) || { echo "git archive failed — the deploy ships the committed tree."; return 1; } ;
|
|
67
|
+
# shellcheck disable=SC2046
|
|
68
|
+
az webapp deploy -g "$(azure_rg "${project_path}")" -n "$(azure_app "${project_path}")" $(azure_slot_arg "${env}") $(azure_sub) --type zip --src-path "${zip}" || return 1 ;
|
|
69
|
+
echo " Deployed to ${env}.";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function azure_do_logs() {
|
|
73
|
+
local project_path="$1" id="$2" env="$3";
|
|
74
|
+
# shellcheck disable=SC2046
|
|
75
|
+
az webapp log tail -g "$(azure_rg "${project_path}")" -n "$(azure_app "${project_path}")" $(azure_slot_arg "${env}") $(azure_sub) ;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function azure_do_activities() {
|
|
79
|
+
local project_path="$1";
|
|
80
|
+
# shellcheck disable=SC2046
|
|
81
|
+
az webapp log deployment list -g "$(azure_rg "${project_path}")" -n "$(azure_app "${project_path}")" $(azure_sub) -o json 2>/dev/null | python3 -c 'import json,sys
|
|
82
|
+
for d in json.load(sys.stdin)[:10]:
|
|
83
|
+
print(" %-20s %-10s %s" % ((d.get("received_time") or d.get("start_time") or "")[:19], "ok" if d.get("complete") else "running", (d.get("message") or d.get("id") or "")[:60]))' \
|
|
84
|
+
|| echo " (could not list the deployments)" ;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function azure_status() {
|
|
88
|
+
local project_path="$1" id="$2";
|
|
89
|
+
if [ -z "${id}" ] ; then
|
|
90
|
+
echo " (the link is resource-group/web-app-name; az webapp list)";
|
|
91
|
+
return 0 ;
|
|
92
|
+
fi
|
|
93
|
+
echo "";
|
|
94
|
+
azure_do_environments "${project_path}" ;
|
|
95
|
+
echo "";
|
|
96
|
+
echo " Console: https://portal.azure.com/ → App Services → $(azure_app "${project_path}")";
|
|
97
|
+
echo " --push zip-deploys the committed tree to the selected slot; --logs tails it.";
|
|
98
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
## The host side of the Azure plugin: the CLI on this machine and the dashboard's credentials.
|
|
3
|
+
## Run by core/scripts/plugins.sh --install azure, and by core/scripts/install.sh for every installed
|
|
4
|
+
## plugin that ships one. Idempotent: whatever is already there is reported, not redone. Offered,
|
|
5
|
+
## never automatic: a hosting CLI carries cloud credentials for real environments.
|
|
6
|
+
set -u
|
|
7
|
+
WORKSPACE_ROOT="${WORKSPACE_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../../.." && pwd)}";
|
|
8
|
+
|
|
9
|
+
# The az CLI on this machine, mounted into the dashboard from ~/.local/bin or found on PATH.
|
|
10
|
+
BIN='';
|
|
11
|
+
for candidate in "$(command -v az 2>/dev/null)" "${HOME}/.local/bin/az" ; do
|
|
12
|
+
[ -n "${candidate}" ] && [ -x "${candidate}" ] && { BIN="${candidate}"; break; }
|
|
13
|
+
done
|
|
14
|
+
if [ -n "${BIN}" ] ; then
|
|
15
|
+
printf ' ✓ %-16s %s\n' "az" "${BIN}" ;
|
|
16
|
+
else
|
|
17
|
+
printf ' ✗ %-16s %s\n' "az" "missing — the AZURE menu needs it (learn.microsoft.com/cli/azure/install-azure-cli — pipx install azure-cli, or the apt repository)" ;
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
STATE="$(grep -E '^client_id:' "${WORKSPACE_ROOT}/core/config/plugin.azure.settings.yml" 2>/dev/null | head -1 | sed -E 's/^[a-z_]+:[[:space:]]*//')";
|
|
21
|
+
case "${STATE}" in
|
|
22
|
+
''|CHANGE_ME|"''"|'""') printf ' ✗ %-16s %s\n' "client_id" "not set in plugin.azure.settings.yml — the dashboard cannot reach Azure" ;;
|
|
23
|
+
*) printf ' ✓ %-16s %s\n' "client_id" "set (plugin.azure.settings.yml)" ;;
|
|
24
|
+
esac
|
|
25
|
+
|
|
26
|
+
STATE="$(grep -E '^client_secret:' "${WORKSPACE_ROOT}/core/config/plugin.azure.settings.yml" 2>/dev/null | head -1 | sed -E 's/^[a-z_]+:[[:space:]]*//')";
|
|
27
|
+
case "${STATE}" in
|
|
28
|
+
''|CHANGE_ME|"''"|'""') printf ' ✗ %-16s %s\n' "client_secret" "not set in plugin.azure.settings.yml — the dashboard cannot reach Azure" ;;
|
|
29
|
+
*) printf ' ✓ %-16s %s\n' "client_secret" "set (plugin.azure.settings.yml)" ;;
|
|
30
|
+
esac
|
|
31
|
+
|