From d744f76094d7ddecac66aa3e3cc67f57fe4122e1 Mon Sep 17 00:00:00 2001 From: Kim Christensen Date: Mon, 8 Jul 2024 00:28:46 +0200 Subject: [PATCH 1/2] Add optional installation of Bicep Signed-off-by: Kim Christensen --- pkg/az/build.go | 7 +++++++ pkg/az/build_test.go | 1 + pkg/az/schema/schema.json | 4 ++++ pkg/az/testdata/build-input-with-bicep.yaml | 15 +++++++++++++++ pkg/az/testdata/build-with-bicep.txt | 17 +++++++++++++++++ pkg/az/testdata/build-with-config.txt | 2 ++ pkg/az/testdata/build-without-config.txt | 2 ++ 7 files changed, 48 insertions(+) create mode 100644 pkg/az/testdata/build-input-with-bicep.yaml create mode 100644 pkg/az/testdata/build-with-bicep.txt diff --git a/pkg/az/build.go b/pkg/az/build.go index d671459..6e81995 100644 --- a/pkg/az/build.go +++ b/pkg/az/build.go @@ -28,6 +28,9 @@ type MixinConfig struct { // Extensions is a list of az CLI extensions to install. Extensions []string `yaml:"extensions,omitempty"` + + // Indicates if Bicep should be installed + InstallBicep bool `yaml:"installBicep,omitempty"` } // buildConfig is the set of configuration options for the mixin's portion of the Dockerfile @@ -50,10 +53,14 @@ RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ apt-get update && apt-get install -y --no-install-recommends \ + {{ if .InstallBicep }}libicu72 \{{ end }} {{ if eq .ClientVersion ""}}azure-cli{{else}}azure-cli={{.ClientVersion}}-1~$(lsb_release -cs){{end}} {{ range $ext := .Extensions }} RUN az extension add -y --name {{ $ext }} {{ end }} +{{ if .InstallBicep }} +RUN az bicep install +{{ end }} ` // Build installs the az cli and any configured extensions. diff --git a/pkg/az/build_test.go b/pkg/az/build_test.go index dac469c..7f7b7c0 100644 --- a/pkg/az/build_test.go +++ b/pkg/az/build_test.go @@ -19,6 +19,7 @@ func TestMixin_Build(t *testing.T) { }{ {name: "build with config", inputFile: "testdata/build-input-with-config.yaml", wantOutputFile: "testdata/build-with-config.txt"}, {name: "build without config", inputFile: "testdata/build-input-without-config.yaml", wantOutputFile: "testdata/build-without-config.txt"}, + {name: "build with bicep", inputFile: "testdata/build-input-with-bicep.yaml", wantOutputFile: "testdata/build-with-bicep.txt"}, } for _, tc := range testcases { diff --git a/pkg/az/schema/schema.json b/pkg/az/schema/schema.json index 46bc1a3..04f6f3f 100644 --- a/pkg/az/schema/schema.json +++ b/pkg/az/schema/schema.json @@ -29,6 +29,10 @@ "items": { "type": "string" } + }, + "installBicep": { + "description": "Indicates if Bicep should be install", + "type": "boolean" } }, "additionalProperties": false diff --git a/pkg/az/testdata/build-input-with-bicep.yaml b/pkg/az/testdata/build-input-with-bicep.yaml new file mode 100644 index 0000000..6cd80d7 --- /dev/null +++ b/pkg/az/testdata/build-input-with-bicep.yaml @@ -0,0 +1,15 @@ +config: + userAgentOptOut: true + clientVersion: 1.2.3 + extensions: + - iot + installBicep: true + +actions: + install: + - az: + arguments: + - login + description: Login + uninstall: [] + upgrade: [] \ No newline at end of file diff --git a/pkg/az/testdata/build-with-bicep.txt b/pkg/az/testdata/build-with-bicep.txt new file mode 100644 index 0000000..1d557c0 --- /dev/null +++ b/pkg/az/testdata/build-with-bicep.txt @@ -0,0 +1,17 @@ + +ENV PORTER_AZ_MIXIN_USER_AGENT_OPT_OUT="true" +ENV AZURE_HTTP_USER_AGENT="" +RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ + apt-get update && apt-get install -y apt-transport-https lsb-release gnupg curl +RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg +RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list +RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + libicu72 \ + azure-cli=1.2.3-1~$(lsb_release -cs) + +RUN az extension add -y --name iot + + +RUN az bicep install + diff --git a/pkg/az/testdata/build-with-config.txt b/pkg/az/testdata/build-with-config.txt index 87fc910..5ff2105 100644 --- a/pkg/az/testdata/build-with-config.txt +++ b/pkg/az/testdata/build-with-config.txt @@ -7,7 +7,9 @@ RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ apt-get update && apt-get install -y --no-install-recommends \ + azure-cli=1.2.3-1~$(lsb_release -cs) RUN az extension add -y --name iot + diff --git a/pkg/az/testdata/build-without-config.txt b/pkg/az/testdata/build-without-config.txt index 494975b..1760c29 100644 --- a/pkg/az/testdata/build-without-config.txt +++ b/pkg/az/testdata/build-without-config.txt @@ -7,5 +7,7 @@ RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ apt-get update && apt-get install -y --no-install-recommends \ + azure-cli + From 695436258619c29c19f6d36337c7d669b5fde6ce Mon Sep 17 00:00:00 2001 From: Kim Christensen Date: Mon, 8 Jul 2024 13:43:45 +0200 Subject: [PATCH 2/2] Add documentation Signed-off-by: Kim Christensen --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index d673254..795dd76 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,18 @@ You can add your own custom strings to the user agent string by editing your [te [template Dockerfile]: https://getporter.org/bundle/custom-dockerfile/ +### Install Bicep + +When you declare the mixin, you can also configure Bicep to be install + +```yaml +mixins: +- az: + installBicep: true +``` + +This is required if you want to use the `az bicep` subcommands. + ## Mixin Syntax The format below is for executing any arbitrary az CLI command.