Added Docker/Podman build information.

This commit is contained in:
2025-08-14 21:30:56 +02:00
parent 73c87a733b
commit d2abe3fd27
9 changed files with 148 additions and 1 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
.terraform
**/*.tfplan
**/*.tfstate*
.venv
.terraform.lock.hcl
.acr-pat
azure.env

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --root-user-action=ignore --no-cache-dir -r requirements.txt
COPY image-chooser.py .
COPY ./entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "run", "image-chooser.py" ]

8
build.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
IMAGE_NAME="azure-image-chooser"
#IMAGE="docker.io/skoszewski/$IMAGE_NAME"
IMAGE="skdomlab.azurecr.io/$IMAGE_NAME"
podman build -t $IMAGE .
podman push $IMAGE

8
entrypoint.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
if [ "$1" = "-s" ] || [ "$1" = "--shell" ]; then
shift
exec bash $@
fi
exec streamlit $@

View File

@@ -32,7 +32,7 @@ def get_skus(location: str, publisher: str, offer: str):
def get_image_versions(location: str, publisher: str, offer: str, sku: str):
return [version.name for version in compute_client.virtual_machine_images.list(location, publisher, offer, sku)]
subscription_id = "046a1c08-9940-48c0-893c-77eccd7e875d"
subscription_id = "c885a276-c882-483f-b216-42f73715161d"
location = "westeurope"
credential = DefaultAzureCredential()

2
main.auto.tfvars Normal file
View File

@@ -0,0 +1,2 @@
subscription_id = "c885a276-c882-483f-b216-42f73715161d"
project_name = "azure-image-chooser"

91
main.tf Normal file
View File

@@ -0,0 +1,91 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 4.0.0"
}
}
backend "local" {
path = "azure-image-chooser.tfstate"
}
}
provider "azurerm" {
features {}
subscription_id = var.subscription_id
}
variable "subscription_id" {
description = "The Azure Subscription ID to use for the resources."
type = string
}
variable "project_name" {
description = "The name used to construct Azure resource names."
type = string
}
resource "azurerm_resource_group" "rg" {
name = "rg-${var.project_name}"
location = "Poland Central"
}
resource "azurerm_log_analytics_workspace" "logaws" {
name = "${var.project_name}-logs"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_container_app_environment" "env" {
name = "${var.project_name}-env"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
log_analytics_workspace_id = azurerm_log_analytics_workspace.logaws.id
workload_profile {
name = "Consumption"
workload_profile_type = "Consumption"
maximum_count = 1
}
}
resource "azurerm_container_app" "app" {
name = "${var.project_name}-app"
container_app_environment_id = azurerm_container_app_environment.env.id
resource_group_name = azurerm_resource_group.rg.name
revision_mode = "Single"
template {
container {
name = "${var.project_name}-container"
image = "skdomlab.azurecr.io/azure-image-chooser:latest"
cpu = "0.25"
memory = "0.5Gi"
}
}
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.uai.id]
}
}
resource "azurerm_user_assigned_identity" "uai" {
name = "${var.project_name}-uai"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
}
resource "azurerm_role_assignment" "acr_pull" {
scope = data.azurerm_container_registry.acr.id
role_definition_name = "AcrPull"
principal_id = azurerm_user_assigned_identity.uai.principal_id
}
data "azurerm_container_registry" "acr" {
name = "skdomlab"
resource_group_name = "dom-lab-common"
}

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
streamlit
azure-identity
azure-mgmt-compute

15
run-container.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
if [ -z "$AZURE_CLIENT_ID" ] || [ -z "$AZURE_TENANT_ID" ] || [ -z "$AZURE_CLIENT_SECRET" ] || [ -z "$AZURE_SUBSCRIPTION_ID" ]; then
echo "One or more environment variables are not set."
exit 1
fi
podman run --rm \
-it \
-e AZURE_CLIENT_ID="$AZURE_CLIENT_ID" \
-e AZURE_TENANT_ID="$AZURE_TENANT_ID" \
-e AZURE_CLIENT_SECRET="$AZURE_CLIENT_SECRET" \
-e AZURE_SUBSCRIPTION_ID="$AZURE_SUBSCRIPTION_ID" \
-p 8501:8501 \
azure-image-chooser