From fcde6cfbe07a0e263bee9f086c08b74c196f6aaa Mon Sep 17 00:00:00 2001 From: Mike Larah Date: Tue, 14 Jan 2020 16:50:02 +0000 Subject: [PATCH] Use porter azure plugin to store instances in blob storage --- docker/Dockerfile | 17 ++++++++++++++--- docker/config.toml | 1 + pkg/generator/testdata/azuredeploy-simple.json | 14 ++++++++++++++ pkg/generator/testdata/azuredeploy.json | 14 ++++++++++++++ pkg/template/cnab-arm-driver-template.go | 13 +++++++++++++ 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 docker/config.toml diff --git a/docker/Dockerfile b/docker/Dockerfile index 38e083a..8a7aaa9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,19 @@ +# Build Porter Azure plugin (remove this when `porter plugin install` command is implemented - https://github.com/deislabs/porter/issues/771) +FROM golang:1.13.6 +RUN go get github.com/deislabs/porter-azure-plugins/... +WORKDIR /go/src/github.com/deislabs/porter-azure-plugins +RUN make build + FROM alpine:latest ARG CNAB_ARM_DRIVER_VERSION ARG CNAB_ARM_DRIVER_REPO ENV PORTER_URL=https://cdn.deislabs.io/porter -ENV PORTER_VERSION=v0.17.1-beta.1 +ENV PORTER_VERSION=v0.22.1-beta.1 -ENV CNAB_AZURE_DRIVER_VERSION=v.0.0.3 -ENV CNAB_AZURE_DRIVER_REPO=simongdavies/cnab-azure-driver +ENV CNAB_AZURE_DRIVER_VERSION=v0.0.4 +ENV CNAB_AZURE_DRIVER_REPO=deislabs/cnab-azure-driver ENV CNAB_ARM_DRIVER_VERSION=$CNAB_ARM_DRIVER_VERSION ENV CNAB_ARM_DRIVER_REPO=$CNAB_ARM_DRIVER_REPO @@ -32,4 +38,9 @@ RUN chmod +x "${TOOLHOME}/cnab-azure" RUN curl "https://github.com/${CNAB_ARM_DRIVER_REPO}/releases/download/${CNAB_ARM_DRIVER_VERSION}/cnabarmdriver-linux-amd64" -fLo "${TOOLHOME}/cnabarmdriver" RUN chmod +x "${TOOLHOME}/cnabarmdriver" +# Install Porter Azure plugin +RUN mkdir -p ${PORTER_HOME}/plugins +COPY --from=0 /go/src/github.com/deislabs/porter-azure-plugins/bin/plugins/azure ${PORTER_HOME}/plugins/ +COPY config.toml ${PORTER_HOME}/ + CMD cnabarmdriver \ No newline at end of file diff --git a/docker/config.toml b/docker/config.toml new file mode 100644 index 0000000..1f36cbf --- /dev/null +++ b/docker/config.toml @@ -0,0 +1 @@ +instance-storage-plugin = "azure.blob" \ No newline at end of file diff --git a/pkg/generator/testdata/azuredeploy-simple.json b/pkg/generator/testdata/azuredeploy-simple.json index bf3f7c2..10a36b5 100644 --- a/pkg/generator/testdata/azuredeploy-simple.json +++ b/pkg/generator/testdata/azuredeploy-simple.json @@ -106,6 +106,16 @@ } } }, + { + "type": "Microsoft.Storage/storageAccounts/blobServices/containers", + "name": "[concat(variables('cnab_azure_state_storage_account_name'), '/default/porter'))]", + "apiVersion": "2019-04-01", + "location": "[variables('aci_location')]", + "dependsOn": [ + "[variables('cnab_azure_state_storage_account_name')]" + ], + "properties": null + }, { "type": "Microsoft.Storage/storageAccounts/fileServices/shares", "name": "[concat(variables('cnab_azure_state_storage_account_name'), '/default/', variables('cnab_azure_state_fileshare'))]", @@ -189,6 +199,10 @@ "name": "CNAB_BUNDLE_TAG", "value": "cnabquickstarts.azurecr.io/porter/hello-world/bundle:1.0.0" }, + { + "name": "AZURE_STORAGE_CONNECTION_STRING", + "secureValue": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('cnab_azure_state_storage_account_name')), '2019-04-01').keys[0].value]" + }, { "name": "CNAB_PARAM_age", "value": "[parameters('age')]" diff --git a/pkg/generator/testdata/azuredeploy.json b/pkg/generator/testdata/azuredeploy.json index 547eaae..f2c6ad3 100644 --- a/pkg/generator/testdata/azuredeploy.json +++ b/pkg/generator/testdata/azuredeploy.json @@ -221,6 +221,16 @@ } } }, + { + "type": "Microsoft.Storage/storageAccounts/blobServices/containers", + "name": "[concat(variables('cnab_azure_state_storage_account_name'), '/default/porter'))]", + "apiVersion": "2019-04-01", + "location": "[variables('aci_location')]", + "dependsOn": [ + "[variables('cnab_azure_state_storage_account_name')]" + ], + "properties": null + }, { "type": "Microsoft.Storage/storageAccounts/fileServices/shares", "name": "[concat(variables('cnab_azure_state_storage_account_name'), '/default/', variables('cnab_azure_state_fileshare'))]", @@ -304,6 +314,10 @@ "name": "CNAB_BUNDLE_TAG", "value": "cnabquickstarts.azurecr.io/porter/hello-world/bundle:1.0.0" }, + { + "name": "AZURE_STORAGE_CONNECTION_STRING", + "secureValue": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('cnab_azure_state_storage_account_name')), '2019-04-01').keys[0].value]" + }, { "name": "CNAB_PARAM_age", "value": "[parameters('age')]" diff --git a/pkg/template/cnab-arm-driver-template.go b/pkg/template/cnab-arm-driver-template.go index 9024a39..08cb105 100644 --- a/pkg/template/cnab-arm-driver-template.go +++ b/pkg/template/cnab-arm-driver-template.go @@ -35,6 +35,15 @@ func NewCnabArmDriverTemplate(bundleName string, bundleTag string, containerImag }, }, }, + { + Type: "Microsoft.Storage/storageAccounts/blobServices/containers", + Name: "[concat(variables('cnab_azure_state_storage_account_name'), '/default/porter'))]", + APIVersion: "2019-04-01", + Location: "[variables('aci_location')]", + DependsOn: []string{ + "[variables('cnab_azure_state_storage_account_name')]", + }, + }, { Type: "Microsoft.Storage/storageAccounts/fileServices/shares", Name: "[concat(variables('cnab_azure_state_storage_account_name'), '/default/', variables('cnab_azure_state_fileshare'))]", @@ -116,6 +125,10 @@ func NewCnabArmDriverTemplate(bundleName string, bundleTag string, containerImag Name: common.GetEnvironmentVariableNames().CnabBundleTag, Value: bundleTag, }, + { + Name: "AZURE_STORAGE_CONNECTION_STRING", + SecureValue: "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('cnab_azure_state_storage_account_name')), '2019-04-01').keys[0].value]", + }, }, }, },