CI

Compose2ContainerApps

This is a proof of concept to take Docker Compose files (following the spec) and converting them to YAML files that can be used to deploy Azure ContainerApps services.

Try it

If you have the just task runner, then you can run the example conversions from the /test/ directory with:

This assumes that PowerShell Core or PowerShell 7 is available.

just demo-convert

To run it with bash

just --shell sh --shell-arg "-cu" demo-convert

Work To Be Done

There are lots of things that the Compose file can express that are not supported. We should add some warnings about those configuration elements that are not going to be represented - things like volume mounts, network configurations, etc..

Things to figure out:

  • A compose file can describe multiple containers and their connections. ContainerApps has two options, multiple containers on the same host (basically a k8s pod) or separate ContainerApps in the same environment with an HTTP ingress between them. Currently, the app creates separate ContainerApps deployments for each service defined.
  • A compose file can expose multiple ports or ranges (internal ingress) or define multiple ports or ranges (external ingress). ContainerApps exposes one port either internally or externally (exclusive) per ContainerApp.
  • Something else?

Building The App

This app should build with minimal dependencies. It's been tested with Rust 1.57.

cargo build

Running The App

The application has three mandatory parameters and two optional ones (that have default values). There are environment variables that can be provided in place of CLI arguments.

compose2containerapp --help

compose2containerapps v0.6.1
Steven Murawski <steven.murawski@microsoft.com>
Converts Docker Compose files to Azure ContainerApps yaml configuration files

USAGE:
    compose2containerapp.exe [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    convert    Converts a Docker Compose file into Azure ContainerApps configurations.
    deploy     Deploys a Docker Compose file into Azure ContainerApps
    help       Prints this message or the help of the given subcommand(s)
    logs       Retrieves Azure ContainerApps Logs

Convert

The convert subcommand takes a Docker Compose file and translates it into a YAML configuration file for Azure ContainerApps.

This YAML file can be deployed with az containerapp create --name YOURCONTAINERAPPNAME --yaml ./path/to/configuration.yaml.

compose2containerapp convert --help

compose2containerapp.exe-convert
Converts a Docker Compose file into Azure ContainerApps configurations.

USAGE:
    compose2containerapp.exe convert [OPTIONS] [ARGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i, --containerapps-environment-id <ContainerAppsEnvironmentId>
            Resource ID for the ContainerApps environment. [env:
            CONTAINERAPPS_ENVIRONMENT_ID=/subscriptions/mysubscription/resourceGroups/myresourcegroup/providers/Microsoft.Web/kubeEnvironments/myenvironment]
    -l, --location <Location>
            Resource group location for the ContainerApps environment. [env: LOCATION=eastus]  [possible values: eastus,
            westus, centralus]
    -g, --resource-group <ResourceGroup>
            Resource Group for the ContainerApps environment. [env: RESOURCE_GROUP=hollan_test]

        --transport <Transport>
            ContainerApps transport. [possible values: Auto, Http, Http2]


ARGS:
    <INPUT>     Path to read the Docker Compose yaml configuration file. [default: ./docker-compose.yml]
    <OUTPUT>    Base file name to write the Azure ContainerApps yaml configuration files.  Output file name will be
                prefixed with the service name. [default: containerapps.yml]

Deploy

The deploy subcommand will take a Docker Compose file and iterate over the services defined, converting them to supported ContainerApps configurations and deploying them to Azure.

If an existing Azure ContainerApps environment is not present, it will create and configure the dependencies in the targeted resource group.

compose2containerapp deploy --help

compose2containerapp.exe-deploy
Deploys a Docker Compose file into Azure ContainerApps

USAGE:
    compose2containerapp.exe deploy [OPTIONS] [ARGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i, --containerapps-environment-id <ContainerAppsEnvironmentId>
            Resource ID for the ContainerApps environment. [env:
            CONTAINERAPPS_ENVIRONMENT_ID=/subscriptions/mysubscription/resourceGroups/myresourcegroup/providers/Microsoft.Web/kubeEnvironments/myenvironment]
    -n, --containerapps-environment-name <ContainerAppsEnvironmentName>
            Resource Name for the ContainerApps environment. [env: CONTAINERAPPS_ENVIRONMENT=hollantest]

    -l, --location <Location>
            Resource group location for the ContainerApps environment. [env: LOCATION=eastus]  [possible values: eastus,
            westus, centralus]
    -g, --resource-group <ResourceGroup>
            Resource Group for the ContainerApps environment. [env: RESOURCE_GROUP=hollan_test]

        --subscription-name <SubscriptionName>
            Resource group location for the ContainerApps environment. [env: AZURE_SUBSCRIPTION_NAME=ca-stmuraws-demo-
            test]
        --transport <Transport>
            ContainerApps transport. [possible values: Auto, Http, Http2]


ARGS:
    <INPUT>     Path to read the Docker Compose yaml configuration file. [default: ./docker-compose.yml]
    <OUTPUT>    Base file name to write the Azure ContainerApps yaml configuration files.  Output file name will be
                prefixed with the service name. [default: containerapps.yml]

Logs

The logs subcommand helps retrieve logs from Azure Container Apps. The logs are kept in Azure Log Analytics. This command simplifies what you need to know to retrieve the logs.

compose2containerapp logs --help

compose2containerapp.exe-logs
Retrieves Azure ContainerApps Logs

USAGE:
    compose2containerapp.exe logs [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --name <ContainerAppName>                                          Name of the ContainerApp to retrive logs for.
    -i, --containerapps-environment-id <ContainerAppsEnvironmentId>
            Resource ID for the ContainerApps environment. [env:
            CONTAINERAPPS_ENVIRONMENT_ID=/subscriptions/mysubscription/resourceGroups/myresourcegroup/providers/Microsoft.Web/kubeEnvironments/myenvironment]
    -n, --containerapps-environment-name <ContainerAppsEnvironmentName>
            Resource Name for the ContainerApps environment. [env: CONTAINERAPPS_ENVIRONMENT=hollantest]

        --number-of-results <NumberOfResults>                              Number of records to return. [default: 100]
    -g, --resource-group <ResourceGroup>
            Resource Group for the ContainerApps environment. [env: RESOURCE_GROUP=hollan_test]

    -c, --log-analtyics-client-id <log_analytics_client_id>
            Resource ID for the ContainerApps environment. [env: LOG_ANALYTICS_WORKSPACE_CLIENT_ID=]