Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Created March 20, 2025 13:58
Show Gist options
  • Save pythoninthegrass/171bd3ce92ceeac97a5b9fb4f299804a to your computer and use it in GitHub Desktop.
Save pythoninthegrass/171bd3ce92ceeac97a5b9fb4f299804a to your computer and use it in GitHub Desktop.
Pulumi copilot - Azure container
import pulumi
from pulumi_azure_native import resources, containerregistry, containerinstance
from pulumi_docker import Image
# Create an Azure Resource Group
resource_group = resources.ResourceGroup('resourceGroup')
# Create an Azure Container Registry with admin user enabled
registry = containerregistry.Registry('myRegistry',
resource_group_name=resource_group.name,
sku=containerregistry.SkuArgs(
name='Basic',
),
admin_user_enabled=True)
# Retrieve the registry credentials
credentials = containerregistry.list_registry_credentials_output(
resource_group_name=resource_group.name,
registry_name=registry.name)
# Define a Docker image to be built and pushed to the Azure Container Registry
image = Image('myImage',
image_name=registry.login_server.apply(
lambda login_server: f'{login_server}/myapp:latest'),
build='./app',
registry={
'server': registry.login_server,
'username': credentials.username,
'password': credentials.passwords[0].value,
})
# Create an Azure Container Group with the Docker image
container_group = containerinstance.ContainerGroup('myContainerGroup',
resource_group_name=resource_group.name,
os_type='Linux',
containers=[containerinstance.ContainerArgs(
name='mycontainer',
image=image.image_name,
resources=containerinstance.ResourceRequirementsArgs(
requests=containerinstance.ResourceRequestsArgs(
cpu=1.0,
memory_in_gb=1.5,
),
),
ports=[containerinstance.ContainerPortArgs(
port=80,
)],
)],
ip_address=containerinstance.IpAddressArgs(
ports=[containerinstance.PortArgs(
port=80,
protocol='Tcp',
)],
type='Public',
))
# Export the URL of the deployed container
pulumi.export('container_url', container_group.ip_address.apply(
lambda ip: f'http://{ip.ip}'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment