Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional installation of Bicep #66

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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