From ad49f02c88ba7c4e7e3aaf61eec145ff0162685d Mon Sep 17 00:00:00 2001 From: Jeremy Rickard Date: Mon, 5 Aug 2019 10:42:39 -0600 Subject: [PATCH] Update the workshop examples: (#495) * Add a bundle output to porter-tf and porter-tf-aci * Update the update/uninstall steps to not print anything * Updated porter-tf-aci to deploy a trivial webapp to ACI --- workshop/porter-tf-aci/azure/app/Dockerfile | 6 ++ workshop/porter-tf-aci/azure/app/main.go | 23 ++++++ .../porter-tf-aci/azure/bundle/porter.yaml | 82 ++++++------------- workshop/porter-tf/azure/porter.yaml | 60 ++++---------- 4 files changed, 72 insertions(+), 99 deletions(-) create mode 100644 workshop/porter-tf-aci/azure/app/Dockerfile diff --git a/workshop/porter-tf-aci/azure/app/Dockerfile b/workshop/porter-tf-aci/azure/app/Dockerfile new file mode 100644 index 000000000..79461cc70 --- /dev/null +++ b/workshop/porter-tf-aci/azure/app/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:latest +RUN mkdir /app +ADD . /app/ +WORKDIR /app +RUN go build -o main . +CMD ["/app/main"] diff --git a/workshop/porter-tf-aci/azure/app/main.go b/workshop/porter-tf-aci/azure/app/main.go index da29a2cad..6155ae490 100644 --- a/workshop/porter-tf-aci/azure/app/main.go +++ b/workshop/porter-tf-aci/azure/app/main.go @@ -1,4 +1,27 @@ package main +import ( + "fmt" + "log" + "net/http" + "os" +) + +func handle(w http.ResponseWriter, r *http.Request) { + sqlFQDN := os.Getenv("MYSQL_FQDN") + if sqlFQDN == "" { + http.Error(w, "couldn't find MYSQL FQDN", http.StatusInternalServerError) + } + + w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN))) +} + func main() { + + http.HandleFunc("/", handle) + + fmt.Printf("Server starting on port 8080\n") + if err := http.ListenAndServe(":8080", nil); err != nil { + log.Fatal(err) + } } diff --git a/workshop/porter-tf-aci/azure/bundle/porter.yaml b/workshop/porter-tf-aci/azure/bundle/porter.yaml index 77a5b3d66..2fb368020 100644 --- a/workshop/porter-tf-aci/azure/bundle/porter.yaml +++ b/workshop/porter-tf-aci/azure/bundle/porter.yaml @@ -48,6 +48,17 @@ parameters: - name: database-name type: string +outputs: + - name: IP_ADDRESS + type: string + +imageMap: + websvc: + description: "A simple web service" + imageType: "docker" + image: "jeremyrickard/devops-days-msp@sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914" + digest: "sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914" + install: - azure: description: "Create an Azure Storage Account" @@ -89,66 +100,25 @@ install: parameters: containerName: "{{ bundle.parameters.server-name }}-aci-go" location: "{{ bundle.parameters.location }}" - imageName: "nginx:1.17.2" + imageName: "jeremyrickard/devops-days-msp@sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914" mysqlFQDN: "{{bundle.outputs.mysql_fqdn}}" - port: "80" + port: "8080" outputs: - name: "IP_ADDRESS" key: "IP_ADDRESS" - + upgrade: - - terraform: - description: "Update Azure MySQL With Terraform" - autoApprove: true - input: false - backendConfig: - key: "{{ bundle.name }}.tfstate" - storage_account_name: "{{ bundle.parameters.backend_storage_account }}" - container_name: "{{ bundle.parameters.backend_storage_container }}" - access_key: "{{ bundle.outputs.STORAGE_ACCOUNT_KEY }}" - vars: - backend_storage_account: "{{ bundle.parameters.backend_storage_account }}" - subscription_id: "{{bundle.credentials.subscription_id}}" - tenant_id: "{{bundle.credentials.tenant_id}}" - client_id: "{{bundle.credentials.client_id}}" - client_secret: "{{bundle.credentials.client_secret}}" - server-name: "{{bundle.parameters.server-name}}" + - exec: + description: "Perform an upgrade" + command: "bash" + arguments: + - "-c" + - "echo Not implemented yet" uninstall: - - azure: - description: "Create an ACI Instance" - type: aci - name: "{{ bundle.name }}-aci" - resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}" - parameters: - name: "{{ bundle.name }}-aci-go" - location: "{{ bundle.parameters.location }}" - image: "nginx:1.17.2" - - - terraform: - description: "Remove Azure CosmosDB and Event Hubs" - autoApprove: true - input: false - vars: - subscription_id: "{{bundle.credentials.subscription_id}}" - tenant_id: "{{bundle.credentials.tenant_id}}" - client_id: "{{bundle.credentials.client_id}}" - client_secret: "{{bundle.credentials.client_secret}}" - database_name: "{{bundle.parameters.database-name}}" - resource_group_name: "{{bundle.parameters.resource_group_name}}" - resource_group_location: "{{bundle.parameters.location}}" - backendConfig: - key: "{{ bundle.name }}.tfstate" - storage_account_name: "{{ bundle.parameters.storage_account_name }}" - container_name: "{{ bundle.parameters.storage_container_name }}" - access_key: "{{ bundle.parameters.tf_storage_account_key }}" - - - azure: - description: "Create an Azure Storage Account" - type: storage - name: "{{ bundle.parameters.backend_storage_account }}" - resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}" - parameters: - location: "{{ bundle.parameters.location }}" - storageAccountName: "{{ bundle.parameters.backend_storage_account }}" - storageContainerName: "{{ bundle.parameters.backend_storage_container }}" \ No newline at end of file + - exec: + description: "Perform an uninstall" + command: "bash" + arguments: + - "-c" + - "echo Not implemented yet" \ No newline at end of file diff --git a/workshop/porter-tf/azure/porter.yaml b/workshop/porter-tf/azure/porter.yaml index 47eb6f2fa..b152b3a2a 100644 --- a/workshop/porter-tf/azure/porter.yaml +++ b/workshop/porter-tf/azure/porter.yaml @@ -1,5 +1,6 @@ mixins: - azure + - exec - terraform name: porter-workshop-tf @@ -47,6 +48,10 @@ parameters: - name: database-name type: string +outputs: + - name: STORAGE_ACCOUNT_KEY + type: string + install: - azure: description: "Create an Azure Storage Account" @@ -79,48 +84,17 @@ install: database-name: "{{bundle.parameters.database-name}}" upgrade: - - terraform: - description: "Update Azure MySQL With Terraform" - autoApprove: true - input: false - backendConfig: - key: "{{ bundle.name }}.tfstate" - storage_account_name: "{{ bundle.parameters.backend_storage_account }}" - container_name: "{{ bundle.parameters.backend_storage_container }}" - access_key: "{{ bundle.outputs.STORAGE_ACCOUNT_KEY }}" - vars: - backend_storage_account: "{{ bundle.parameters.backend_storage_account }}" - subscription_id: "{{bundle.credentials.subscription_id}}" - tenant_id: "{{bundle.credentials.tenant_id}}" - client_id: "{{bundle.credentials.client_id}}" - client_secret: "{{bundle.credentials.client_secret}}" - server-name: "{{bundle.parameters.server-name}}" + - exec: + description: "Perform an upgrade" + command: "bash" + arguments: + - "-c" + - "echo Not implemented yet" uninstall: - - terraform: - description: "Remove Azure CosmosDB and Event Hubs" - autoApprove: true - input: false - vars: - subscription_id: "{{bundle.credentials.subscription_id}}" - tenant_id: "{{bundle.credentials.tenant_id}}" - client_id: "{{bundle.credentials.client_id}}" - client_secret: "{{bundle.credentials.client_secret}}" - database_name: "{{bundle.parameters.database-name}}" - resource_group_name: "{{bundle.parameters.resource_group_name}}" - resource_group_location: "{{bundle.parameters.location}}" - backendConfig: - key: "{{ bundle.name }}.tfstate" - storage_account_name: "{{ bundle.parameters.storage_account_name }}" - container_name: "{{ bundle.parameters.storage_container_name }}" - access_key: "{{ bundle.parameters.tf_storage_account_key }}" - - - azure: - description: "Create an Azure Storage Account" - type: storage - name: "{{ bundle.parameters.backend_storage_account }}" - resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}" - parameters: - location: "{{ bundle.parameters.location }}" - storageAccountName: "{{ bundle.parameters.backend_storage_account }}" - storageContainerName: "{{ bundle.parameters.backend_storage_container }}" \ No newline at end of file + - exec: + description: "Perform an uninstall" + command: "bash" + arguments: + - "-c" + - "echo Not implemented yet" \ No newline at end of file