Skip to content

Commit 4a4db78

Browse files
committed
Test build 13
1 parent ac82e56 commit 4a4db78

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

articles/deployment-environments/how-to-configure-extensibility-model-custom-image.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ After you complete the image customization, you can build the image and push it
7979
8080
Rather than building your custom image and pushing it to a container registry yourself, you can use a script to build and push it to a specified container registry.
8181
82-
[!INCLUDE [custom-image-script](includes/custom-image-script.md)]
82+
[!INCLUDE [custom-image-script](includes/custom-image-script-build.md)]
8383
8484
### [Create a custom image manually](#tab/custom-manual/)
8585
### Create a custom container image manually
@@ -98,6 +98,9 @@ After you complete the image customization, you can build the image and push it
9898
9999
::: zone-end
100100
101+
<!-- =========== TERRAFORM ======================================================================================================== -->
102+
103+
101104
::: zone pivot="terraform"
102105
## Use container images with ADE
103106
@@ -232,6 +235,150 @@ echo "{\"outputs\": $tfOutputs}" > $ADE_OUTPUTS
232235

233236
::: zone-end
234237

238+
<!-- ======== PULUMI ==================================================================================================================== -->
239+
240+
::: zone pivot="pulumi"
241+
### [Use a standard container image](#tab/standard/)
242+
243+
### Use a standard container image provided by Pulumi
244+
245+
The Pulumi team provides a prebuilt image to get you started, which you can see in the [Runner-Image](https://github.com/pulumi/azure-deployment-environments/tree/main/Runner-Image) folder. This image is publicly available at Pulumi's Docker Hub as [`pulumi/azure-deployment-environments`](https://hub.docker.com/repository/docker/pulumi/azure-deployment-environments), so you can use it directly from your ADE environment definitions.
246+
247+
Here's a sample *environment.yaml* file that utilizes the prebuilt image:
248+
249+
```yaml
250+
name: SampleDefinition
251+
version: 1.0.0
252+
summary: First Pulumi-Enabled Environment
253+
description: Deploys a Storage Account with Pulumi
254+
runner: pulumi/azure-deployment-environments:0.1.0
255+
templatePath: Pulumi.yaml
256+
```
257+
258+
You can find a few sample environment definitions in the [Environments folder](https://github.com/pulumi/azure-deployment-environments/tree/main/Environments).
259+
260+
### [Create a custom image](#tab/custom/)
261+
262+
### Create a custom image
263+
264+
Creating a custom container image allows you to customize your deployments to fit your requirements. You can create custom images based on the Pulumi standard images, and customize them to meet your requirements. After you complete the image customization, you must build the image and push it to your container registry.
265+
266+
To create an image configured for ADE, follow these steps:
267+
1. Create a custom image based on a standard image.
268+
1. Install desired packages.
269+
1. Configure operation shell scripts.
270+
1. Create operation shell scripts that use the Pulumi CLI.
271+
272+
**1. Create a custom image based on a standard image**
273+
274+
Create a DockerFile that includes a FROM statement pointing to a standard image hosted on Microsoft Artifact Registry.
275+
276+
Here's an example FROM statement, referencing the standard core image:
277+
278+
```docker
279+
FROM mcr.microsoft.com/deployment-environments/runners/core:latest
280+
```
281+
282+
This statement pulls the most recently published core image, and makes it a basis for your custom image.
283+
284+
**2. Install required packages**
285+
286+
You can install the Pulumi CLI to an executable location so that it can be used in your deployment and deletion scripts.
287+
288+
Here's an example of that process, installing the latest version of the Pulumi CLI:
289+
290+
```docker
291+
RUN apk add curl
292+
RUN curl -fsSL https://get.pulumi.com | sh
293+
ENV PATH="${PATH}:/root/.pulumi/bin"
294+
```
295+
296+
Depending on which programming language you intend to use for Pulumi programs, you might need to install one or more corresponding runtimes. The Python runtime is already available in the base image.
297+
298+
Here's an example of installing Node.js and TypeScript:
299+
300+
```docker
301+
# install node.js, npm, and typescript
302+
RUN apk add nodejs npm
303+
RUN npm install typescript -g
304+
```
305+
306+
The ADE standard images are based on the Azure CLI image, and have the ADE CLI and JQ packages preinstalled. You can learn more about the [Azure CLI](/cli/azure/), and the [JQ package](https://devdocs.io/jq/).
307+
308+
To install any more packages you need within your image, use the RUN statement.
309+
310+
There are four steps to deploy infrastructure via Pulumi:
311+
312+
1. `pulumi login` - connect to the state storage, either in local file system or in [Pulumi Cloud](https://www.pulumi.com/product/pulumi-cloud/)
313+
1. `pulumi stack select` - create or select the stack to use for the particular environment
314+
1. `pulumi config set` - pass deployment parameters as Pulumi configuration values
315+
1. `pulumi up` - run the deployment to create new or update existing infrastructure in Azure
316+
317+
During the core image's entrypoint, any existing local state files are pulled into the container and the directory saved under the environment variable ```$ADE_STORAGE```. In order to access the existing state file, run the following commands:
318+
319+
```bash
320+
mkdir -p $ADE_STORAGE
321+
export PULUMI_CONFIG_PASSPHRASE=
322+
pulumi login file://$ADE_STORAGE
323+
```
324+
325+
To sign in to Pulumi Cloud instead, set your Pulumi access token as an environment variable, and run the following commands:
326+
327+
```bash
328+
export PULUMI_ACCESS_TOKEN=YOUR_PULUMI_ACCESS_TOKEN
329+
pulumi login
330+
```
331+
332+
Any parameters set for the current environment are stored under the variable ```$ADE_OPERATION_PARAMETERS```. Additionally, the selected Azure region and resource group name are passed in ```ADE_ENVIRONMENT_LOCATION``` and ```ADE_RESOURCE_GROUP_NAME``` respectively. In order to set your Pulumi stack config, run the following commands:
333+
334+
```bash
335+
# Create or select the stack for the current environment
336+
pulumi stack select $ADE_ENVIRONMENT_NAME --create
337+
338+
# Store configuration values in durable storage
339+
export PULUMI_CONFIG_FILE=$ADE_STORAGE/Pulumi.$ADE_ENVIRONMENT_NAME.yaml
340+
341+
# Set the Pulumi stack config
342+
pulumi config set azure-native:location $ADE_ENVIRONMENT_LOCATION --config-file $PULUMI_CONFIG_FILE
343+
pulumi config set resource-group-name $ADE_RESOURCE_GROUP_NAME --config-file $PULUMI_CONFIG_FILE
344+
echo "$ADE_OPERATION_PARAMETERS" | jq -r 'to_entries|.[]|[.key, .value] | @tsv' |
345+
while IFS=$'\t' read -r key value; do
346+
pulumi config set $key $value --config-file $PULUMI_CONFIG_FILE
347+
done
348+
```
349+
350+
Additionally, to utilize ADE privileges to deploy infrastructure inside your subscription, your script needs to use ADE Managed Service Identity (MSI) when provisioning infrastructure by using the Pulumi Azure Native or Azure Classic provider. If your deployment needs special permissions to complete your deployment, such as particular roles, assign those permissions to the project environment type's identity that is being used for your environment deployment. ADE sets the relevant environment variables, such as the client, tenant, and subscription IDs within the core image's entrypoint, so run the following commands to ensure the provider uses ADE MSI:
351+
352+
```bash
353+
export ARM_USE_MSI=true
354+
export ARM_CLIENT_ID=$ADE_CLIENT_ID
355+
export ARM_TENANT_ID=$ADE_TENANT_ID
356+
export ARM_SUBSCRIPTION_ID=$ADE_SUBSCRIPTION_ID
357+
```
358+
359+
Now, you can run the `pulumi up` command to execute the deployment:
360+
```bash
361+
pulumi up --refresh --yes --config-file $PULUMI_CONFIG_FILE
362+
```
363+
364+
During your deletion script, you can instead run the `destroy` command, as shown in the following example:
365+
```bash
366+
pulumi destroy --refresh --yes --config-file $PULUMI_CONFIG_FILE
367+
```
368+
369+
Finally, to make the outputs of your deployment uploaded and accessible when accessing your environment via the Azure CLI, transform the output object from Pulumi to the ADE-specified format through the JQ package. Set the value to the $ADE_OUTPUTS environment variable, as shown in the following example:
370+
```bash
371+
stackout=$(pulumi stack output --json | jq -r 'to_entries|.[]|{(.key): {type: "string", value: (.value)}}')
372+
echo "{\"outputs\": ${stackout:-{\}}}" > $ADE_OUTPUTS
373+
```
374+
375+
### Build the custom image
376+
377+
[!INCLUDE [custom-image-manual-build](includes/custom-image-manual-build.md)]
378+
379+
---
380+
381+
::: zone-end
235382
236383
## Make the custom image available to ADE
237384

0 commit comments

Comments
 (0)