|
1 | 1 | # DSC to Bicep Types Generator |
2 | 2 |
|
3 | | -This is a work-in-progress app to convert DSC type definitions to Bicep's format. |
| 3 | +This is a work-in-progress app to convert DSC type definitions to Bicep's |
| 4 | +format, and now includes a DSC gRPC server (written in Rust) to support `bicep |
| 5 | +local-deploy`. |
4 | 6 |
|
5 | | -DSC types are defined inside each resource manifest. |
6 | | -For now, only embedded schemas are supported. |
| 7 | +With no arguments, this app will attempt to get the schemas for each available |
| 8 | +DSC resource by shelling out to `dsc` (and each resources subcommands if the |
| 9 | +manifest isn't embedded, so be sure to have a build of DSC in the `PATH`. |
7 | 10 |
|
8 | | -Run this app to generate `out/types.json` and `out/index.json`. |
9 | | -Then run `bicep publish-extension --target out/dsc.tgz out/index.json`. |
10 | | -Move this file to wherever you'll refer to it in Bicep's configuration. |
| 11 | +The app will then run `bicep publish-extension ... --target out/dsc.tgz` where |
| 12 | +the rest of the arguments are the generated types (in the `out` directory) and |
| 13 | +the `dscbicep` binary, which currently only exists in DSC's `biecp-gRPC` branch. |
| 14 | + |
| 15 | +That emitted tarball is an OCI artifact recognized by Bicep as an extension, |
| 16 | +which we then need to configure. Note that that the only experimental feature of |
| 17 | +Bicep we're using now is [Local Deploy][]. The extension contains the generated |
| 18 | +type definitions and `dscbicep`, which is a small gRPC server that handles |
| 19 | +requests from `bicep local-deploy` by calling into `dsc-lib`. At no point are we |
| 20 | +passing JSON files to DSC, or calling the `dsc` CLI. Using Local Deploy, Bicep |
| 21 | +_remains_ the orchestrator of Bicep code, meaning that everything just works. |
| 22 | +The gRPC server is implemented in in [PR #1330][]. |
| 23 | + |
| 24 | +On Windows, Rust doesn't really support Unix Domain Sockets so Bicep needed to |
| 25 | +be patched to prefer Named Pipes. Until [PR #18712][] is merged and a new release is |
| 26 | +out, a developer build of that will be needed too. This does not apply to macOS. |
| 27 | + |
| 28 | +[local deploy]: https://github.com/Azure/bicep/blob/main/docs/experimental/local-deploy.md |
| 29 | +[PR #1330]: https://github.com/PowerShell/DSC/pull/1330 |
| 30 | +[PR #18712]: https://github.com/Azure/bicep/pull/18712 |
11 | 31 |
|
12 | 32 | In `bicepconfig.json` enable extensibility and add the extension: |
13 | 33 |
|
14 | 34 | ```json |
15 | 35 | { |
16 | 36 | "experimentalFeaturesEnabled": { |
17 | | - "desiredStateConfiguration": true |
| 37 | + "localDeploy": true |
18 | 38 | }, |
19 | 39 | "extensions": { |
20 | | - "dsc": "./dsc.tgz" |
| 40 | + "dsc": "./out/dsc.tgz" |
21 | 41 | }, |
22 | 42 | "implicitExtensions": [] |
23 | 43 | } |
24 | 44 | ``` |
25 | 45 |
|
26 | | -Then at the top of your Bicep file, enable both the extension and the target scope: |
| 46 | +Then at the top of your Bicep file, enable both the extension and the _local_ target scope: |
27 | 47 |
|
28 | 48 | ```bicep |
29 | 49 | extension dsc |
30 | | -targetScope = 'desiredStateConfiguration' |
| 50 | +targetScope = 'local' |
31 | 51 | ``` |
32 | 52 |
|
33 | | -Now you'll have resource completions for DSC. |
34 | | -However, it won't work yet. Two issues to solve: |
| 53 | +See `example.bicep`, `macos.bicep`, `windows.bicep` and their associated |
| 54 | +`.bicepparam` files for more detailed examples. |
35 | 55 |
|
36 | | -1. Enabling these Bicep configs moves to ARMv2 which emits resources as a dict instead of an array. |
37 | | -2. A new 'imports' property (with our extension) is emmited. |
38 | | - |
39 | | -We actually don't have to use the version, |
40 | | -but the Bicep extension likes to auto-complete type with `@`. |
| 56 | +Use the `Local Deploy` VS Code task to launch one of the examples. It's |
| 57 | +equivalent to: `bicep local-deploy example.bicepparam`, but patches the path to |
| 58 | +the dev build of Bicep and has some environment variables you can edit for |
| 59 | +debugging. |
41 | 60 |
|
42 | 61 | ## Building |
43 | 62 |
|
44 | | -1. Install [Node.js](https://nodejs.org/en/download) |
45 | | -2. Clone repo: `git clone https://github.com/microsoft/bicep-types-dsc.git` |
46 | | -3. Clone submodules: `git submodule update --init` |
47 | | -4. Build `bicep-types`: |
48 | | - 1. `cd bicep-types/src/bicep-types` |
49 | | - 2. `npm install` |
50 | | - 3. `npm run build` |
51 | | - 4. `cd ../../..` |
52 | | -5. `npm install` |
53 | | -6. With `dsc` and `bicep` in `PATH`: |
54 | | - 1. Run `npm start` |
| 63 | +1. Install [Node.js](https://nodejs.org/en/download), for this extension |
| 64 | +2. Install [Rust](https://rust-lang.org/tools/install/), for DSC |
| 65 | +3. Install [.NET SDK](https://dotnet.microsoft.com/en-us/download), for Bicep |
| 66 | +4. Clone this repo: `git clone https://github.com/microsoft/bicep-types-dsc.git` |
| 67 | +5. Clone DSC feature branch: `git clone -b bicep-gRPC https://github.com/andyleejordan/DSC.git` |
| 68 | +6. Clone Bicep feature branch: `git clone -b named-pipes https://github.com/andyleejordan/bicep.git` |
| 69 | +7. Open this project's multi-root workspace: `code bicep-types-dsc/bicep-types-dsc.code-workspace` |
| 70 | +8. Run `Publish Extension` VS Code workspace build task, equivalent to: |
| 71 | + - `cd dsc && ./build.ps1 -Project dscbicep` |
| 72 | + - `cd bicep-types-dsc && npm start` (might need `npm install` first) |
| 73 | +9. Run `Build CLI` VS Code Bicep task, equivalent to: |
| 74 | + - `cd bicep && dotnet build src/Bicep.Cli/Bicep.Cli.csproj` |
| 75 | + |
| 76 | +DSC sometimes needs the CFS Cargo feed updated. A Microsoft employee can add |
| 77 | +`-UseCFS` to the build command. This project sometimes needs the CFS NPM feed |
| 78 | +updated. A Microsoft employee can follow a GUI-driven login procedure. |
0 commit comments