Skip to content

Commit

Permalink
Add optional installation of Bicep
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Christensen <[email protected]>
  • Loading branch information
kichristensen committed Jul 8, 2024
1 parent 732c043 commit d744f76
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/az/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/az/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/az/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"items": {
"type": "string"
}
},
"installBicep": {
"description": "Indicates if Bicep should be install",
"type": "boolean"
}
},
"additionalProperties": false
Expand Down
15 changes: 15 additions & 0 deletions pkg/az/testdata/build-input-with-bicep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
config:
userAgentOptOut: true
clientVersion: 1.2.3
extensions:
- iot
installBicep: true

actions:
install:
- az:
arguments:
- login
description: Login
uninstall: []
upgrade: []
17 changes: 17 additions & 0 deletions pkg/az/testdata/build-with-bicep.txt
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions pkg/az/testdata/build-with-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 2 additions & 0 deletions pkg/az/testdata/build-without-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit d744f76

Please sign in to comment.